2 // PageCas.cs - CAS unit tests for System.Web.UI.Page
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit
.Framework
;
33 using System
.Security
;
34 using System
.Security
.Permissions
;
38 using System
.Web
.UI
.HtmlControls
;
40 namespace MonoCasTests
.System
.Web
.UI
{
44 public class PageCas
: AspNetHostingMinimal
{
46 private Control control
;
50 public void FixtureSetUp ()
52 control
= new Control ();
58 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
59 public void Properties_Deny_Unrestricted ()
62 Assert
.IsNull (p
.Application
, "Application");
63 p
.ClientTarget
= "mono";
64 Assert
.AreEqual ("mono", p
.ClientTarget
, "ClientTarget");
65 p
.EnableViewState
= true;
66 Assert
.IsTrue (p
.EnableViewState
, "EnableViewState");
67 p
.ErrorPage
= "error.html";
68 Assert
.AreEqual ("error.html", p
.ErrorPage
, "ErrorPage");
70 Assert
.AreEqual ("mono", p
.ID
, "ID");
71 Assert
.IsFalse (p
.IsPostBack
, "IsPostBack");
72 Assert
.IsFalse (p
.IsReusable
, "IsReusable");
73 p
.SmartNavigation
= false;
74 Assert
.IsFalse (p
.SmartNavigation
, "SmartNavigation");
75 Assert
.IsNotNull (p
.Validators
, "Validators");
76 p
.ViewStateUserKey
= "mono";
77 Assert
.AreEqual ("mono", p
.ViewStateUserKey
, "ViewStateUserKey");
79 Assert
.IsTrue (p
.Visible
, "Visible");
80 Assert
.IsNotNull (p
.ClientScript
, "ClientScript");
82 // Assert.AreEqual (0, p.CodePage, "CodePage");
83 // p.ContentType = "mono";
84 // Assert.AreEqual ("mono", p.ContentType, "ContentType");
85 Assert
.IsNotNull (p
.Culture
, "Culture");
86 Assert
.IsNull (p
.Form
, "Form");
87 Assert
.IsNull (p
.Header
, "Header");
88 Assert
.IsFalse (p
.IsCallback
, "IsCallback");
89 Assert
.IsFalse (p
.IsCrossPagePostBack
, "IsCrossPagePostBack");
90 Assert
.IsTrue (p
.LCID
!= 0, "LCID");
91 p
.MasterPageFile
= String
.Empty
;
92 Assert
.AreEqual (String
.Empty
, p
.MasterPageFile
, "MasterPageFile");
93 Assert
.IsNull (p
.Master
, "Master");
94 Assert
.IsNull (p
.PageAdapter
, "PageAdapter");
95 Assert
.IsNull (p
.PreviousPage
, "PreviousPage");
96 // p.ResponseEncoding = Encoding.UTF8.WebName;
97 // Assert.AreEqual (Encoding.UTF8.WebName, p.ResponseEncoding, "ResponseEncoding");
98 p
.UICulture
= "en-us";
99 Assert
.IsNotNull (p
.UICulture
, "UICulture");
103 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
104 [ExpectedException (typeof (HttpException
))]
105 public void Cache_Deny_Unrestricted ()
107 Assert
.IsNotNull (new Page ().Cache
, "Cache");
111 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
112 [ExpectedException (typeof (HttpException
))]
113 public void IsValid_Deny_Unrestricted ()
115 Assert
.IsFalse (new Page ().IsValid
, "IsValid");
119 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
120 [ExpectedException (typeof (HttpException
))]
121 public void Request_Deny_Unrestricted ()
123 Assert
.IsNotNull (new Page ().Request
, "Request");
127 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
128 [ExpectedException (typeof (HttpException
))]
129 public void Response_Deny_Unrestricted ()
131 Assert
.IsNotNull (new Page ().Response
, "Response");
135 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
136 [ExpectedException (typeof (NullReferenceException
))]
137 public void Server_Deny_Unrestricted ()
139 Assert
.IsNotNull (new Page ().Server
, "Server");
143 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
144 [ExpectedException (typeof (HttpException
))]
145 public void Session_Deny_Unrestricted ()
147 Assert
.IsNotNull (new Page ().Session
, "Session");
151 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
152 [ExpectedException (typeof (NullReferenceException
))]
153 public void Trace_Deny_Unrestricted ()
155 Assert
.IsNotNull (new Page ().Trace
, "Trace");
159 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
160 [ExpectedException (typeof (NullReferenceException
))]
161 public void User_Deny_Unrestricted ()
163 Assert
.IsNotNull (new Page ().User
, "User");
166 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
167 [ExpectedException (typeof (HttpException
))]
168 public void Buffer_set_Deny_Unrestricted ()
174 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
175 [ExpectedException (typeof (HttpException
))]
176 public void Buffer_get_Deny_Unrestricted ()
178 Assert
.IsTrue (page
.Buffer
, "Buffer");
182 [SecurityPermission (SecurityAction
.Deny
, ControlThread
= true)]
183 [ExpectedException (typeof (SecurityException
))]
184 public void Culture_Deny_ControlThread ()
186 page
.Culture
= "fr-ca";
190 [SecurityPermission (SecurityAction
.PermitOnly
, ControlThread
= true)]
191 public void Culture_PermitOnly_ControlThread ()
193 page
.Culture
= "fr-ca";
197 [SecurityPermission (SecurityAction
.Deny
, ControlThread
= true)]
198 [ExpectedException (typeof (SecurityException
))]
199 public void LCID_Deny_ControlThread ()
205 [SecurityPermission (SecurityAction
.PermitOnly
, ControlThread
= true)]
206 public void LCID_PermitOnly_ControlThread ()
212 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
213 [ExpectedException (typeof (NullReferenceException
))]
214 public void TraceEnabled_set_Deny_Unrestricted ()
216 page
.TraceEnabled
= false;
220 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
221 [ExpectedException (typeof (NullReferenceException
))]
222 public void TraceEnabled_get_Deny_Unrestricted ()
224 Assert
.IsFalse (page
.TraceEnabled
, "TraceEnabled");
228 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
229 [ExpectedException (typeof (NullReferenceException
))]
230 public void TraceModeValue_set_Deny_Unrestricted ()
232 page
.TraceModeValue
= TraceMode
.Default
;
236 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
237 [ExpectedException (typeof (NullReferenceException
))]
238 public void TraceModeValue_get_Deny_Unrestricted ()
240 Assert
.AreEqual (TraceMode
.Default
, page
.TraceModeValue
, "TraceModeValue");
243 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
244 public void Methods_Deny_Unrestricted ()
246 Page p
= new Page ();
247 p
.DesignerInitialize ();
248 Assert
.IsNotNull (p
.GetPostBackClientEvent (control
, "mono"), "GetPostBackClientEvent");
249 Assert
.IsNotNull (p
.GetPostBackClientHyperlink (control
, "mono"), "GetPostBackClientHyperlink");
250 Assert
.IsNotNull (p
.GetPostBackEventReference (control
), "GetPostBackEventReference(control)");
251 Assert
.IsNotNull (p
.GetPostBackEventReference (control
, "mono"), "GetPostBackEventReference(control,string)");
252 Assert
.AreEqual (0, p
.GetTypeHashCode (), "GetTypeHashCode");
253 Assert
.IsFalse (p
.IsClientScriptBlockRegistered ("mono"), "IsClientScriptBlockRegistered");
254 Assert
.IsFalse (p
.IsStartupScriptRegistered ("mono"), "IsStartupScriptRegistered");
255 p
.RegisterArrayDeclaration ("arrayname", "value");
256 p
.RegisterClientScriptBlock ("key", "script");
257 p
.RegisterHiddenField ("name", "hidden");
258 p
.RegisterOnSubmitStatement ("key", "script");
259 p
.RegisterRequiresPostBack (new HtmlTextArea ());
260 p
.RegisterRequiresRaiseEvent (new HtmlAnchor ());
261 p
.RegisterStartupScript ("key", "script");
263 p
.VerifyRenderingInServerForm (control
);
264 p
.Controls
.Add (control
);
265 Assert
.IsNotNull (p
.FindControl ("mono"), "FindControl");
266 p
.RegisterRequiresControlState (control
);
267 Assert
.IsTrue (p
.RequiresControlState (control
), "RequiresControlState");
268 p
.UnregisterRequiresControlState (control
);
269 Assert
.IsNotNull (p
.GetValidators (String
.Empty
), "GetValidators");
270 p
.Validate (String
.Empty
);
274 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
275 public void MapPath_Deny_Unrestricted ()
278 new Page ().MapPath ("/");
280 catch (NullReferenceException
) {
283 catch (HttpException
) {
289 [FileIOPermission (SecurityAction
.Deny
, Unrestricted
= true)]
290 [ExpectedException (typeof (SecurityException
))]
291 public void ProcessRequest_Deny_Unrestricted ()
293 new Page ().ProcessRequest (new HttpContext (null));
297 [FileIOPermission (SecurityAction
.PermitOnly
, Unrestricted
= true)]
298 [ExpectedException (typeof (HttpException
))]
299 public void ProcessRequest_PermitOnly_FileIOPermission ()
301 new Page ().ProcessRequest (new HttpContext (null));
304 private void Handler (object sender
, EventArgs e
)
309 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
310 public void Events_Deny_Unrestricted ()
312 Page p
= new Page ();
313 p
.InitComplete
+= new EventHandler (Handler
);
314 p
.LoadComplete
+= new EventHandler (Handler
);
315 p
.PreInit
+= new EventHandler (Handler
);
316 p
.PreLoad
+= new EventHandler (Handler
);
317 p
.PreRenderComplete
+= new EventHandler (Handler
);
318 p
.SaveStateComplete
+= new EventHandler (Handler
);
320 p
.InitComplete
-= new EventHandler (Handler
);
321 p
.LoadComplete
-= new EventHandler (Handler
);
322 p
.PreInit
-= new EventHandler (Handler
);
323 p
.PreLoad
-= new EventHandler (Handler
);
324 p
.PreRenderComplete
-= new EventHandler (Handler
);
325 p
.SaveStateComplete
-= new EventHandler (Handler
);
330 public override Type Type
{
331 get { return typeof (Page); }