Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / PanelTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.Panel.cs 
3 //
4 // Author:
5 //     Ben Maurer <bmaurer@novell.com>
6 //     Yoni Klain <yonik@mainsoft.com>
7 //
8
9 //
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using NUnit.Framework;
33 using System;
34 using System.IO;
35 using System.Globalization;
36 using System.Web;
37 using System.Web.UI;
38 using System.Web.UI.WebControls;
39 using System.Drawing;
40 using MonoTests.stand_alone.WebHarness;
41 using MonoTests.SystemWeb.Framework;
42
43 namespace MonoTests.System.Web.UI.WebControls {
44         [TestFixture]
45         public class PanelTest
46         {
47                 #region helpclasses
48                 class Poker : Panel {
49                         
50                         public string Render ()
51                         {
52                                 StringWriter sw = new StringWriter ();
53                                 sw.NewLine = "\n";
54                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
55                                 base.Render (writer);
56                                 return writer.InnerWriter.ToString ();
57                         }
58                 }
59         
60                 class PokerS : Panel
61                 {
62                         public string Render ()
63                         {
64                                 StringWriter sw = new StringWriter ();
65                                 sw.NewLine = "\n";
66                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
67                                 base.Render (writer);
68                                 return writer.InnerWriter.ToString ();
69                         }
70                         protected override Style CreateControlStyle ()
71                         {
72                                 Style s = new Style (new StateBag ());
73                                 s.BackColor = Color.Red;
74                                 s.BorderColor = Color.Red;
75                                 return s;
76                         }
77
78                         public override void RenderBeginTag (HtmlTextWriter writer)
79                         {
80                                 base.RenderBeginTag (writer);
81                         }
82
83                         public override void RenderEndTag (HtmlTextWriter writer)
84                         {
85                                 base.RenderEndTag (writer);
86                         }
87
88                         public  string RenderBeginTag ()
89                         {
90                                 StringWriter sw = new StringWriter ();
91                                 sw.NewLine = "\n";
92                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
93                                 base.RenderBeginTag (writer);
94                                 return writer.InnerWriter.ToString ();
95                         }
96
97                         public  string RenderEndTag ()
98                         {
99                                 StringWriter sw = new StringWriter ();
100                                 sw.NewLine = "\n";
101                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
102                                 base.RenderBeginTag (writer);
103                                 base.RenderEndTag (writer);
104                                 return writer.InnerWriter.ToString ();
105                         }
106                 }
107
108                 class PokerR : Panel
109                 {
110                         public string Render ()
111                         {
112                                 StringWriter sw = new StringWriter ();
113                                 sw.NewLine = "\n";
114                                 HtmlTextWriter writer = new HtmlTextWriter (sw);
115                                 sw.Write ("Render");
116                                 base.Render (writer);
117                                 return writer.InnerWriter.ToString ();
118                         }
119
120                         public override void RenderBeginTag (HtmlTextWriter writer)
121                         {
122                                 writer.Write ("RenderBeginTag");
123                         }
124
125                         public override void RenderEndTag (HtmlTextWriter writer)
126                         {
127                                 writer.Write ("RenderEndTag");
128                         }
129                 }
130                 #endregion
131
132                 [TestFixtureSetUp]
133                 public void SetUp ()
134                 {
135                         WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
136                 }
137
138                 [Test]
139                 public void Defaults ()
140                 {
141                         Poker p = new Poker ();
142
143                         Assert.AreEqual (ContentDirection.NotSet, p.Direction, "Direction"); 
144                         Assert.AreEqual (string.Empty, p.GroupingText, "GroupingText");
145                         Assert.AreEqual (ScrollBars.None, p.ScrollBars, "ScrollBars"); 
146                         Assert.AreEqual (string.Empty, p.DefaultButton, "DefaultButton");
147                 }
148                 
149                 [Test]
150                 public void NoWrap ()
151                 {
152                         Poker p = new Poker ();
153                         p.Wrap = false;
154                         p.Controls.Add (new LiteralControl ("TEXT"));
155                         const string html ="<div style=\"white-space:nowrap;\">\n\tTEXT\n</div>";
156                         Assert.AreEqual (html, p.Render ());
157                 }
158
159                 [Test]
160                 public void CreateControlStyle ()
161                 {
162                         PokerS p = new PokerS ();
163                         Style s = p.ControlStyle;
164                         Assert.AreEqual (Color.Red, s.BackColor, "CreateControlStyle#1");
165                         Assert.AreEqual (Color.Red, s.BorderColor, "CreateControlStyle#2");
166                         p.ApplyStyle (s);
167                         string html = p.Render ();
168                         string origHtml = "<div style=\"background-color:Red;border-color:Red;\">\n\n</div>";
169                         HtmlDiff.AssertAreEqual (origHtml, html, "CreateControlStyle");
170                 }
171
172                 [Test]
173                 [Category ("NunitWeb")]
174                 public void DefaultButton ()
175                 {
176                         WebTest t = new WebTest ("NoEventValidation.aspx");
177                         t.Invoker = PageInvoker.CreateOnInit (DefaultButton__Init);
178                         t.Run ();
179                 }
180
181                 public static void DefaultButton__Init (Page p)
182                 {
183                         Poker pl = new Poker ();
184                         pl.DefaultButton = "MyButton";
185                         Button b = new Button ();
186                         b.ID = "MyButton";
187                         p.Form.Controls.Add (b);
188                         p.Form.Controls.Add (pl);
189                         string html = pl.Render ();
190                         if (html.IndexOf ("onkeypress") == -1)
191                                 Assert.Fail ("Default button script not created #1");
192                         if (html.IndexOf ("MyButton") == -1)
193                                 Assert.Fail ("Default button script not created #2");
194                 }
195                 
196                 [Test]
197                 [Category("NunitWeb")]
198                 [ExpectedException(typeof(InvalidOperationException))]
199                 public void DefaultButton_Exception ()
200                 {
201                         WebTest t = new WebTest ("NoEventValidation.aspx");
202                         t.Invoker = PageInvoker.CreateOnInit (DefaultButton_Init);
203                         t.Run ();
204
205                 }
206
207                 public static void DefaultButton_Init (Page p)
208                 {
209                         Poker pl = new Poker ();
210                         pl.DefaultButton = "test";
211                         p.Form.Controls.Add (pl);
212                         pl.Render ();
213
214                 }
215
216                 [Test]
217                 public void Direction ()
218                 {
219                         Poker p = new Poker ();
220                         p.Direction = ContentDirection.LeftToRight;
221                         string html = p.Render();
222                         string origHtml = "<div dir=\"ltr\">\n\n</div>";
223                         HtmlDiff.AssertAreEqual (origHtml, html, "Direction");
224                 }
225
226                 [Test]
227                 public void GroupingText ()
228                 {
229                         Poker p = new Poker ();
230                         p.GroupingText = "MyNameText";
231                         string html = p.Render ();
232                         string origHtml = "<div>\n\t<fieldset>\n\t\t<legend>\n\t\t\tMyNameText\n\t\t</legend>\n\t</fieldset>\n</div>";
233                         HtmlDiff.AssertAreEqual (origHtml, html, "GroupingText");
234                 }
235
236                 [Test]
237                 public void RenderBeginTag ()
238                 {
239                         PokerS p = new PokerS ();
240                         string html = p.RenderBeginTag ();
241                         HtmlDiff.AssertAreEqual ("<div>\n", html, "RenderBeginTag");
242                 }
243
244                 [Test]
245                 public void RenderEndTag ()
246                 {
247                         PokerS p = new PokerS ();
248                         string html = p.RenderEndTag ();
249                         HtmlDiff.AssertAreEqual ("<div>\n\n</div>", html, "RenderBeginTag");
250                 }
251
252                 [Test]
253                 public void RenderFlow ()
254                 {
255                         PokerR p = new PokerR ();
256                         string html = p.Render ();
257                         Assert.AreEqual ("RenderRenderBeginTagRenderEndTag", html, "RenderFlow");
258                 }
259
260                 [Test]
261                 public void Scroll_Bars ()
262                 {
263                         Poker p = new Poker ();
264                         p.ScrollBars = ScrollBars.Horizontal;
265                         string html = p.Render ();
266                         string origHtml1 = "<div style=\"overflow-x:scroll;\">\n\n</div>";
267                         HtmlDiff.AssertAreEqual (origHtml1, html, "ScrollBars.Horizontal");
268                         p.ScrollBars = ScrollBars.Vertical;
269                         html = p.Render ();
270                         string origHtml2 = "<div style=\"overflow-y:scroll;\">\n\n</div>";
271                         HtmlDiff.AssertAreEqual (origHtml2, html, "ScrollBars.Vertical");
272                         p.ScrollBars = ScrollBars.Both;
273                         html = p.Render ();
274                         string origHtml3 = "<div style=\"overflow:scroll;\">\n\n</div>";
275                         HtmlDiff.AssertAreEqual (origHtml3, html, "ScrollBars.Both");
276                 }
277
278                 [TestFixtureTearDown]
279                 public void TearDown ()
280                 {
281                         WebTest.Unload ();
282                 }
283         }
284 }
285
286