update readme (#21797)
[mono-project.git] / mcs / class / System.Web / Test / System.Web.UI / PageCas.cs
blob46ca9b74842ac97a16d2a2cfd5841f3aaabe4c1b
1 //
2 // PageCas.cs - CAS unit tests for System.Web.UI.Page
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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;
31 using System;
32 using System.IO;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Text;
36 using System.Web;
37 using System.Web.UI;
38 using System.Web.UI.HtmlControls;
40 namespace MonoCasTests.System.Web.UI {
42 [TestFixture]
43 [Category ("CAS")]
44 public class PageCas : AspNetHostingMinimal {
46 private Control control;
47 private Page page;
49 [TestFixtureSetUp]
50 public void FixtureSetUp ()
52 control = new Control ();
53 control.ID = "mono";
54 page = new Page ();
57 [Test]
58 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
59 public void Properties_Deny_Unrestricted ()
61 Page p = new Page ();
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");
69 p.ID = "mono";
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");
78 p.Visible = true;
79 Assert.IsTrue (p.Visible, "Visible");
80 Assert.IsNotNull (p.ClientScript, "ClientScript");
81 // p.CodePage = 0;
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");
102 [Test]
103 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
104 [ExpectedException (typeof (HttpException))]
105 public void Cache_Deny_Unrestricted ()
107 Assert.IsNotNull (new Page ().Cache, "Cache");
110 [Test]
111 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
112 [ExpectedException (typeof (HttpException))]
113 public void IsValid_Deny_Unrestricted ()
115 Assert.IsFalse (new Page ().IsValid, "IsValid");
118 [Test]
119 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
120 [ExpectedException (typeof (HttpException))]
121 public void Request_Deny_Unrestricted ()
123 Assert.IsNotNull (new Page ().Request, "Request");
126 [Test]
127 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
128 [ExpectedException (typeof (HttpException))]
129 public void Response_Deny_Unrestricted ()
131 Assert.IsNotNull (new Page ().Response, "Response");
134 [Test]
135 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
136 [ExpectedException (typeof (NullReferenceException))]
137 public void Server_Deny_Unrestricted ()
139 Assert.IsNotNull (new Page ().Server, "Server");
142 [Test]
143 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
144 [ExpectedException (typeof (HttpException))]
145 public void Session_Deny_Unrestricted ()
147 Assert.IsNotNull (new Page ().Session, "Session");
150 [Test]
151 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
152 [ExpectedException (typeof (NullReferenceException))]
153 public void Trace_Deny_Unrestricted ()
155 Assert.IsNotNull (new Page ().Trace, "Trace");
158 [Test]
159 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
160 [ExpectedException (typeof (NullReferenceException))]
161 public void User_Deny_Unrestricted ()
163 Assert.IsNotNull (new Page ().User, "User");
165 [Test]
166 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
167 [ExpectedException (typeof (HttpException))]
168 public void Buffer_set_Deny_Unrestricted ()
170 page.Buffer = true;
173 [Test]
174 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
175 [ExpectedException (typeof (HttpException))]
176 public void Buffer_get_Deny_Unrestricted ()
178 Assert.IsTrue (page.Buffer, "Buffer");
181 [Test]
182 [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
183 [ExpectedException (typeof (SecurityException))]
184 public void Culture_Deny_ControlThread ()
186 page.Culture = "fr-ca";
189 [Test]
190 [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true)]
191 public void Culture_PermitOnly_ControlThread ()
193 page.Culture = "fr-ca";
196 [Test]
197 [SecurityPermission (SecurityAction.Deny, ControlThread = true)]
198 [ExpectedException (typeof (SecurityException))]
199 public void LCID_Deny_ControlThread ()
201 page.LCID = 0x409;
204 [Test]
205 [SecurityPermission (SecurityAction.PermitOnly, ControlThread = true)]
206 public void LCID_PermitOnly_ControlThread ()
208 page.LCID = 0x409;
211 [Test]
212 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
213 [ExpectedException (typeof (NullReferenceException))]
214 public void TraceEnabled_set_Deny_Unrestricted ()
216 page.TraceEnabled = false;
219 [Test]
220 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
221 [ExpectedException (typeof (NullReferenceException))]
222 public void TraceEnabled_get_Deny_Unrestricted ()
224 Assert.IsFalse (page.TraceEnabled, "TraceEnabled");
227 [Test]
228 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
229 [ExpectedException (typeof (NullReferenceException))]
230 public void TraceModeValue_set_Deny_Unrestricted ()
232 page.TraceModeValue = TraceMode.Default;
235 [Test]
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");
242 [Test]
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");
262 p.Validate ();
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);
273 [Test]
274 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
275 public void MapPath_Deny_Unrestricted ()
277 try {
278 new Page ().MapPath ("/");
280 catch (NullReferenceException) {
281 // ms 1.x + 2.0
283 catch (HttpException) {
284 // mono
288 [Test]
289 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
290 [ExpectedException (typeof (SecurityException))]
291 public void ProcessRequest_Deny_Unrestricted ()
293 new Page ().ProcessRequest (new HttpContext (null));
296 [Test]
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)
308 [Test]
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);
328 // LinkDemand
330 public override Type Type {
331 get { return typeof (Page); }