2007-03-22 Adar Wesley <adarw@mainsoft.com>
[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 (key == "platform") ? "Win32" : "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                         Type t = cap.TagWriter;
115                         // note: right now the value is hardcoded in Mono, i.e. it doesn't come from the ini file
116                         Assert.IsTrue (((t == null) || (t == typeof (HtmlTextWriter))), "TagWriter");
117                 }
118
119                 [Test]
120                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
121                 public void NumericProperties_Deny_Unrestricted ()
122                 {
123                         HttpBrowserCapabilities cap = new NumericHttpBrowserCapabilities ();
124                         // int
125                         Assert.AreEqual (1, cap.MajorVersion, "MajorVersion");
126                         // double
127                         Assert.AreEqual (1, cap.MinorVersion, "MinorVersion");
128                 }
129
130                 [Test]
131                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
132                 public void VersionProperties_Deny_Unrestricted ()
133                 {
134                         HttpBrowserCapabilities cap = new VersionHttpBrowserCapabilities ();
135                         Assert.IsNotNull (cap.ClrVersion, "ClrVersion");
136                         Assert.IsNotNull (cap.EcmaScriptVersion, "EcmaScriptVersion");
137                         Assert.IsNotNull (cap.MSDomVersion, "MSDomVersion");
138                         Assert.IsNotNull (cap.W3CDomVersion, "W3CDomVersion");
139                 }
140
141                 [Test]
142                 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
143                 public void GetClrVersions_Deny_Unrestricted ()
144                 {
145                         HttpBrowserCapabilities cap = new StringHttpBrowserCapabilities ();
146 #if NET_2_0
147                         Assert.IsNull (cap.GetClrVersions (), "GetClrVersions");
148 #else
149                         Version[] versions = cap.GetClrVersions ();
150                         Assert.AreEqual (1, versions.Length, "GetClrVersions");
151                         Assert.AreEqual ("0.0", versions [0].ToString (), "Version[0]");
152 #endif
153                 }
154
155                 // LinkDemand
156
157                 public override Type Type {
158                         get { return typeof (HttpBrowserCapabilities); }
159                 }
160         }
161 }