ImageMapTest.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. //
  2. // Tests for System.Web.UI.WebControls.ImageMap.cs
  3. //
  4. // Author:
  5. // Hagit Yidov ([email protected]
  6. //
  7. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using NUnit.Framework;
  30. using System;
  31. using System.IO;
  32. using System.Globalization;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using MonoTests.stand_alone.WebHarness;
  37. using MonoTests.SystemWeb.Framework;
  38. using System.Threading;
  39. namespace MonoTests.System.Web.UI.WebControls
  40. {
  41. class PokerImageMap : ImageMap
  42. {
  43. // View state Stuff
  44. public PokerImageMap ()
  45. {
  46. TrackViewState ();
  47. }
  48. public object SaveState ()
  49. {
  50. return SaveViewState ();
  51. }
  52. public void LoadState (object o)
  53. {
  54. LoadViewState (o);
  55. }
  56. public StateBag StateBag
  57. {
  58. get { return base.ViewState; }
  59. }
  60. public void DoOnClick (ImageMapEventArgs e)
  61. {
  62. base.OnClick (e);
  63. }
  64. public void DoOnBubbleEven (Object source, ImageMapEventArgs e)
  65. {
  66. base.OnBubbleEvent (source, e);
  67. }
  68. // Render Method
  69. public string Render ()
  70. {
  71. StringWriter sw = new StringWriter ();
  72. HtmlTextWriter tw = new HtmlTextWriter (sw);
  73. Render (tw);
  74. return sw.ToString ();
  75. }
  76. }
  77. [TestFixture]
  78. public class ImageMapTest
  79. {
  80. [TestFixtureSetUp]
  81. public void SetUp ()
  82. {
  83. WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
  84. }
  85. [Test]
  86. public void ImageMap_DefaultProperties ()
  87. {
  88. PokerImageMap imageMap = new PokerImageMap ();
  89. Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count");
  90. Assert.AreEqual (true, imageMap.Enabled, "Enabled");
  91. Assert.AreEqual (HotSpotMode.NotSet, imageMap.HotSpotMode, "HotSpotMode");
  92. Assert.AreEqual (0, imageMap.HotSpots.Count, "HotSpots.Count");
  93. Assert.AreEqual (string.Empty, imageMap.Target, "Target");
  94. }
  95. [Test]
  96. public void ImageMap_AssignToDefaultProperties ()
  97. {
  98. PokerImageMap imageMap = new PokerImageMap ();
  99. Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count");
  100. imageMap.Enabled = true;
  101. Assert.AreEqual (true, imageMap.Enabled, "Enabled");
  102. Assert.AreEqual (0, imageMap.StateBag.Count, "ViewState.Count-1");
  103. imageMap.HotSpotMode = HotSpotMode.Navigate;
  104. Assert.AreEqual (HotSpotMode.Navigate, imageMap.HotSpotMode, "HotSpotMode");
  105. Assert.AreEqual (1, imageMap.StateBag.Count, "ViewState.Count-2");
  106. imageMap.HotSpots.Add (new CircleHotSpot ());
  107. Assert.AreEqual (1, imageMap.HotSpots.Count, "HotSpots.Count");
  108. Assert.AreEqual (1, imageMap.StateBag.Count, "ViewState.Count-3");
  109. imageMap.Target = "Target";
  110. Assert.AreEqual ("Target", imageMap.Target, "Target");
  111. Assert.AreEqual (2, imageMap.StateBag.Count, "ViewState.Count-4");
  112. }
  113. [Test]
  114. public void ImageMap_Defaults_Render ()
  115. {
  116. PokerImageMap imageMap = new PokerImageMap ();
  117. #if NET_4_0
  118. string originalHtml = "<img src=\"\" />";
  119. #else
  120. string originalHtml = "<img src=\"\" style=\"border-width:0px;\" />";
  121. #endif
  122. string renderedHtml = imageMap.Render ();
  123. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderDefault");
  124. }
  125. [Test]
  126. public void ImageMap_AssignedValues_RenderNavigate ()
  127. {
  128. // HotSpotMode = Navigate using NavigateURL
  129. //-----------------------------------------
  130. PokerImageMap imageMap = new PokerImageMap ();
  131. imageMap.Enabled = true;
  132. imageMap.HotSpotMode = HotSpotMode.Navigate;
  133. imageMap.Target = "Target";
  134. CircleHotSpot circle = new CircleHotSpot ();
  135. circle.NavigateUrl = "NavigateURL";
  136. imageMap.HotSpots.Add (circle);
  137. #if NET_4_0
  138. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
  139. #else
  140. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
  141. #endif
  142. string renderedHtml = imageMap.Render ();
  143. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateTextAssigned");
  144. }
  145. [Test]
  146. public void ImageMap_AssignedValues_RenderNavigateCircle ()
  147. {
  148. // Circle.HotSpotMode = Navigate
  149. //------------------------------
  150. PokerImageMap imageMap = new PokerImageMap ();
  151. imageMap.Enabled = true;
  152. CircleHotSpot circle = new CircleHotSpot ();
  153. circle.AccessKey = "A";
  154. circle.AlternateText = "Circle";
  155. circle.HotSpotMode = HotSpotMode.Navigate;
  156. circle.NavigateUrl = "NavigateURL";
  157. circle.TabIndex = 1;
  158. circle.Radius = 10;
  159. circle.X = 30;
  160. circle.Y = 40;
  161. imageMap.HotSpots.Add (circle);
  162. #if NET_4_0
  163. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"30,40,10\" href=\"NavigateURL\" title=\"Circle\" alt=\"Circle\" accesskey=\"A\" tabindex=\"1\" />\r\n</map>";
  164. #else
  165. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"30,40,10\" href=\"NavigateURL\" title=\"Circle\" alt=\"Circle\" accesskey=\"A\" tabindex=\"1\" />\r\n</map>";
  166. #endif
  167. string renderedHtml = imageMap.Render ();
  168. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateCircleTextAssigned");
  169. }
  170. [Test]
  171. public void ImageMap_AssignedValues_RenderNavigateShapes ()
  172. {
  173. // Rectangle/Polygon.HotSpotMode = Navigate
  174. //-----------------------------------------
  175. PokerImageMap imageMap = new PokerImageMap ();
  176. imageMap.Enabled = true;
  177. imageMap.HotSpotMode = HotSpotMode.NotSet;
  178. RectangleHotSpot rect = new RectangleHotSpot ();
  179. rect.AccessKey = "R";
  180. rect.AlternateText = "Rectangle";
  181. rect.HotSpotMode = HotSpotMode.Navigate;
  182. rect.NavigateUrl = "NavigateUrlRect";
  183. rect.TabIndex = 1;
  184. rect.Bottom = 10;
  185. rect.Top = 20;
  186. rect.Left = 30;
  187. rect.Right = 40;
  188. imageMap.HotSpots.Add (rect);
  189. imageMap.HotSpotMode = HotSpotMode.Navigate;
  190. PolygonHotSpot poly = new PolygonHotSpot ();
  191. poly.AccessKey = "P";
  192. poly.AlternateText = "Polygon";
  193. poly.NavigateUrl = "NavigateUrlPoly";
  194. poly.TabIndex = 2;
  195. poly.Coordinates = "10,20,30,40,50,60,100,200";
  196. imageMap.HotSpots.Add (poly);
  197. #if NET_4_0
  198. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"rect\" coords=\"30,20,40,10\" href=\"NavigateUrlRect\" title=\"Rectangle\" alt=\"Rectangle\" accesskey=\"R\" tabindex=\"1\" /><area shape=\"poly\" coords=\"10,20,30,40,50,60,100,200\" href=\"NavigateUrlPoly\" title=\"Polygon\" alt=\"Polygon\" accesskey=\"P\" tabindex=\"2\" />\r\n</map>";
  199. #else
  200. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"rect\" coords=\"30,20,40,10\" href=\"NavigateUrlRect\" title=\"Rectangle\" alt=\"Rectangle\" accesskey=\"R\" tabindex=\"1\" /><area shape=\"poly\" coords=\"10,20,30,40,50,60,100,200\" href=\"NavigateUrlPoly\" title=\"Polygon\" alt=\"Polygon\" accesskey=\"P\" tabindex=\"2\" />\r\n</map>";
  201. #endif
  202. string renderedHtml = imageMap.Render ();
  203. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderNavigateShapesTextAssigned");
  204. }
  205. [Test]
  206. public void ImageMap_AssignedValues_RenderInactive ()
  207. {
  208. // HotSpotMode = Inactive
  209. //-----------------------
  210. PokerImageMap imageMap = new PokerImageMap ();
  211. imageMap.Enabled = true;
  212. imageMap.HotSpotMode = HotSpotMode.Inactive;
  213. imageMap.Target = "Target";
  214. imageMap.HotSpots.Add (new CircleHotSpot ());
  215. #if NET_4_0
  216. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" nohref=\"true\" title=\"\" alt=\"\" />\r\n</map>";
  217. #else
  218. string originalHtml = "<img src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" nohref=\"true\" title=\"\" alt=\"\" />\r\n</map>";
  219. #endif
  220. string renderedHtml = imageMap.Render ();
  221. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderInaciveTextAssigned");
  222. }
  223. [Test]
  224. public void ImageMap_AssignedValues_RenderDisabled ()
  225. {
  226. // Enabled = false
  227. //----------------
  228. PokerImageMap imageMap = new PokerImageMap ();
  229. imageMap.Enabled = false;
  230. imageMap.HotSpotMode = HotSpotMode.Navigate;
  231. imageMap.Target = "Target";
  232. CircleHotSpot circle = new CircleHotSpot ();
  233. circle.NavigateUrl = "NavigateURL";
  234. imageMap.HotSpots.Add (circle);
  235. #if NET_4_0
  236. string originalHtml = "<img class=\"aspNetDisabled\" src=\"\" usemap=\"#ImageMap\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
  237. #else
  238. string originalHtml = "<img disabled=\"disabled\" src=\"\" usemap=\"#ImageMap\" style=\"border-width:0px;\" /><map name=\"ImageMap\" id=\"ImageMap\">\r\n\t<area shape=\"circle\" coords=\"0,0,0\" href=\"NavigateURL\" target=\"Target\" title=\"\" alt=\"\" />\r\n</map>";
  239. #endif
  240. string renderedHtml = imageMap.Render ();
  241. Console.WriteLine (renderedHtml);
  242. Console.WriteLine ("-----------");
  243. Console.WriteLine (originalHtml);
  244. HtmlDiff.AssertAreEqual (originalHtml, renderedHtml, "RenderDisabledTextAssigne");
  245. }
  246. [Test]
  247. public void ImageMap_ViewState ()
  248. {
  249. PokerImageMap imageMap = new PokerImageMap ();
  250. imageMap.Enabled = true;
  251. Assert.AreEqual (true, imageMap.Enabled, "Enabled-beforecopy");
  252. imageMap.HotSpotMode = HotSpotMode.Navigate;
  253. Assert.AreEqual (HotSpotMode.Navigate, imageMap.HotSpotMode, "HotSpotMode-beforecopy");
  254. imageMap.HotSpots.Add (new CircleHotSpot ());
  255. Assert.AreEqual (1, imageMap.HotSpots.Count, "HotSpots.Count-beforecopy");
  256. imageMap.Target = "Target";
  257. Assert.AreEqual ("Target", imageMap.Target, "Target-beforecopy");
  258. object state = imageMap.SaveState ();
  259. PokerImageMap copy = new PokerImageMap ();
  260. copy.LoadState (state);
  261. Assert.AreEqual (true, copy.Enabled, "Enabled-aftercopy");
  262. Assert.AreEqual (HotSpotMode.Navigate, copy.HotSpotMode, "HotSpotMode-aftercopy");
  263. //Assert.AreEqual(1, copy.HotSpots.Count, "HotSpots.Count-aftercopy");
  264. Assert.AreEqual ("Target", copy.Target, "Target-aftercopy");
  265. }
  266. // Events Stuff
  267. private bool clicked = false;
  268. private string pbValue;
  269. private void ImageMapClickHandler (object sender, ImageMapEventArgs e)
  270. {
  271. clicked = true;
  272. pbValue = e.PostBackValue;
  273. }
  274. private void ResetEvents ()
  275. {
  276. clicked = false;
  277. pbValue = "Init";
  278. }
  279. [Test]
  280. public void ImageMap_Event ()
  281. {
  282. PokerImageMap imageMap = new PokerImageMap ();
  283. ResetEvents ();
  284. imageMap.HotSpotMode = HotSpotMode.PostBack;
  285. imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
  286. Assert.AreEqual (false, clicked, "BeforeClick");
  287. imageMap.DoOnClick (new ImageMapEventArgs ("HotSpotName"));
  288. Assert.AreEqual (true, clicked, "AfterClick");
  289. }
  290. [Test]
  291. public void ImageMap_EventCircle ()
  292. {
  293. PokerImageMap imageMap = new PokerImageMap ();
  294. ResetEvents ();
  295. imageMap.HotSpotMode = HotSpotMode.NotSet;
  296. CircleHotSpot circle = new CircleHotSpot ();
  297. circle.HotSpotMode = HotSpotMode.PostBack;
  298. circle.PostBackValue = "myCircle";
  299. imageMap.HotSpots.Add (circle);
  300. imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
  301. Assert.AreEqual ("Init", pbValue, "BeforeClick");
  302. imageMap.DoOnClick (new ImageMapEventArgs (circle.PostBackValue));
  303. Assert.AreEqual ("myCircle", pbValue, "AfterClick");
  304. }
  305. [Test]
  306. public void ImageMap_EventRectangle ()
  307. {
  308. PokerImageMap imageMap = new PokerImageMap ();
  309. ResetEvents ();
  310. imageMap.HotSpotMode = HotSpotMode.PostBack;
  311. RectangleHotSpot rect = new RectangleHotSpot ();
  312. rect.PostBackValue = "myRect";
  313. imageMap.HotSpots.Add (rect);
  314. imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
  315. Assert.AreEqual ("Init", pbValue, "BeforeClick");
  316. imageMap.DoOnClick (new ImageMapEventArgs (rect.PostBackValue));
  317. Assert.AreEqual ("myRect", pbValue, "AfterClick");
  318. }
  319. [Test]
  320. public void ImageMap_EventPolygon ()
  321. {
  322. PokerImageMap imageMap = new PokerImageMap ();
  323. ResetEvents ();
  324. imageMap.HotSpotMode = HotSpotMode.NotSet;
  325. PolygonHotSpot poly = new PolygonHotSpot ();
  326. poly.HotSpotMode = HotSpotMode.PostBack;
  327. poly.PostBackValue = "myPoly";
  328. imageMap.HotSpots.Add (poly);
  329. imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
  330. Assert.AreEqual ("Init", pbValue, "BeforeClick");
  331. imageMap.DoOnClick (new ImageMapEventArgs (poly.PostBackValue));
  332. Assert.AreEqual ("myPoly", pbValue, "AfterClick");
  333. }
  334. public void ImageMap_BubbleEvent ()
  335. {
  336. PokerImageMap imageMap = new PokerImageMap ();
  337. ResetEvents ();
  338. ImageMapEventArgs args = new ImageMapEventArgs ("HotSpotName");
  339. imageMap.Click += new ImageMapEventHandler (ImageMapClickHandler);
  340. Assert.AreEqual (false, clicked, "BeforeClick");
  341. imageMap.DoOnBubbleEven (imageMap, args);
  342. Assert.AreEqual (true, clicked, "AfterClick");
  343. }
  344. private static void ImageMapClickHandler2 (object sender, ImageMapEventArgs e)
  345. {
  346. WebTest.CurrentTest.UserData = e.PostBackValue;
  347. }
  348. [Test]
  349. [Category ("NunitWeb")]
  350. public void ImageMap_PostBackRectangle ()
  351. {
  352. WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
  353. t.Run ();
  354. FormRequest fr = new FormRequest (t.Response, "form1");
  355. fr.Controls.Add ("__EVENTTARGET");
  356. fr.Controls.Add ("__EVENTARGUMENT");
  357. fr.Controls["__EVENTTARGET"].Value = "imgmap";
  358. fr.Controls["__EVENTARGUMENT"].Value = "0";
  359. t.Request = fr;
  360. t.Run ();
  361. Assert.AreEqual ("Rectangle", t.UserData, "AfterPostBack");
  362. }
  363. [Test]
  364. [Category ("NunitWeb")]
  365. public void ImageMap_PostBackFireEvent ()
  366. {
  367. WebTest t = new WebTest ("NoEventValidation.aspx");
  368. t.Invoker = PageInvoker.CreateOnLoad (PostBackFireEvent_Init);
  369. t.Run ();
  370. FormRequest fr = new FormRequest (t.Response, "form1");
  371. fr.Controls.Add ("__EVENTTARGET");
  372. fr.Controls.Add ("__EVENTARGUMENT");
  373. fr.Controls["__EVENTTARGET"].Value = "imgmap";
  374. fr.Controls["__EVENTARGUMENT"].Value = "0";
  375. t.Request = fr;
  376. t.Run ();
  377. if (t.UserData == null)
  378. Assert.Fail ("Event not fired fail");
  379. Assert.AreEqual ("ImageMapClickHandler", t.UserData.ToString (), "PostBackFireEvent");
  380. }
  381. #region PostBackFireEvent
  382. public static void PostBackFireEvent_Init (Page p)
  383. {
  384. ImageMap imgmap = new ImageMap ();
  385. imgmap.ID = "imgmap";
  386. imgmap.HotSpotMode = HotSpotMode.NotSet;
  387. imgmap.Click += new ImageMapEventHandler (ImageMapClickHandler3);
  388. RectangleHotSpot rect = new RectangleHotSpot ();
  389. rect.HotSpotMode = HotSpotMode.PostBack;
  390. rect.PostBackValue = "Rectangle";
  391. imgmap.HotSpots.Add (rect);
  392. p.Form.Controls.Add (imgmap);
  393. }
  394. public static void ImageMapClickHandler3 (object sender, ImageMapEventArgs e)
  395. {
  396. WebTest.CurrentTest.UserData = "ImageMapClickHandler";
  397. }
  398. #endregion
  399. [Test]
  400. [Category ("NunitWeb")]
  401. public void ImageMap_PostBackCircle ()
  402. {
  403. WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
  404. t.Run ();
  405. FormRequest fr = new FormRequest (t.Response, "form1");
  406. fr.Controls.Add ("__EVENTTARGET");
  407. fr.Controls.Add ("__EVENTARGUMENT");
  408. fr.Controls["__EVENTTARGET"].Value = "imgmap";
  409. fr.Controls["__EVENTARGUMENT"].Value = "2";
  410. t.Request = fr;
  411. t.Run ();
  412. Assert.AreEqual ("Circle", t.UserData, "AfterPostBack");
  413. }
  414. [Test]
  415. [Category ("NunitWeb")]
  416. public void ImageMap_PostBackPolygon ()
  417. {
  418. WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
  419. t.Run ();
  420. FormRequest fr = new FormRequest (t.Response, "form1");
  421. fr.Controls.Add ("__EVENTTARGET");
  422. fr.Controls.Add ("__EVENTARGUMENT");
  423. fr.Controls["__EVENTTARGET"].Value = "imgmap";
  424. fr.Controls["__EVENTARGUMENT"].Value = "1";
  425. t.Request = fr;
  426. t.Run ();
  427. Assert.AreEqual ("Polygon", t.UserData, "AfterPostBack");
  428. }
  429. [Test]
  430. [Category ("NunitWeb")]
  431. public void ImageMap_PostBack_RenderBefore ()
  432. {
  433. WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
  434. #region orig
  435. #if NET_4_0
  436. string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;0&#39;)\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;1&#39;)\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;2&#39;)\" title=\"\" alt=\"\" />\r\n</map>";
  437. #else
  438. string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" style=\"border-width:0px;\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack('imgmap','0')\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack('imgmap','1')\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack('imgmap','2')\" title=\"\" alt=\"\" />\r\n</map>";
  439. #endif
  440. #endregion
  441. string RenderedPageHtml = t.Run ();
  442. string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
  443. HtmlDiff.AssertAreEqual (strTarget, RenderedControlHtml, "BeforePostBack");
  444. }
  445. [Test]
  446. [Category ("NunitWeb")]
  447. public void ImageMap_PostBack_RenderAfter ()
  448. {
  449. WebTest t = new WebTest (PageInvoker.CreateOnLoad (myPageLoad));
  450. t.Run ();
  451. FormRequest fr = new FormRequest (t.Response, "form1");
  452. fr.Controls.Add ("__EVENTTARGET");
  453. fr.Controls.Add ("__EVENTARGUMENT");
  454. fr.Controls["__EVENTTARGET"].Value = "imgmap";
  455. fr.Controls["__EVENTARGUMENT"].Value = "0";
  456. t.Request = fr;
  457. #region orig
  458. #if NET_4_0
  459. string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;0&#39;)\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;1&#39;)\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack(&#39;imgmap&#39;,&#39;2&#39;)\" title=\"\" alt=\"\" />\r\n</map>";
  460. #else
  461. string strTarget = "<img id=\"imgmap\" src=\"\" usemap=\"#ImageMapimgmap\" style=\"border-width:0px;\" /><map name=\"ImageMapimgmap\" id=\"ImageMapimgmap\">\r\n\t<area shape=\"rect\" coords=\"0,0,0,0\" href=\"javascript:__doPostBack('imgmap','0')\" title=\"\" alt=\"\" /><area shape=\"poly\" coords=\"\" href=\"javascript:__doPostBack('imgmap','1')\" title=\"\" alt=\"\" /><area shape=\"circle\" coords=\"0,0,0\" href=\"javascript:__doPostBack('imgmap','2')\" title=\"\" alt=\"\" />\r\n</map>";
  462. #endif
  463. #endregion
  464. string RenderedPageHtml = t.Run ();
  465. string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
  466. HtmlDiff.AssertAreEqual (strTarget, RenderedControlHtml, "AfterPostBack");
  467. }
  468. public static void myPageLoad (Page page)
  469. {
  470. WebTest.CurrentTest.UserData = "Init";
  471. ImageMap imgmap = new ImageMap ();
  472. imgmap.ID = "imgmap";
  473. imgmap.HotSpotMode = HotSpotMode.NotSet;
  474. imgmap.Click += new ImageMapEventHandler (ImageMapClickHandler2);
  475. RectangleHotSpot rect = new RectangleHotSpot ();
  476. rect.HotSpotMode = HotSpotMode.PostBack;
  477. rect.PostBackValue = "Rectangle";
  478. imgmap.HotSpots.Add (rect);
  479. PolygonHotSpot poly = new PolygonHotSpot ();
  480. poly.HotSpotMode = HotSpotMode.PostBack;
  481. poly.PostBackValue = "Polygon";
  482. imgmap.HotSpots.Add (poly);
  483. imgmap.HotSpotMode = HotSpotMode.PostBack;
  484. CircleHotSpot circle = new CircleHotSpot ();
  485. circle.PostBackValue = "Circle";
  486. imgmap.HotSpots.Add (circle);
  487. // Two marks for getting controls from form
  488. LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
  489. LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
  490. page.Form.Controls.Add (lcb);
  491. page.Form.Controls.Add (imgmap);
  492. page.Form.Controls.Add (lce);
  493. }
  494. [SetUp]
  495. public void SetUpTest ()
  496. {
  497. Thread.Sleep (100);
  498. }
  499. [TestFixtureTearDown]
  500. public void TearDown ()
  501. {
  502. WebTest.Unload ();
  503. }
  504. }
  505. }
  506. #endif