New tests.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI / ControlTest.cs
1 //
2 // Tests for System.Web.UI.Control
3 //
4 // Author:
5 //      Peter Dennis Bartok (pbartok@novell.com)
6 //      Gonzalo Paniagua Javier (gonzalo@novell.com)
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9
10
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.Collections;
35 using System.Drawing;
36 using System.IO;
37 using System.Globalization;
38 using System.Web;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
41 using MonoTests.SystemWeb.Framework;
42 using MonoTests.stand_alone.WebHarness;
43
44 #if NET_2_0
45 using System.Web.UI.Adapters;
46 #endif
47
48 namespace MonoTests.System.Web.UI
49 {
50         [TestFixture]
51         public class ControlTest
52         {
53                 [Test]
54                 public void DataBindingInterfaceTest ()
55                 {
56                         Control c;
57                         DataBindingCollection db;
58
59                         c = new Control ();
60                         Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB1");
61                         db = ((IDataBindingsAccessor) c).DataBindings;
62                         Assert.IsNotNull (db, "DB2");
63                         Assert.AreEqual (false, ((IDataBindingsAccessor) c).HasDataBindings, "DB3");
64                         db.Add (new DataBinding ("property", typeof (bool), "expression"));
65                         Assert.AreEqual (true, ((IDataBindingsAccessor) c).HasDataBindings);
66                 }
67
68                 [Test] // bug #82546
69                 public void FindControl_NamingContainer ()
70                 {
71                         Control topControl = new NamingContainer ();
72                         topControl.ID = "top";
73
74                         Control controlLevel1A = new Control ();
75                         controlLevel1A.ID = "Level1#A";
76                         topControl.Controls.Add (controlLevel1A);
77
78                         Control controlLevel1B = new Control ();
79                         controlLevel1B.ID = "Level1#B";
80                         topControl.Controls.Add (controlLevel1B);
81
82                         Control controlLevel2AA = new Control ();
83                         controlLevel2AA.ID = "Level2#AA";
84                         controlLevel1A.Controls.Add (controlLevel2AA);
85
86                         Control controlLevel2AB = new Control ();
87                         controlLevel2AB.ID = "Level2#AB";
88                         controlLevel1A.Controls.Add (controlLevel2AB);
89
90                         Control foundControl = topControl.FindControl ("Level1#A");
91                         Assert.IsNotNull (foundControl, "#A1");
92                         Assert.AreSame (controlLevel1A, foundControl, "#A2");
93
94                         foundControl = topControl.FindControl ("LEVEL1#B");
95                         Assert.IsNotNull (foundControl, "#B1");
96                         Assert.AreSame (controlLevel1B, foundControl, "#B2");
97
98                         foundControl = topControl.FindControl ("LeVeL2#AB");
99                         Assert.IsNotNull (foundControl, "#C1");
100                         Assert.AreSame (controlLevel2AB, foundControl, "#C2");
101
102                         foundControl = topControl.FindControl ("doesnotexist");
103                         Assert.IsNull (foundControl, "#D1");
104                         foundControl = topControl.FindControl ("top");
105                         Assert.IsNull (foundControl, "#D2");
106
107                         foundControl = controlLevel1A.FindControl ("Level2#AA");
108                         Assert.IsNotNull (foundControl, "#E1");
109                         Assert.AreSame (controlLevel2AA, foundControl, "#E2");
110
111                         foundControl = controlLevel1A.FindControl ("LEveL2#ab");
112                         Assert.IsNotNull (foundControl, "#F1");
113                         Assert.AreSame (controlLevel2AB, foundControl, "#F2");
114                 }
115
116                 [Test]
117                 public void UniqueID1 ()
118                 {
119                         // Standalone NC
120                         Control nc = new MyNC ();
121                         Assert.IsNull (nc.UniqueID, "nulltest");
122                 }
123                 
124                 [Test]
125                 public void UniqueID1_1 () {
126                         // Standalone NC
127                         Control nc = new MyNC ();
128                         Page p = new Page ();
129                         p.Controls.Add (nc);
130                         Assert.IsNotNull (nc.UniqueID, "notnull");
131                 }
132                 
133                 [Test]
134                 public void UniqueID2 ()
135                 {
136                         // NC in NC
137                         Control nc = new MyNC ();
138                         Control nc2 = new MyNC ();
139                         nc2.Controls.Add (nc);
140                         Assert.IsNotNull (nc.UniqueID, "notnull");
141                         Assert.IsTrue (nc.UniqueID.IndexOfAny (new char[] { ':', '$' }) == -1, "separator");
142                 }
143
144                 [Test]
145                 public void UniqueID2_1 () {
146                         // NC in NC
147                         Control nc = new MyNC ();
148                         Control nc2 = new MyNC ();
149                         nc2.Controls.Add (nc);
150                         Page p = new Page ();
151                         p.Controls.Add (nc2);
152                         Assert.IsNotNull (nc.UniqueID, "notnull");
153                         Assert.IsTrue (nc.UniqueID.IndexOfAny (new char [] { ':', '$' }) != -1, "separator");
154                 }
155
156                 [Test]
157                 public void UniqueID3 ()
158                 {
159                         // NC in control
160                         Control control = new Control ();
161                         Control nc = new MyNC ();
162
163                         control.Controls.Add (nc);
164                         Assert.IsNull (nc.UniqueID, "null");
165                 }
166
167                 [Test]
168                 public void UniqueID4 ()
169                 {
170                         // NC in control
171                         Control control = new Control ();
172                         Control nc = new MyNC ();
173
174                         nc.Controls.Add (control);
175                         Assert.IsNotNull (control.UniqueID, "notnull");
176                 }
177
178                 [Test]
179                 public void UniqueID5 ()
180                 {
181                         // NC in control
182                         Control control = new Control ();
183                         Control nc = new MyNC ();
184                         Control nc2 = new MyNC ();
185
186                         nc2.Controls.Add (nc);
187                         nc.Controls.Add (control);
188                         Assert.IsNotNull (control.UniqueID, "notnull");
189                         Assert.IsNull (nc2.ID, "null-1");
190                         Assert.IsNull (nc.ID, "null-2");
191                         Assert.IsTrue (-1 != control.UniqueID.IndexOfAny (new char[] { ':', '$' }), "separator");
192                 }
193
194                 [Test]
195                 public void UniqueID6 () {
196                         // NC in NC
197                         Control nc = new MyNC ();
198                         Page p = new Page ();
199                         p.Controls.Add (nc);
200                         Assert.IsNotNull (nc.UniqueID, "notnull");
201
202                         Control c1 = new Control ();
203                         Control c2 = new Control ();
204                         nc.Controls.Add (c1);
205                         nc.Controls.Add (c2);
206                         string uid1_1 = c1.UniqueID;
207                         string uid2_1 = c2.UniqueID;
208
209                         nc.Controls.Clear ();
210
211                         Assert.IsNull (c1.UniqueID);
212                         Assert.IsNull (c2.UniqueID);
213
214                         // ad in another order
215                         nc.Controls.Add (c2);
216                         nc.Controls.Add (c1);
217                         string uid1_2 = c1.UniqueID;
218                         string uid2_2 = c2.UniqueID;
219
220                         Assert.IsFalse (uid1_1 == uid1_2);
221                         Assert.IsFalse (uid2_1 == uid2_2);
222                         Assert.AreEqual (uid1_1, uid2_2);
223                         Assert.AreEqual (uid2_1, uid1_2);
224
225                         nc.Controls.Remove (c1);
226                         nc.Controls.Add (c1);
227                         string uid1_3 = c1.UniqueID;
228                         Assert.IsFalse (uid1_3 == uid1_2, "id was not reset");
229
230 #if NET_2_0
231                         EnsureIDControl c3 = new EnsureIDControl ();
232                         nc.Controls.Add (c3);
233                         string uid3_1 = c3.UniqueID;
234                         c3.DoEnsureID ();
235                         Assert.IsNotNull (c3.ID);
236                         nc.Controls.Remove (c3);
237                         nc.Controls.Add (c3);
238                         string uid3_2 = c3.UniqueID;
239                         Assert.IsNull (c3.ID);
240                         Assert.IsFalse (uid3_1 == uid3_2, "id was not reset");
241 #endif
242                 }
243
244                 [Test]
245                 public void ClientID () 
246                 {
247                         // NC in control
248                         Control control = new Control ();
249                         Control nc = new MyNC ();
250                         Control nc2 = new MyNC ();
251                         Control nc3 = new MyNC ();
252
253                         nc3.Controls.Add (nc2);
254                         nc2.Controls.Add (nc);
255                         nc.Controls.Add (control);
256 #if NET_2_0
257                         string expected = "ctl00_ctl00_ctl00";
258 #else
259                         string expected = "_ctl0__ctl0__ctl0";
260 #endif
261                         Assert.AreEqual (expected, control.ClientID, "ClientID");
262                 }
263
264                 // From bug #76919: Control uses _controls instead of
265                 // Controls when RenderChildren is called.
266                 [Test]
267                 public void Controls1 ()
268                 {
269                         DerivedControl derived = new DerivedControl ();
270                         derived.Controls.Add (new LiteralControl ("hola"));
271                         StringWriter sw = new StringWriter ();
272                         HtmlTextWriter htw = new HtmlTextWriter (sw);
273                         derived.RenderControl (htw);
274                         string result = sw.ToString ();
275                         Assert.AreEqual ("", result, "#01");
276                 }
277
278                 [Test] // Bug #471305
279                 [Category ("NunitWeb")]
280                 public void NoDoubleOnInitOnRemoveAdd ()
281                 {
282                         WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx", "NoDoubleOnInitOnRemoveAdd.aspx");
283                         WebTest.CopyResource (GetType (), "NoDoubleOnInitOnRemoveAdd.aspx.cs", "NoDoubleOnInitOnRemoveAdd.aspx.cs");
284                         WebTest t = new WebTest ("NoDoubleOnInitOnRemoveAdd.aspx");
285                         string html = t.Run ();
286
287                         Assert.AreEqual (-1, html.IndexOf ("<span>label</span><span>label</span>"), "#A1");
288                 }
289                 
290 #if NET_2_0
291                 [Test]
292                 [Category("NunitWeb")]
293                 public void AppRelativeTemplateSourceDirectory ()
294                 {
295                         new WebTest(PageInvoker.CreateOnLoad(AppRelativeTemplateSourceDirectory_Load)).Run();
296                 }
297                 
298                 public static void AppRelativeTemplateSourceDirectory_Load(Page p)
299                 {
300                         Control ctrl = new Control();
301                         Assert.AreEqual("~/", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#1");
302                         ctrl.AppRelativeTemplateSourceDirectory = "~/Fake";
303                         Assert.AreEqual("~/Fake", ctrl.AppRelativeTemplateSourceDirectory, "AppRelativeTemplateSourceDirectory#2");
304                 }
305
306                 [Test]
307                 public void ApplyStyleSheetSkin ()
308                 {
309                         Page p = new Page ();
310                         p.StyleSheetTheme = "";
311                         Control c = new Control ();
312                         c.ApplyStyleSheetSkin (p);
313                 }
314
315                 [Test]
316                 [Category ("NunitWeb")]
317                 public void ApplyStyleSheetSkin_1 ()
318                 {
319                         WebTest.CopyResource (GetType (), "Theme2.skin", "App_Themes/Theme2/Theme2.skin");
320                         WebTest t = new WebTest ();
321                         PageDelegates pd = new PageDelegates ();
322                         pd.PreInit = ApplyStyleSheetSkin_PreInit;
323                         pd.Load = ApplyStyleSheetSkin_Load;
324                         t.Invoker = new PageInvoker (pd);
325                         string str = t.Run ();
326                 }
327                 public static void ApplyStyleSheetSkin_PreInit (Page p)
328                 {
329                         p.Theme = "Theme2";
330                 }
331                 public static void ApplyStyleSheetSkin_Load (Page p)
332                 {
333                         Label lbl = new Label ();
334                         lbl.ID = "StyleLbl";
335                         lbl.SkinID = "red";
336                         lbl.Text = "StyleLabel";
337                         p.Controls.Add (lbl);
338                         lbl.ApplyStyleSheetSkin (p);
339                         Assert.AreEqual (Color.Red, lbl.ForeColor, "ApplyStyleSheetSkin_BackColor");
340                         Assert.AreEqual ("TextFromSkinFile", lbl.Text, "ApplyStyleSheetSkin");
341                 }
342
343                 [Test]
344                 [Category ("NunitWeb")]
345                 public void ClearChildControlState ()
346                 {
347                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildControlState_Load));
348                         t.Run ();
349                         FormRequest fr = new FormRequest (t.Response, "form1");
350                         fr.Controls.Add ("__EVENTTARGET");
351                         fr.Controls.Add ("__EVENTARGUMENT");
352                         fr.Controls["__EVENTTARGET"].Value = "";
353                         fr.Controls["__EVENTARGUMENT"].Value = "";
354                         t.Request = fr;
355                         t.Run ();
356                 }
357                 public static void ClearChildControlState_Load (Page p)
358                 {
359                         ControlWithState c1 = new ControlWithState ();
360                         p.Form.Controls.Add (c1);
361                         if (p.IsPostBack) {
362                                 c1.ClearChildControlState ();
363                         }
364                         ControlWithState c2 = new ControlWithState ();
365                         c1.Controls.Add (c2);
366                         ControlWithState c3 = new ControlWithState ();
367                         c2.Controls.Add (c3);
368                         if (!p.IsPostBack) {
369                                 c1.State = "State";
370                                 c2.State = "Cool";
371                                 c3.State = "SubCool";
372                         }
373                         else {
374                                 Assert.AreEqual ("State", c1.State, "ControlState#1");
375                                 Assert.AreEqual (null, c2.State, "ControlState#2");
376                                 Assert.AreEqual (null, c3.State, "ControlState#2");
377                         }
378                 }
379
380                 [Test]
381                 [Category ("NunitWeb")]
382                 public void ClearChildState ()
383                 {
384                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ClearChildState_Load));
385                         t.Run ();
386                         FormRequest fr = new FormRequest (t.Response, "form1");
387                         fr.Controls.Add ("__EVENTTARGET");
388                         fr.Controls.Add ("__EVENTARGUMENT");
389                         fr.Controls["__EVENTTARGET"].Value = "";
390                         fr.Controls["__EVENTARGUMENT"].Value = "";
391                         t.Request = fr;
392                         t.Run ();
393                 }
394                 public static void ClearChildState_Load (Page p)
395                 {
396                         ControlWithState c1 = new ControlWithState ();
397                         p.Form.Controls.Add (c1);
398                         if (p.IsPostBack) {
399                                 c1.ClearChildState ();
400                         }
401                         ControlWithState c2 = new ControlWithState ();
402                         c1.Controls.Add (c2);
403                         ControlWithState c3 = new ControlWithState ();
404                         c2.Controls.Add (c3);
405                         if (!p.IsPostBack) {
406                                 c1.State = "State";
407                                 c2.State = "Cool";
408                                 c2.Viewstate = "Very Cool";
409                                 c3.State = "SubCool";
410                                 c3.Viewstate = "Super Cool";
411                         }
412                         else {
413                                 Assert.AreEqual ("State", c1.State, "ClearChildState#1");
414                                 Assert.AreEqual (null, c2.State, "ClearChildState#2");
415                                 Assert.AreEqual (null, c3.State, "ClearChildState#3");
416                                 Assert.AreEqual (null, c2.Viewstate, "ClearChildState#4");
417                                 Assert.AreEqual (null, c3.Viewstate, "ClearChildState#5");
418                         }
419                 }
420
421                 [Test]
422                 public void DataBind ()
423                 {
424                         MyNC ctrl = new MyNC ();
425                         ctrl.DataBinding += new EventHandler (ctrl_DataBinding);
426                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
427                         ctrl.DataBind (false);
428                         Assert.AreEqual (false, _eventDataBinding, "Before DataBinding");
429                         ctrl.DataBind (true);
430                         Assert.AreEqual (true, _eventDataBinding, "After DataBinding");
431                 }
432                 bool _eventDataBinding;
433                 void ctrl_DataBinding (object sender, EventArgs e)
434                 {
435                         _eventDataBinding = true;
436                 }
437
438                 [Test]
439                 public void DataBindChildren ()
440                 {
441                         MyNC ctrl1 = new MyNC ();
442                         Control ctrl2 = new Control ();
443                         Control ctrl3 = new Control ();
444                         ctrl2.DataBinding += new EventHandler (ctrl2_DataBinding);
445                         ctrl3.DataBinding += new EventHandler (ctrl3_DataBinding);
446
447                         ctrl2.Controls.Add (ctrl3);
448                         ctrl1.Controls.Add (ctrl2);
449                         Assert.AreEqual (false, _eventChild1, "Before DataBinding#1");
450                         Assert.AreEqual (false, _eventChild2, "Before DataBinding#2");
451                         ctrl1.DataBindChildren ();
452                         Assert.AreEqual (true, _eventChild1, "After DataBinding#1");
453                         Assert.AreEqual (true, _eventChild2, "After DataBinding#2");
454                 }
455                 bool _eventChild1;
456                 bool _eventChild2;
457                 void ctrl3_DataBinding (object sender, EventArgs e)
458                 {
459                         _eventChild1 = true;
460                 }
461                 void ctrl2_DataBinding (object sender, EventArgs e)
462                 {
463                         _eventChild2 = true;
464                 }
465
466                 [Test]
467                 public void EnsureID ()
468                 {
469                         MyNC ctrl = new MyNC ();
470                         MyNC ctrl1 = new MyNC ();
471                         ctrl.Controls.Add (ctrl1);
472                         Page p = new Page ();
473                         p.Controls.Add (ctrl);
474                         ctrl.EnsureID ();
475                         if (String.IsNullOrEmpty (ctrl.ID))
476                                 Assert.Fail ("EnsureID#1");
477                         ctrl1.EnsureID ();
478                         if (String.IsNullOrEmpty (ctrl1.ID))
479                                 Assert.Fail ("EnsureID#2");
480                 }
481
482                 [Test]
483                 [Category("NotWorking")]
484                 public void Focus ()
485                 {
486                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (Focus_Load));
487                         string html = t.Run ();
488                         Assert.AreEqual (3, contain (html, "TestBox"), "Focus script not created");
489
490                 }
491                 public static void Focus_Load (Page p)
492                 {
493                         TextBox tbx = new TextBox ();
494                         tbx.ID = "TestBox";
495                         p.Controls.Add (tbx);
496                         tbx.Focus ();
497                 }
498                 int contain (string orig, string compare)
499                 {
500                         if (orig.IndexOf (compare) == -1)
501                                 return 0;
502                         return 1 + contain (orig.Substring (orig.IndexOf (compare) + compare.Length), compare);
503                 }
504
505                 [Test]
506                 public void HasEvent ()
507                 {
508                         MyNC ctrl1 = new MyNC ();
509                         Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#1");
510                         EventHandler ctrl_hdlr = new EventHandler (ctrl1_Init);
511                         ctrl1.Init += new EventHandler (ctrl1_Init);
512                         ctrl1.Init += ctrl_hdlr;
513                         Assert.AreEqual (true, ctrl1.HasEvents (), "HasEvent#2");
514                         // Dosn't work than removed handler
515                         //ctrl1.Init -= ctrl_hdlr;
516                         //Assert.AreEqual (false, ctrl1.HasEvents (), "HasEvent#3");
517                 }
518                 void ctrl1_Init (object sender, EventArgs e)
519                 {
520                         throw new Exception ("The method or operation is not implemented.");
521                 }
522
523                 [Test]
524                 public void IsViewStateEnabled ()
525                 {
526                         DerivedControl c = new DerivedControl ();
527                         Assert.IsTrue (c.DoIsViewStateEnabled);
528                         Page p = new Page ();
529                         c.Page = p;
530                         p.Controls.Add (c);
531                         Assert.IsTrue (c.DoIsViewStateEnabled);
532                         p.EnableViewState = false;
533                         Assert.IsFalse (c.DoIsViewStateEnabled);
534                 }
535
536                 [Test]
537                 [Category ("NunitWeb")]
538                 public void ControlState ()
539                 {
540                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState_Load));
541                         t.Run ();
542                         FormRequest fr = new FormRequest (t.Response, "form1");
543                         fr.Controls.Add ("__EVENTTARGET");
544                         fr.Controls.Add ("__EVENTARGUMENT");
545                         fr.Controls["__EVENTTARGET"].Value = "";
546                         fr.Controls["__EVENTARGUMENT"].Value = "";
547                         t.Request = fr;
548                         t.Run ();
549                 }
550                 public static void ControlState_Load (Page p)
551                 {
552                         ControlWithState c1 = new ControlWithState ();
553                         ControlWithState c2 = new ControlWithState ();
554                         c1.Controls.Add (c2);
555                         p.Form.Controls.Add (c1);
556                         if (!p.IsPostBack) {
557                                 c1.State = "State";
558                                 c2.State = "Cool";
559                         }
560                         else {
561                                 ControlWithState c3 = new ControlWithState ();
562                                 p.Form.Controls.Add (c3);
563                                 Assert.AreEqual ("State", c1.State, "ControlState");
564                                 Assert.AreEqual ("Cool", c2.State, "ControlState");
565                         }
566                 }
567
568                 [Test]
569                 [Category ("NunitWeb")]
570                 public void ControlState2 () {
571                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ControlState2_Load));
572                         t.Run ();
573                         FormRequest fr = new FormRequest (t.Response, "form1");
574                         fr.Controls.Add ("__EVENTTARGET");
575                         fr.Controls.Add ("__EVENTARGUMENT");
576                         fr.Controls ["__EVENTTARGET"].Value = "";
577                         fr.Controls ["__EVENTARGUMENT"].Value = "";
578                         t.Request = fr;
579                         t.Run ();
580                         
581                         fr = new FormRequest (t.Response, "form1");
582                         fr.Controls.Add ("__EVENTTARGET");
583                         fr.Controls.Add ("__EVENTARGUMENT");
584                         fr.Controls ["__EVENTTARGET"].Value = "";
585                         fr.Controls ["__EVENTARGUMENT"].Value = "";
586                         t.Request = fr;
587                         t.Run ();
588                 }
589                 public static void ControlState2_Load (Page p) {
590                         ControlWithState parent = new ControlWithState ();
591                         p.Form.Controls.Add (parent);
592                         if (!p.IsPostBack) {
593                                 // emulate DataBind
594                                 parent.Controls.Clear ();
595                                 parent.ClearChildControlState ();
596                                 ControlWithState c1 = new ControlWithState ();
597                                 ControlWithState c2 = new ControlWithState ();
598                                 parent.Controls.Add (c1);
599                                 parent.Controls.Add (c2);
600                                 c1.State = "State1_1";
601                                 c2.State = "State1_2";
602                                 parent.State = "First";
603                         }
604                         else if (parent.State == "First") {
605                                 // emulate DataBind
606                                 parent.Controls.Clear ();
607                                 parent.ClearChildControlState ();
608                                 ControlWithState c1 = new ControlWithState ();
609                                 ControlWithState c2 = new ControlWithState ();
610                                 parent.Controls.Add (c1);
611                                 parent.Controls.Add (c2);
612                                 c1.State = "State2_1";
613                                 c2.State = "State2_2";
614                                 parent.State = "Second";
615                         }
616                         else {
617                                 // emulate CrerateChildControl only
618                                 parent.Controls.Clear ();
619                                 ControlWithState c1 = new ControlWithState ();
620                                 ControlWithState c2 = new ControlWithState ();
621                                 parent.Controls.Add (c1);
622                                 parent.Controls.Add (c2);
623
624                                 Assert.AreEqual ("State2_1", c1.State, "ControlState#1");
625                                 Assert.AreEqual ("State2_2", c2.State, "ControlState#2");
626                         }
627                 }
628
629                 [Test]
630                 public void ClientIDSeparator ()
631                 {
632                         DerivedControl ctrl = new DerivedControl ();
633                         Assert.AreEqual (95, (int) ctrl.ClientIDSeparator, "ClientIDSeparator");
634                 }
635
636                 [Test]
637                 public void IDSeparator ()
638                 {
639                         DerivedControl ctrl = new DerivedControl ();
640                         Assert.AreEqual (36, (int) ctrl.IdSeparator, "IDSeparator");
641                 }
642
643                 [Test]
644                 [Category ("NunitWeb")]
645                 public void IsChildControlStateCleared ()
646                 {
647                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (IsChildControlStateCleared_Load));
648                         t.Run ();
649                         FormRequest fr = new FormRequest (t.Response, "form1");
650                         fr.Controls.Add ("__EVENTTARGET");
651                         fr.Controls.Add ("__EVENTARGUMENT");
652                         fr.Controls["__EVENTTARGET"].Value = "";
653                         fr.Controls["__EVENTARGUMENT"].Value = "";
654                         t.Request = fr;
655                         t.Run ();
656                 }
657                 public static void IsChildControlStateCleared_Load (Page p)
658                 {
659                         ControlWithState c1 = new ControlWithState ();
660                         p.Form.Controls.Add (c1);
661                         if (p.IsPostBack) {
662                                 Assert.IsFalse (c1.IsChildControlStateCleared, "ControlState#1");
663                                 c1.ClearChildControlState ();
664                                 Assert.IsTrue (c1.IsChildControlStateCleared, "ControlState#1");
665                         }
666                         ControlWithState c2 = new ControlWithState ();
667                         c1.Controls.Add (c2);
668                         ControlWithState c3 = new ControlWithState ();
669                         c2.Controls.Add (c3);
670                         if (p.IsPostBack) {
671                                 Assert.IsFalse (c2.IsChildControlStateCleared, "ControlState#1");
672                                 Assert.IsFalse (c3.IsChildControlStateCleared, "ControlState#1");
673                         }
674                         if (!p.IsPostBack) {
675                                 c1.State = "State";
676                                 c2.State = "Cool";
677                                 c3.State = "SubCool";
678                         }
679                 }
680
681                 [Test]
682                 [Category ("NunitWeb")]
683                 public void LoadViewStateByID ()
684                 {
685                         ControlWithState c1 = new ControlWithState ();
686                         ControlWithState c2 = new ControlWithState ();
687                         c1.Controls.Add (c2);
688                         Assert.AreEqual (false, c1.LoadViewStateByID, "LoadViewStateByID#1");
689                 }
690
691                 [Test]
692                 [Category ("NunitWeb")]
693                 public void OpenFile ()
694                 {
695                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFile_Load));
696                         t.Run ();
697                 }
698                 public static void OpenFile_Load (Page p)
699                 {
700                         DerivedControl ctrl = new DerivedControl ();
701                         Stream strem = ctrl.OpenFile ("~/MyPage.aspx");
702                         Assert.IsNotNull (strem, "OpenFile failed");
703                 }
704
705                 [Test]
706                 [Category ("NunitWeb")]
707                 [ExpectedException (typeof (FileNotFoundException))]
708                 public void OpenFile_Exception ()
709                 {
710                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (OpenFileException_Load));
711                         t.Run ();
712                 }
713                 public static void OpenFileException_Load (Page p)
714                 {
715                         DerivedControl ctrl = new DerivedControl ();
716                         Stream strem = ctrl.OpenFile ("~/Fake.tmp");
717                 }
718
719                 [Test]
720                 [Category ("NunitWeb")]
721                 public void ResolveClientUrl ()
722                 {
723                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveClientUrl_Load));
724                         string html = t.Run ();
725                 }
726                 public static void ResolveClientUrl_Load (Page p)
727                 {
728                         Control ctrl = new Control ();
729                         p.Controls.Add (ctrl);
730                         string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
731                         Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
732
733                         Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
734                         
735                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
736                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
737
738                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
739                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
740                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
741                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
742                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
743                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
744                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
745                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
746                         Assert.AreEqual ("NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
747                         Assert.AreEqual ("NunitWeb/../MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
748                         Assert.AreEqual ("NunitWeb/./MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
749                         Assert.AreEqual ("http://google.com/", ctrl.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
750
751                         Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
752                         Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
753
754                         Assert.AreEqual ("./MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
755                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
756                 
757                 }
758                 
759                 [Test]
760                 [Category ("NunitWeb")]
761                 public void ResolveClientUrl2 ()
762                 {
763                         WebTest t = new WebTest ("ResolveUrl.aspx");
764                         PageDelegates delegates = new PageDelegates ();
765                         delegates.Load = ResolveClientUrl2_Load;
766                         t.Invoker = new PageInvoker (delegates);
767                         string html = t.Run ();
768                 }
769                 
770                 public static void ResolveClientUrl2_Load (Page p)
771                 {
772                         Control uc = p.FindControl ("WebUserControl1");
773                         Control ctrl = uc.FindControl ("Label");
774                         
775                         string url = ctrl.ResolveClientUrl ("~/MyPage.aspx");
776                         Assert.AreEqual ("MyPage.aspx", url, "ResolveClientUrl Failed");
777
778                         Assert.AreEqual ("", ctrl.ResolveClientUrl (""), "empty string");
779
780                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~"), "~");
781                         Assert.AreEqual ("./", ctrl.ResolveClientUrl ("~/"), "~/");
782
783                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
784                         Assert.AreEqual ("../MyPage.aspx", ctrl.ResolveClientUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
785                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
786                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveClientUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
787                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveClientUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
788                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
789                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
790                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveClientUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
791                         Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
792                         Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
793                         Assert.AreEqual ("Folder/NunitWeb/MyPage.aspx", ctrl.ResolveClientUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
794                         Assert.AreEqual ("http://google.com/", ctrl.ResolveClientUrl ("http://google.com/"), "ResolveClientUrl Failed");
795
796                         Assert.AreEqual ("MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
797                         Assert.AreEqual ("../MyPage.aspx?param=val&yes=no", ctrl.ResolveClientUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
798
799                         Assert.AreEqual ("Folder/MyPage.aspx", ctrl.ResolveClientUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
800                         Assert.AreEqual ("MyPage.aspx", ctrl.ResolveClientUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
801
802                 }
803
804                 [Test]
805                 [Category ("NunitWeb")]
806                 public void ResolveUrl ()
807                 {
808                         WebTest t = new WebTest (PageInvoker.CreateOnLoad (ResolveUrl_Load));
809                         string html = t.Run ();
810                 }
811
812                 public static void ResolveUrl_Load (Page p)
813                 {
814 #if TARGET_JVM
815                         string appPath = "/MainsoftWebApp20";
816 #else
817                         string appPath = "/NunitWeb";
818 #endif
819                         Control ctrl = new Control ();
820                         p.Controls.Add (ctrl);
821                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
822
823                         Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
824
825                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
826                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
827
828                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
829                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
830                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
831                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
832                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
833                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
834                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
835                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
836                         Assert.AreEqual (appPath + "/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
837                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
838                         Assert.AreEqual (appPath + "/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
839                         Assert.AreEqual ("http://google.com/", ctrl.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
840
841                         Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
842                         Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
843
844                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
845                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
846
847                         Assert.AreEqual ("/", ctrl.ResolveUrl (".."), "..");
848                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../"), "../");
849                 }
850
851                 [Test]
852                 [Category ("NunitWeb")]
853                 public void ResolveUrl2 ()
854                 {
855                         WebTest t = new WebTest ("ResolveUrl.aspx");
856                         PageDelegates delegates = new PageDelegates ();
857                         delegates.Load = ResolveUrl2_Load;
858                         t.Invoker = new PageInvoker (delegates);
859                         string html = t.Run ();
860                 }
861
862                 public static void ResolveUrl2_Load (Page p)
863                 {
864 #if TARGET_JVM
865                         string appPath = "/MainsoftWebApp20";
866 #else
867                         string appPath = "/NunitWeb";
868 #endif
869                         Control uc = p.FindControl ("WebUserControl1");
870                         Control ctrl = uc.FindControl ("Label");
871
872                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~/MyPage.aspx"), "ResolveClientUrl Failed");
873
874                         Assert.AreEqual ("", ctrl.ResolveUrl (""), "empty string");
875
876                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~"), "~");
877                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("~/"), "~/");
878
879                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~/../MyPage.aspx"), "~/../MyPage.aspx");
880                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("~\\..\\MyPage.aspx"), "~\\..\\MyPage.aspx");
881                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("~////MyPage.aspx"), "ResolveClientUrl Failed");
882                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("/MyPage.aspx"), "ResolveClientUrl Failed");
883                         Assert.AreEqual ("/folder/MyPage.aspx", ctrl.ResolveUrl ("/folder/MyPage.aspx"), "ResolveClientUrl Failed");
884                         Assert.AreEqual ("/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("/NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
885                         Assert.AreEqual ("\\NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("\\NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
886                         Assert.AreEqual ("///NunitWeb\\..\\MyPage.aspx", ctrl.ResolveUrl ("///NunitWeb\\..\\MyPage.aspx"), "ResolveClientUrl Failed");
887                         Assert.AreEqual (appPath + "/Folder/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/MyPage.aspx"), "ResolveClientUrl Failed");
888                         Assert.AreEqual (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/../MyPage.aspx"), "ResolveClientUrl Failed");
889                         Assert.AreEqual (appPath + "/Folder/NunitWeb/MyPage.aspx", ctrl.ResolveUrl ("NunitWeb/./MyPage.aspx"), "ResolveClientUrl Failed");
890                         Assert.AreEqual ("http://google.com/", ctrl.ResolveUrl ("http://google.com/"), "ResolveClientUrl Failed");
891
892                         Assert.AreEqual (appPath + "/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
893                         Assert.AreEqual ("/MyPage.aspx?param=val&yes=no", ctrl.ResolveUrl ("~/../MyPage.aspx?param=val&yes=no"), "~/../MyPage.aspx");
894
895                         Assert.AreEqual (appPath + "/Folder/MyPage.aspx", ctrl.ResolveUrl ("./MyPage.aspx"), "ResolveClientUrl Failed");
896                         Assert.AreEqual (appPath + "/MyPage.aspx", ctrl.ResolveUrl ("../MyPage.aspx"), "ResolveClientUrl Failed");
897
898                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl (".."), "..");
899                         Assert.AreEqual (appPath + "/", ctrl.ResolveUrl ("../"), "../");
900                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../.."), "../..");
901                         Assert.AreEqual ("/", ctrl.ResolveUrl ("../../"), "../../");
902                         Assert.AreEqual ("/MyPage.aspx", ctrl.ResolveUrl ("../../MyPage.aspx"), "../../MyPage.aspx");
903                 }
904
905                 [Test]
906                 [Category ("NotWorking")] // Not implemented exception
907                 public void ResolveAdapter_2 ()
908                 {
909                         DerivedControl ctrl = new DerivedControl ();
910                         Assert.AreEqual (null, ctrl.ResolveAdapter (), "ResolveAdapter");
911                 }
912
913                 [Test]
914                 public void EnableTheming ()
915                 {
916                         DerivedControl ctrl = new DerivedControl ();
917                         Assert.AreEqual (true, ctrl.EnableTheming, "EnableTheming#1");
918                         ctrl.EnableTheming = false;
919                         Assert.AreEqual (false, ctrl.EnableTheming, "EnableTheming#2");
920                 }
921
922 #endif
923                 [Test]
924                 public void BindingContainer ()
925                 {
926                         ControlWithTemplate c = new ControlWithTemplate ();
927                         c.Template = new CompiledTemplateBuilder (new BuildTemplateMethod (BindingContainer_BuildTemplate));
928
929                         // cause CreateChildControls called
930                         c.FindControl ("stam");
931                 }
932
933                 static void BindingContainer_BuildTemplate (Control control)
934                 {
935                         Control child1 = new Control ();
936                         control.Controls.Add (child1);
937
938                         Assert.IsTrue (Object.ReferenceEquals (child1.NamingContainer, control), "NamingContainer #1");
939                         Assert.IsTrue (Object.ReferenceEquals (child1.BindingContainer, control), "BindingContainer #1");
940
941                         NamingContainer nc = new NamingContainer ();
942                         Control child2 = new Control ();
943                         nc.Controls.Add (child2);
944                         control.Controls.Add (nc);
945
946                         Assert.IsTrue (Object.ReferenceEquals (child2.NamingContainer, nc), "NamingContainer #2");
947                         Assert.IsTrue (Object.ReferenceEquals (child2.BindingContainer, nc), "BindingContainer #2");
948
949 #if NET_2_0
950                         // DetailsViewPagerRow marked to be not BindingContainer 
951                         DetailsViewPagerRow row = new DetailsViewPagerRow (0, DataControlRowType.Pager, DataControlRowState.Normal);
952                         TableCell cell = new TableCell ();
953                         Control child3 = new Control ();
954                         cell.Controls.Add (child3);
955                         row.Cells.Add (cell);
956                         control.Controls.Add (row);
957
958                         Assert.IsTrue (Object.ReferenceEquals (child3.NamingContainer, row), "NamingContainer #3");
959                         Assert.IsTrue (Object.ReferenceEquals (child3.BindingContainer, control), "BindingContainer #3");
960 #endif
961                 }
962 #if NET_2_0
963                 [Test]
964                 public void Control_Adapter ()
965                 {
966                         MyNC ctr = new MyNC ();
967                         Assert.AreEqual (null, ctr.Adapter (), "Adapter");
968                 }
969 #endif
970                 [Test]
971                 public void ChildControlsCreated () {
972                         ChildControlsCreatedControl ctr = new ChildControlsCreatedControl ();
973                         ctr.Controls.Add (new Control ());
974                         //ctr.DoEnsureChildControls ();
975
976                         Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#1");
977                         ctr.SetChildControlsCreated (false);
978                         Assert.AreEqual (1, ctr.Controls.Count, "ChildControlsCreated#2");
979                 }
980
981 #if NET_2_0
982                 [Test (Description="Bug #594238")]
983                 public void OverridenControlsPropertyAndPostBack_Bug594238 ()
984                 {
985                         WebTest t = new WebTest ("OverridenControlsPropertyAndPostBack_Bug594238.aspx");
986                         t.Run ();
987
988                         FormRequest fr = new FormRequest (t.Response, "form1");
989                         fr.Controls.Add ("__EVENTTARGET");
990                         fr.Controls.Add ("__EVENTARGUMENT");
991                         fr.Controls ["__EVENTTARGET"].Value = "container$children$lb";
992                         fr.Controls ["__EVENTARGUMENT"].Value = String.Empty;
993                         t.Request = fr;
994
995                         string originalHtml = @"<span id=""container""><a href=""javascript:__doPostBack('container$children$lb','')"" id=""container_children_lb"">Woot! I got clicked!</a></span><hr/>";
996                         string pageHtml = t.Run ();
997                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
998
999                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
1000                 }
1001                 
1002                 [TestFixtureTearDown]
1003                 public void Tear_down ()
1004                 {
1005                         WebTest.Unload ();
1006                 }
1007                 
1008                 [TestFixtureSetUp]
1009                 public void TestFixtureSetUp ()
1010                 {
1011                         WebTest.CopyResource (GetType (), "ResolveUrl.aspx", "ResolveUrl.aspx");
1012                         WebTest.CopyResource (GetType (), "ResolveUrl.ascx", "Folder/ResolveUrl.ascx");
1013                         WebTest.CopyResource (GetType (), "OverridenControlsPropertyAndPostBack_Bug594238.aspx", "OverridenControlsPropertyAndPostBack_Bug594238.aspx");
1014                 }
1015
1016 #endif
1017
1018                 #region helpcalsses
1019 #if NET_2_0
1020                 class ControlWithState : Control
1021                 {
1022                         string _state;
1023
1024                         public string State
1025                         {
1026                                 get { return _state; }
1027                                 set { _state = value; }
1028                         }
1029
1030                         public string Viewstate {
1031                                 get { return (string) ViewState ["Viewstate"]; }
1032                                 set { ViewState ["Viewstate"] = value; }
1033                         }
1034
1035                         protected override void OnInit (EventArgs e)
1036                         {
1037                                 base.OnInit (e);
1038                                 Page.RegisterRequiresControlState (this);
1039                         }
1040
1041                         protected override object SaveControlState ()
1042                         {
1043                                 return State;
1044                         }
1045
1046                         protected override void LoadControlState (object savedState)
1047                         {
1048                                 State = (string) savedState;
1049                         }
1050
1051                         public new void ClearChildState ()
1052                         {
1053                                 base.ClearChildState ();
1054                         }
1055
1056                         public new void ClearChildControlState ()
1057                         {
1058                                 base.ClearChildControlState ();
1059                         }
1060
1061                         public new bool IsChildControlStateCleared
1062                         {
1063                                 get { return base.IsChildControlStateCleared; }
1064                         }
1065
1066                         public new bool LoadViewStateByID
1067                         {
1068                                 get { return base.LoadViewStateByID; }
1069                         }
1070                 }
1071
1072 #endif
1073                 class MyNC : Control, INamingContainer
1074                 {
1075                         #if NET_2_0
1076                         public ControlAdapter Adapter ()
1077                         {
1078                                 return base.Adapter;
1079                         }
1080
1081                         public new void DataBind (bool opt)
1082                         {
1083                                 base.DataBind (opt);
1084                         }
1085
1086                         public new void DataBindChildren ()
1087                         {
1088                                 base.DataBindChildren ();
1089                         }
1090
1091                         public new void EnsureID ()
1092                         {
1093                                 base.EnsureID ();
1094                         }
1095
1096                         public new bool HasEvents ()
1097                         {
1098                                 return base.HasEvents ();
1099                         }
1100                         #endif
1101                 }
1102
1103                 class DerivedControl : Control
1104                 {
1105                         ControlCollection coll;
1106
1107                         public DerivedControl ()
1108                         {
1109                                 coll = new ControlCollection (this);
1110                         }
1111
1112                         public override ControlCollection Controls
1113                         {
1114                                 get { return coll; }
1115                         }
1116
1117 #if NET_2_0
1118                         public bool DoIsViewStateEnabled
1119                         {
1120                                 get { return IsViewStateEnabled; }
1121                         }
1122
1123                         public new char ClientIDSeparator
1124                         {
1125                                 get { return base.ClientIDSeparator; }
1126                         }
1127
1128                         public new char IdSeparator
1129                         {
1130                                 get { return base.IdSeparator; }
1131                         }
1132
1133                         public new Stream OpenFile (string path)
1134                         {
1135                                 return base.OpenFile (path);
1136                         }
1137
1138                         public new ControlAdapter ResolveAdapter ()
1139                         {
1140                                 return base.ResolveAdapter ();
1141                         }
1142 #endif
1143                 }
1144
1145                 class NamingContainer : Control, INamingContainer
1146                 {
1147                 }
1148
1149                 class ControlWithTemplate : Control
1150                 {
1151                         ITemplate _template;
1152
1153                         [TemplateContainer (typeof (TemplateContainer))]
1154                         public ITemplate Template
1155                         {
1156                                 get { return _template; }
1157                                 set { _template = value; }
1158                         }
1159
1160                         protected override void CreateChildControls ()
1161                         {
1162                                 Controls.Clear ();
1163
1164                                 TemplateContainer container = new TemplateContainer ();
1165                                 Controls.Add (container);
1166
1167                                 if (Template != null)
1168                                         Template.InstantiateIn (container);
1169                         }
1170                 }
1171
1172                 class TemplateContainer : Control, INamingContainer
1173                 {
1174                 }
1175                 #endregion
1176         }
1177
1178 #if NET_2_0
1179         public class Customadaptercontrol : Control
1180         {
1181                 public new ControlAdapter Adapter {
1182                         get { return base.Adapter; }
1183                 }
1184
1185                 public new ControlAdapter ResolveAdapter ()
1186                 {
1187                         return base.ResolveAdapter ();
1188                 }
1189         }
1190
1191         public class Customadapter : ControlAdapter
1192         {
1193         }
1194
1195         class EnsureIDControl : Control {
1196                 public void DoEnsureID () {
1197                         EnsureID ();
1198                 }
1199         }
1200 #endif
1201
1202         public class ChildControlsCreatedControl : Control
1203         {
1204                 protected override void CreateChildControls () {
1205                         Controls.Add (new Control ());
1206                 }
1207
1208                 public void DoEnsureChildControls () {
1209                         EnsureChildControls ();
1210                 }
1211
1212                 public void SetChildControlsCreated (bool value) {
1213                         ChildControlsCreated = value;
1214                 }
1215         }
1216 }