2 // ControlCas.cs - CAS unit tests for System.Web.UI.Control
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.Reflection;
34 using System.Security;
35 using System.Security.Permissions;
38 using System.Web.UI.WebControls;
40 namespace MonoCasTests.System.Web.UI {
44 public class ControlCas : AspNetHostingMinimal {
46 private Control control;
47 private HtmlTextWriter writer;
51 public void FixtureSetUp ()
53 control = new Control ();
54 writer = new HtmlTextWriter (new StringWriter ());
59 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
60 public void Properties_Deny_Unrestricted ()
62 Control c = new Control ();
63 Assert.IsNull (c.ClientID, "ClientID");
64 Assert.IsNotNull (c.Controls, "Controls");
65 c.EnableViewState = true;
66 Assert.IsTrue (c.EnableViewState, "EnableViewState");
68 Assert.AreEqual ("mono", c.ID, "ID");
69 Assert.IsNull (c.NamingContainer, "NamingContainer");
70 Assert.IsNull (c.Page, "Page");
71 Assert.IsNull (c.Parent, "Parent");
72 Assert.IsNull (c.Site, "Site");
73 Assert.AreEqual ("mono", c.UniqueID, "UniqueID");
74 Assert.IsTrue (c.Visible, "Visible");
76 c.AppRelativeTemplateSourceDirectory = String.Empty;
77 Assert.AreEqual (String.Empty, c.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory");
78 c.EnableTheming = true;
79 Assert.IsTrue (c.EnableTheming, "EnableTheming");
80 c.SkinID = String.Empty;
81 Assert.AreEqual (String.Empty, c.SkinID, "SkinID");
82 c.TemplateControl = null;
83 Assert.IsNull (c.TemplateControl, "TemplateControl");
84 Assert.AreEqual (String.Empty, c.TemplateSourceDirectory, "TemplateSourceDirectory");
88 private void SetRenderMethodDelegate (HtmlTextWriter writer, Control control)
93 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
94 public void Methods_Deny_Unrestricted ()
96 Control c = new Control ();
99 Assert.IsNull (c.FindControl ("mono"), "FindControl");
101 Assert.IsFalse (c.HasControls (), "HasControls");
102 c.RenderControl (writer);
103 Assert.IsNotNull (c.ResolveUrl (String.Empty), "ResolveUrl");
104 c.SetRenderMethodDelegate (new RenderMethod (SetRenderMethodDelegate));
106 c.ApplyStyleSheetSkin (page);
107 Assert.IsNotNull (c.ResolveClientUrl (String.Empty), "ResolveClientUrl");
114 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
115 [ExpectedException (typeof (InvalidOperationException))]
116 public void Focus_Deny_Unrestricted ()
118 Control c = new Control ();
119 page.Controls.Add (c);
121 // normal, no forms on page
125 private void Handler (object sender, EventArgs e)
130 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
131 public void Events_Deny_Unrestricted ()
133 Control c = new Control ();
134 c.DataBinding += new EventHandler (Handler);
135 c.Disposed += new EventHandler (Handler);
136 c.Init += new EventHandler (Handler);
137 c.Load += new EventHandler (Handler);
138 c.PreRender += new EventHandler (Handler);
139 c.Unload += new EventHandler (Handler);
141 c.DataBinding -= new EventHandler (Handler);
142 c.Disposed -= new EventHandler (Handler);
143 c.Init -= new EventHandler (Handler);
144 c.Load -= new EventHandler (Handler);
145 c.PreRender -= new EventHandler (Handler);
146 c.Unload -= new EventHandler (Handler);
151 public override Type Type {
152 get { return typeof (Control); }