PageRenderTime 44ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 0ms

/Application/Magnets/Webnet/Webnet.Test/HTMLTools_Test.cs

#
C# | 100 lines | 65 code | 6 blank | 29 comment | 0 complexity | 37a38f6b311f9a29512011a4bb1decb7 MD5 | raw file
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace Webnet.Test
  7. {
  8. /// <summary>
  9. /// Summary description for UnitTest1
  10. /// </summary>
  11. [TestClass]
  12. public class HTMLTools_Test
  13. {
  14. public HTMLTools_Test()
  15. {
  16. //
  17. // TODO: Add constructor logic here
  18. //
  19. }
  20. private TestContext testContextInstance;
  21. /// <summary>
  22. ///Gets or sets the test context which provides
  23. ///information about and functionality for the current test run.
  24. ///</summary>
  25. public TestContext TestContext
  26. {
  27. get
  28. {
  29. return testContextInstance;
  30. }
  31. set
  32. {
  33. testContextInstance = value;
  34. }
  35. }
  36. #region Additional test attributes
  37. //
  38. // You can use the following additional attributes as you write your tests:
  39. //
  40. // Use ClassInitialize to run code before running the first test in the class
  41. // [ClassInitialize()]
  42. // public static void MyClassInitialize(TestContext testContext) { }
  43. //
  44. // Use ClassCleanup to run code after all tests in a class have run
  45. // [ClassCleanup()]
  46. // public static void MyClassCleanup() { }
  47. //
  48. // Use TestInitialize to run code before running each test
  49. // [TestInitialize()]
  50. // public void MyTestInitialize() { }
  51. //
  52. // Use TestCleanup to run code after each test has run
  53. // [TestCleanup()]
  54. // public void MyTestCleanup() { }
  55. //
  56. #endregion
  57. [TestMethod]
  58. public void GetHtmlWidthTest()
  59. {
  60. HTMLTools htmlTools = new HTMLTools();
  61. int width = htmlTools.GetHtmlWidth(@"<p width=""100%"" align=""center""><embed pluginspage=""http://www.adobe.com/go/getflashplayer"" src=""http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/widgia/mini:calculator"" wmode=""transparent"" width=""219"" height=""344"" FlashVars=""color=12111&xheight=344&xwidth=219&mininame=calculator&uri=yourminis%2Fwidgia%2Fmini%3Acalculator&width=209&height=334&"" type=""application/x-shockwave-flash"" allowScriptAccess=""always""></embed><br /><a href=""http://widgia.com"">More widgets here</a></p>",0);
  62. Assert.AreEqual(219, width);
  63. width = htmlTools.GetHtmlWidth(@"<div><object width=""480"" height=""332""><param name=""movie"" value=""http://www.dailymotion.com/swf/x255su&related=0""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowScriptAccess"" value=""always""></param><embed src=""http://www.dailymotion.com/swf/x255su&related=0"" type=""application/x-shockwave-flash"" width=""480"" height=""332"" allowfullscreen=""true"" allowscriptaccess=""always""></embed></object><br /><b><a href=""http://www.dailymotion.com/video/x255su_50-cents-pimp-uncensored_music"">50 Cents - P.I.M.P (Uncensored)</a></b><br /><i>envoy&eacute; par <a href=""http://www.dailymotion.com/toto60620"">toto60620</a>. - <a href=""http://www.dailymotion.com/ca-fr/channel/music"">Regardez d'autres vidéos de musique.</a></i></div>", 0);
  64. Assert.AreEqual(480, width);
  65. width = htmlTools.GetHtmlWidth(@"<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"" type=""application/x-shockwave-flash"" width=""120px"" height=""203px"" id=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" align=""middle""><param name=""movie"" value=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""/><param name=""quality"" value=""high"" /><param name=""wmode"" value=""transparent"" /><param name=""menu"" value=""false"" /><param name=""flashvars"" value=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /><param name=""allowScriptAccess"" value=""sameDomain"" /> <embed src=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf"" name=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" width=""120px"" height=""203px"" quality=""high"" menu=""false"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent"" align=""middle"" allowScriptAccess=""sameDomain"" flashvars=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /></object>", 0);
  66. Assert.AreEqual(120, width);
  67. width = htmlTools.GetHtmlWidth(@"<script type=""text/javascript"" src=""http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js""></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('4987c999-03e0-446c-a2d7-fd9f9a784914');</script><noscript>Get the <a href=""http://www.widgetbox.com/widget/baby-ticker"">Baby Ticker - The Baby Countdown Pregnancy Ticker</a> wiydget and many other <a href=""http://www.widgetbox.com/"">great free widgets</a> at <a href=""http://www.widgetbox.com"">Widgetbox</a>! Not seeing a widget? (<a href=""http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/"">More info</a>)</noscript>", 0);
  68. Assert.AreEqual(-1, width);
  69. width = htmlTools.GetHtmlWidth(@"<script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F%2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishColor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&amp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script>", 0);
  70. Assert.AreEqual(320, width);
  71. }
  72. [TestMethod]
  73. public void GetHtmlHeightTest()
  74. {
  75. HTMLTools htmlTools = new HTMLTools();
  76. int height = htmlTools.GetHtmlHeight(@"<p width=""100%"" align=""center""><embed pluginspage=""http://www.adobe.com/go/getflashplayer"" src=""http://www.yourminis.com/Dir/GetContainer.api?uri=yourminis/widgia/mini:calculator"" wmode=""transparent"" width=""219"" height=""344"" FlashVars=""color=12111&xheight=344&xwidth=219&mininame=calculator&uri=yourminis%2Fwidgia%2Fmini%3Acalculator&width=209&height=334&"" type=""application/x-shockwave-flash"" allowScriptAccess=""always""></embed><br /><a href=""http://widgia.com"">More widgets here</a></p>", 0);
  77. Assert.AreEqual(344, height);
  78. height = htmlTools.GetHtmlHeight(@"<div><object width=""480"" height=""332""><param name=""movie"" value=""http://www.dailymotion.com/swf/x255su&related=0""></param><param name=""allowFullScreen"" value=""true""></param><param name=""allowScriptAccess"" value=""always""></param><embed src=""http://www.dailymotion.com/swf/x255su&related=0"" type=""application/x-shockwave-flash"" width=""480"" height=""332"" allowfullscreen=""true"" allowscriptaccess=""always""></embed></object><br /><b><a href=""http://www.dailymotion.com/video/x255su_50-cents-pimp-uncensored_music"">50 Cents - P.I.M.P (Uncensored)</a></b><br /><i>envoy&eacute; par <a href=""http://www.dailymotion.com/toto60620"">toto60620</a>. - <a href=""http://www.dailymotion.com/ca-fr/channel/music"">Regardez d'autres vidéos de musique.</a></i></div>", 0);
  79. Assert.AreEqual(332, height);
  80. height = htmlTools.GetHtmlHeight(@"<object classid=""clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"" codebase=""http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"" type=""application/x-shockwave-flash"" width=""120px"" height=""203px"" id=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" align=""middle""><param name=""movie"" value=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf""/><param name=""quality"" value=""high"" /><param name=""wmode"" value=""transparent"" /><param name=""menu"" value=""false"" /><param name=""flashvars"" value=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /><param name=""allowScriptAccess"" value=""sameDomain"" /> <embed src=""http://widgetserver.com/syndication/flash/wrapper/InsertWidget.swf"" name=""InsertWidget_28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" width=""120px"" height=""203px"" quality=""high"" menu=""false"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" wmode=""transparent"" align=""middle"" allowScriptAccess=""sameDomain"" flashvars=""r=2&appId=28eb3e5c-e37e-47d8-a4e5-7cdcae9e4c97"" /></object>", 0);
  81. Assert.AreEqual(203, height);
  82. height = htmlTools.GetHtmlHeight(@"<script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F%2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishColor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&amp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script>", 0);
  83. Assert.AreEqual(200, height);
  84. height = htmlTools.GetHtmlHeight(@"@<html><head><style>html, body { height: 100%; overflow: hidden;}</style></head><body bgcolor=""#0F0F0F"" leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0""><script src=""http://www.gmodules.com/ig/ifr?url=http://fishgadget.googlecode.com/svn/trunk/fish.xml&amp;up_fishColor=none&amp;up_fishName=Fish&amp;up_backgroundColor=F0F7FF&amp;up_backgroundImage=http%3A%2F
  85. %2F&amp;up_numFish=5&amp;up_fishColor1=F45540&amp;up_fishColor2=F45540&amp;up_fishColor3=F45540&amp;up_fishColor4=F45540&amp;up_fishColor5=F45540&amp;up_fishColor6=F45540&amp;up_fishColor7=F45540&amp;up_fishC
  86. olor8=F45540&amp;up_fishColor9=F45540&amp;up_fishColor10=F45540&amp;up_foodColor=FCB347&amp;up_userColor1=&amp;up_userColor2=&amp;up_userColor3=&amp;up_userColor4=&amp;up_userColor5=&amp;synd=open&amp;w=320&a
  87. mp;h=200&amp;title=__UP_fishName__&amp;border=%23ffffff%7C0px%2C1px+solid+%23595959%7C0px%2C1px+solid+%23797979%7C0px%2C2px+solid+%23898989&amp;output=js""></script></body><html/>", 0);
  88. Assert.AreEqual(200, height);
  89. }
  90. }
  91. }