a3bac3b7b1d65db01b3872ba4044fd383e774b7a
[mono.git] / mcs / class / System.Web / Test / System.Web / HttpBrowserCapabilitiesCas.cs
1 //
2 // HttpBrowserCapabilitiesCas.cs 
3 //      - CAS unit tests for System.Web.HttpBrowserCapabilities
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31
32 using System;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Web;
36 using System.Web.UI;
37
38 namespace MonoCasTests.System.Web {
39
40         // note: this[string] is throwing NullReferenceException everywhere
41         // so we "remove" it from action (only for full demands)
42         class BoolHttpBrowserCapabilities : HttpBrowserCapabilities {
43
44                 public override string this [string key] {
45                         get { return "true"; }
46                 }
47         }
48
49         class StringHttpBrowserCapabilities : HttpBrowserCapabilities {
50
51                 public override string this [string key] {
52                         get { return String.Empty; }
53                 }
54         }
55
56         class NumericHttpBrowserCapabilities : HttpBrowserCapabilities {
57
58                 public override string this [string key] {
59                         get { return "1"; }
60                 }
61         }
62
63         class VersionHttpBrowserCapabilities : HttpBrowserCapabilities {
64
65                 public override string this [string key] {
66                         get { return "1.2.3.4"; }
67                 }
68         }
69
70         [TestFixture]
71         [Category ("CAS")]
72         public class HttpBrowserCapabilitiesCas : AspNetHostingMinimal {
73
74                 [Test]
75                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
76                 public void BoolProperties_Deny_Unrestricted ()
77                 {
78                         HttpBrowserCapabilities cap = new BoolHttpBrowserCapabilities ();
79                         Assert.IsTrue (cap.ActiveXControls, "ActiveXControls");
80                         Assert.IsTrue (cap.AOL, "AOL");
81                         Assert.IsTrue (cap.BackgroundSounds, "BackgroundSounds");
82                         Assert.IsTrue (cap.Beta, "Beta");
83                         Assert.IsTrue (cap.CDF, "CDF");
84                         Assert.IsTrue (cap.Cookies, "Cookies");
85                         Assert.IsTrue (cap.Crawler, "Crawler");
86                         Assert.IsTrue (cap.Frames, "Frames");
87                         Assert.IsTrue (cap.JavaApplets, "JavaApplets");
88                         Assert.IsTrue (cap.JavaScript, "JavaScript");
89                         Assert.IsTrue (cap.Tables, "Tables");
90                         Assert.IsTrue (cap.VBScript, "VBScript");
91                         Assert.IsTrue (cap.Win16, "Win16");
92                         Assert.IsTrue (cap.Win32, "Win32");
93                 }
94
95                 [Test]
96                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
97                 public void StringProperties_Deny_Unrestricted ()
98                 {
99                         HttpBrowserCapabilities cap = new StringHttpBrowserCapabilities ();
100                         Assert.IsNotNull (cap.Browser, "Browser");
101 #if NET_2_0
102                         Assert.IsNull (cap.Browsers, "Browsers");
103 #endif
104                         Assert.IsNotNull (cap.Platform, "Platform");
105                         Assert.IsNotNull (cap.Type, "Type");
106                         Assert.IsNotNull (cap.Version, "Version");
107                 }
108
109                 [Test]
110                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
111                 public void TypeProperties_Deny_Unrestricted ()
112                 {
113                         HttpBrowserCapabilities cap = new StringHttpBrowserCapabilities ();
114                         Assert.IsNull (cap.TagWriter, "TagWriter");
115                 }
116
117                 [Test]
118                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
119                 public void NumericProperties_Deny_Unrestricted ()
120                 {
121                         HttpBrowserCapabilities cap = new NumericHttpBrowserCapabilities ();
122                         // int
123                         Assert.AreEqual (1, cap.MajorVersion, "MajorVersion");
124                         // double
125                         Assert.AreEqual (1, cap.MinorVersion, "MinorVersion");
126                 }
127
128                 [Test]
129                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
130                 public void VersionProperties_Deny_Unrestricted ()
131                 {
132                         HttpBrowserCapabilities cap = new VersionHttpBrowserCapabilities ();
133                         Assert.IsNotNull (cap.ClrVersion, "ClrVersion");
134                         Assert.IsNotNull (cap.EcmaScriptVersion, "EcmaScriptVersion");
135                         Assert.IsNotNull (cap.MSDomVersion, "MSDomVersion");
136                         Assert.IsNotNull (cap.W3CDomVersion, "W3CDomVersion");
137                 }
138
139                 [Test]
140                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
141                 public void GetClrVersions_Deny_Unrestricted ()
142                 {
143                         HttpBrowserCapabilities cap = new StringHttpBrowserCapabilities ();
144 #if NET_2_0
145                         Assert.IsNull (cap.GetClrVersions (), "GetClrVersions");
146 #else
147                         Version[] versions = cap.GetClrVersions ();
148                         Assert.AreEqual (1, versions.Length, "GetClrVersions");
149                         Assert.AreEqual ("0.0", versions [0].ToString (), "Version[0]");
150 #endif
151                 }
152
153                 // LinkDemand
154
155                 public override Type Type {
156                         get { return typeof (HttpBrowserCapabilities); }
157                 }
158         }
159 }