TemplateControlCompilerTest.cs 11 KB

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