2010-01-20 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / System.Web / Test / System.Web.Compilation / TemplateControlCompilerTest.cs
1 using System;
2 using System.Collections.Generic;
3 using MonoTests.SystemWeb.Framework;
4 using MonoTests.stand_alone.WebHarness;
5 using NUnit.Framework;
6 using System.Web;
7 using System.Web.Compilation;
8 using System.Web.UI.WebControls;
9 using System.Reflection;
10 using System.ComponentModel;
11 using System.Threading;
12
13 namespace MonoTests.System.Web.Compilation {
14         public class ReadOnlyPropertyControl:TextBox {
15                 [Bindable (true)]
16                 public bool MyProp
17                 {
18                         get { return true; }
19                 }
20
21         }
22
23 #if NET_2_0
24         public class BindTestDataItem
25         {
26                 int data;
27                 public int Data {
28                         get { return data; }
29                         set { data = value; }
30                 }
31
32                 public BindTestDataItem (int data)
33                 {
34                         this.data = data;
35                 }
36         }
37         
38         public class BindTestDataSource 
39         {
40                 public IList <BindTestDataItem> GetData ()
41                 {
42                         return new List <BindTestDataItem> {new BindTestDataItem (0), new BindTestDataItem (1)};
43                 }
44         }
45 #endif
46         
47         [TestFixture]
48         public class TemplateControlCompilerTest
49         {
50                 [TestFixtureSetUp]
51                 public void TemplateControlCompiler_Init ()
52                 {
53                         WebTest.CopyResource (GetType (), "ReadOnlyPropertyBind.aspx", "ReadOnlyPropertyBind.aspx");
54                         WebTest.CopyResource (GetType (), "ReadOnlyPropertyControl.ascx", "ReadOnlyPropertyControl.ascx");
55                         WebTest.CopyResource (GetType (), "TemplateControlParsingTest.aspx", "TemplateControlParsingTest.aspx");
56                         WebTest.CopyResource (GetType (), "ServerSideControlsInScriptBlock.aspx", "ServerSideControlsInScriptBlock.aspx");
57                         WebTest.CopyResource (GetType (), "ServerControlInClientSideComment.aspx", "ServerControlInClientSideComment.aspx");
58                         WebTest.CopyResource (GetType (), "UnquotedAngleBrackets.aspx", "UnquotedAngleBrackets.aspx");
59                         WebTest.CopyResource (GetType (), "FullTagsInText.aspx", "FullTagsInText.aspx");
60                         WebTest.CopyResource (GetType (), "TagsExpressionsAndCommentsInText.aspx", "TagsExpressionsAndCommentsInText.aspx");
61                         WebTest.CopyResource (GetType (), "NewlineInCodeExpression.aspx", "NewlineInCodeExpression.aspx");
62                         WebTest.CopyResource (GetType (), "DuplicateControlsInClientComment.aspx", "DuplicateControlsInClientComment.aspx");
63                         WebTest.CopyResource (GetType (), "TagsNestedInClientTag.aspx", "TagsNestedInClientTag.aspx");
64                         WebTest.CopyResource (GetType (), "ConditionalClientComments.aspx", "ConditionalClientComments.aspx");
65 #if NET_2_0
66                         WebTest.CopyResource (GetType (), "InvalidPropertyBind1.aspx", "InvalidPropertyBind1.aspx");
67                         WebTest.CopyResource (GetType (), "InvalidPropertyBind2.aspx", "InvalidPropertyBind2.aspx");
68                         WebTest.CopyResource (GetType (), "InvalidPropertyBind3.aspx", "InvalidPropertyBind3.aspx");
69                         WebTest.CopyResource (GetType (), "InvalidPropertyBind4.aspx", "InvalidPropertyBind4.aspx");
70                         WebTest.CopyResource (GetType (), "ValidPropertyBind1.aspx", "ValidPropertyBind1.aspx");
71                         WebTest.CopyResource (GetType (), "ValidPropertyBind2.aspx", "ValidPropertyBind2.aspx");
72                         WebTest.CopyResource (GetType (), "ValidPropertyBind3.aspx", "ValidPropertyBind3.aspx");
73                         WebTest.CopyResource (GetType (), "ValidPropertyBind4.aspx", "ValidPropertyBind4.aspx");
74                         WebTest.CopyResource (GetType (), "ValidPropertyBind5.aspx", "ValidPropertyBind5.aspx");
75                         WebTest.CopyResource (GetType (), "NoBindForMethodsWithBindInName.aspx", "NoBindForMethodsWithBindInName.aspx");
76                         WebTest.CopyResource (GetType (), "ReadWritePropertyControl.ascx", "ReadWritePropertyControl.ascx");
77                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.aspx", "ContentPlaceHolderInTemplate.aspx");
78                         WebTest.CopyResource (GetType (), "ContentPlaceHolderInTemplate.master", "ContentPlaceHolderInTemplate.master");
79                         WebTest.CopyResource (GetType (), "LinkInHeadWithEmbeddedExpression.aspx", "LinkInHeadWithEmbeddedExpression.aspx");
80                         WebTest.CopyResource (GetType (), "ExpressionInListControl.aspx", "ExpressionInListControl.aspx");
81                         WebTest.CopyResource (GetType (), "PreprocessorDirectivesInMarkup.aspx", "PreprocessorDirectivesInMarkup.aspx");
82                         WebTest.CopyResource (GetType (), "OneLetterIdentifierInCodeRender.aspx", "OneLetterIdentifierInCodeRender.aspx");
83                         WebTest.CopyResource (GetType (), "NestedParserFileText.aspx", "NestedParserFileText.aspx");
84                         WebTest.CopyResource (GetType (), "TagWithExpressionWithinAttribute.aspx", "TagWithExpressionWithinAttribute.aspx");
85 #endif
86                 }
87                 
88                 [Test]
89                 [NUnit.Framework.Category ("NunitWeb")]
90 #if !TARGET_JVM
91                 [NUnit.Framework.Category ("NotWorking")]
92 #endif
93                 public void ReadOnlyPropertyBindTest ()
94                 {
95                         new WebTest ("ReadOnlyPropertyBind.aspx").Run ();
96                 }
97
98 #if NET_2_0
99                 // Test for bug #449970
100                 [Test]
101                 public void MasterPageContentPlaceHolderInTemplate ()
102                 {
103                         new WebTest ("ContentPlaceHolderInTemplate.aspx").Run ();
104                 }
105                 
106                 [Test]
107                 [ExpectedException ("System.Web.Compilation.CompilationException")]
108                 public void InvalidPropertyBindTest1 ()
109                 {
110                         new WebTest ("InvalidPropertyBind1.aspx").Run ();
111                 }
112
113                 [Test]
114                 [ExpectedException (typeof (HttpParseException))]
115                 public void InvalidPropertyBindTest2 ()
116                 {
117                         new WebTest ("InvalidPropertyBind2.aspx").Run ();
118                 }
119
120                 [Test]
121                 [ExpectedException ("System.Web.Compilation.CompilationException")]
122                 public void InvalidPropertyBindTest3 ()
123                 {
124                         new WebTest ("InvalidPropertyBind3.aspx").Run ();
125                 }
126
127                 [Test]
128                 [ExpectedException (typeof (HttpParseException))]
129                 public void InvalidPropertyBindTest4 ()
130                 {
131                         new WebTest ("InvalidPropertyBind4.aspx").Run ();
132                 }
133
134                 [Test]
135                 public void ValidPropertyBindTest1 ()
136                 {
137                         new WebTest ("ValidPropertyBind1.aspx").Run ();
138                 }
139
140                 [Test]
141                 public void ValidPropertyBindTest2 ()
142                 {
143                         new WebTest ("ValidPropertyBind2.aspx").Run ();
144                 }
145
146                 [Test]
147                 public void ValidPropertyBindTest3 ()
148                 {
149                         new WebTest ("ValidPropertyBind3.aspx").Run ();
150                 }
151
152                 [Test]
153                 public void ValidPropertyBindTest4 ()
154                 {
155                         new WebTest ("ValidPropertyBind4.aspx").Run ();
156                 }
157
158                 [Test]
159                 public void ValidPropertyBindTest5 ()
160                 {
161                         new WebTest ("ValidPropertyBind5.aspx").Run ();
162                 }
163
164                 // bug #493639
165                 [Test]
166                 public void NoBindForMethodsWithBindInNameTest ()
167                 {
168                         string pageHtml = new WebTest ("NoBindForMethodsWithBindInName.aspx").Run ();
169                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
170                         string originalHtml = "<span id=\"grid_ctl02_lblTest\">Test</span>";
171                         
172                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
173                 }
174
175                 // bug #498637
176                 [Test]
177                 public void LinkInHeadWithEmbeddedExpression ()
178                 {
179                         string pageHtml = new WebTest ("LinkInHeadWithEmbeddedExpression.aspx").Run ();
180                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
181                         string originalHtml = "<link href=\"Themes/Default/Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />";
182
183                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
184                 }
185
186                 [Test]
187                 public void ExpressionInListControl ()
188                 {
189                         string pageHtml = new WebTest ("ExpressionInListControl.aspx").Run ();
190                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
191                         string originalHtml = @"<select name=""DropDown1"" id=""DropDown1"">
192         <option value=""strvalue"">str</option>
193
194 </select>";
195                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
196                 }
197
198                 [Test (Description="Bug #508888")]
199                 public void ServerSideControlsInScriptBlock ()
200                 {
201                         string pageHtml = new WebTest ("ServerSideControlsInScriptBlock.aspx").Run ();
202                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
203                         string originalHtml = @"<script type=""text/javascript"">alert (escape(""reporting/location?report=ViewsByDate&minDate=minDate&maxDate=maxDate""));</script>";
204                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
205                 }
206
207                 [Test (Description="Bug #520024")]
208                 public void PreprocessorDirectivesInMarkup ()
209                 {
210                         // Just test if it doesn't throw an exception
211                         new WebTest ("PreprocessorDirectivesInMarkup.aspx").Run ();
212                 }
213
214                 [Test (Description="Bug #526449")]
215                 public void NewlineInCodeExpression ()
216                 {
217                         string pageHtml = new WebTest ("NewlineInCodeExpression.aspx").Run ();
218                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
219                         string originalHtml = "<a href=\"test\">bla</a>";
220                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
221                 }
222
223                 [Test (Description="Bug #524358")]
224                 [ExpectedException ("System.Web.Compilation.ParseException")]
225                 public void DuplicateControlsInClientComment ()
226                 {
227                         // Just test if it throws an exception
228                         new WebTest ("DuplicateControlsInClientComment.aspx").Run ();
229                 }
230
231                 [Test (Description="Bug #367723")]
232                 public void ConditionalClientComments ()
233                 {
234                         string pageHtml = new WebTest ("ConditionalClientComments.aspx").Run ();
235                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
236                         string originalHtml = @"<!--[if IE 6]>
237                 <link rel=""styleheet"" type=""text/css"" href=""compat-ie6.css"" />
238         <![endif]-->";
239                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
240                 }
241                 
242                 [Test (Description="Bug #400807")]
243                 public void OneLetterIdentifierInCodeRender ()
244                 {
245                         string pageHtml = new WebTest ("OneLetterIdentifierInCodeRender.aspx").Run ();
246                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
247                         string originalHtml = @"bDoR called";
248
249                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
250                 }
251
252                 [Test (Description="Bug #562286")]
253                 public void NestedParserFileText ()
254                 {
255                         // Just test if it doesn't throw an exception
256                         new WebTest ("NestedParserFileText.aspx").Run ();
257                 }
258
259                 [Test (Description="Bug #568631")]
260                 public void TagWithExpressionWithinAttribute ()
261                 {
262                         // Just test if it doesn't throw an exception
263                         new WebTest ("TagWithExpressionWithinAttribute.aspx").Run ();
264                 }
265 #endif          
266                 [Test (Description="Bug #323719")]
267                 public void TagsNestedInClientTag ()
268                 {
269                         string pageHtml = new WebTest ("TagsNestedInClientTag.aspx").Run ();
270                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
271                         string originalHtml = @"<script language=""javascript"" src=""/js/test.js"" type=""text/javascript""></script>
272 <sometag language=""javascript"" src=""/js/test.js"" type=""text/javascript""></sometag>";
273
274                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
275                 }
276                 
277                 [Test (Description="Bug #517656")]
278                 public void ServerControlInClientSideComment ()
279                 {
280                         string pageHtml = new WebTest ("ServerControlInClientSideComment.aspx").Run ();
281                         string renderedHtml = HtmlDiff.GetControlFromPageHtml (pageHtml);
282                         string originalHtml = @"<!-- comment start
283   <input id=""testBox"" type=""checkbox"" name=""testBox"" />
284 comment end -->";
285                         HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "#A1");
286                 }
287
288                 [Test]
289                 public void UnquotedAngleBrackets ()
290                 {
291                         // We just test if it doesn't throw an exception
292                         new WebTest ("UnquotedAngleBrackets.aspx").Run ();
293                 }
294
295                 [Test]
296                 public void FullTagsInText ()
297                 {
298                         // We just test if it doesn't throw an exception
299                         new WebTest ("FullTagsInText.aspx").Run ();
300                 }
301
302                 [Test]
303                 public void TagsExpressionsAndCommentsInText ()
304                 {
305                         // We just test if it doesn't throw an exception
306                         new WebTest ("TagsExpressionsAndCommentsInText.aspx").Run ();
307                 }
308                 
309                 [Test]
310                 public void ChildTemplatesTest ()
311                 {
312                         try {
313                                 WebTest.Host.AppDomain.AssemblyResolve += new ResolveEventHandler (ResolveAssemblyHandler);
314                                 new WebTest ("TemplateControlParsingTest.aspx").Run ();
315                         } finally {
316                                 WebTest.Host.AppDomain.AssemblyResolve -= new ResolveEventHandler (ResolveAssemblyHandler);
317                         }
318                 }
319                 
320                 [TestFixtureTearDown]
321                 public void TearDown ()
322                 {
323                         Thread.Sleep (100);
324                         WebTest.Unload ();
325                 }
326
327                 public static Assembly ResolveAssemblyHandler (object sender, ResolveEventArgs e)
328                 {
329                         if (e.Name != "System.Web_test")
330                                 return null;
331
332                         return Assembly.GetExecutingAssembly ();
333                 }
334         }
335 }
336