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