test_bug445004.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=445004
  5. -->
  6. <head>
  7. <title>Test for Bug 445004</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=445004">Mozilla Bug 445004</a>
  13. <div id="content" style="display: none">
  14. </div>
  15. <pre id="test">
  16. <script type="application/javascript">
  17. /** Test for Bug 445004 **/
  18. is(window.location.hostname, "mochi.test", "Unexpected hostname");
  19. is(window.location.port, "8888", "Unexpected port; fix testcase");
  20. SimpleTest.waitForExplicitFinish();
  21. var loads = 1;
  22. function loadStarted() {
  23. ++loads;
  24. }
  25. function loadEnded() {
  26. --loads;
  27. if (loads == 0) {
  28. doTest();
  29. }
  30. }
  31. window.onload = loadEnded;
  32. function getMessage(evt) {
  33. ok(evt.data == "start" || evt.data == "end", "Must have start or end");
  34. if (evt.data == "start")
  35. loadStarted();
  36. else
  37. loadEnded();
  38. }
  39. window.addEventListener("message", getMessage, false);
  40. function checkURI(uri, name, type) {
  41. var host = uri.match(/^http:\/\/([a-z.0-9]*)/)[1];
  42. var file = uri.match(/([^\/]*).png$/)[1];
  43. is(host, file, "Unexpected base URI for test " + name +
  44. " when testing " + type);
  45. }
  46. function checkFrame(num) {
  47. // Just snarf our data
  48. var outer = SpecialPowers.wrap(window.frames[num]);
  49. name = outer.name;
  50. is(outer.document.baseURI,
  51. "http://example.org/tests/dom/html/test/bug445004-outer.html",
  52. "Unexpected base URI for " + name);
  53. var iswrite = name.match(/write/);
  54. var inner = outer.frames[0];
  55. if (iswrite) {
  56. is(inner.document.baseURI,
  57. "http://example.org/tests/dom/html/test/bug445004-outer.html",
  58. "Unexpected inner base URI for " + name);
  59. } else {
  60. is(inner.document.baseURI,
  61. "http://test1.example.org/tests/dom/html/test/bug445004-inner.html",
  62. "Unexpected inner base URI for " + name);
  63. }
  64. var isrel = name.match(/rel/);
  65. var offsite = name.match(/offsite/);
  66. if (!iswrite) {
  67. if ((isrel && !offsite) || (!isrel && offsite)) {
  68. is(inner.location.hostname, outer.location.hostname,
  69. "Unexpected hostnames for " + name);
  70. } else {
  71. isnot(inner.location.hostname, outer.location.hostname,
  72. "Unexpected hostnames for " + name);
  73. }
  74. }
  75. checkURI(inner.frames[0].location.href, name, "direct location");
  76. checkURI(inner.frames[1].document.getElementsByTagName("img")[0].src,
  77. name, "direct write");
  78. if (!iswrite) {
  79. is(inner.frames[1].location.hostname, inner.location.hostname,
  80. "Incorrect hostname for " + name + " direct write")
  81. }
  82. checkURI(inner.frames[2].location.href, name, "indirect location");
  83. checkURI(inner.frames[3].document.getElementsByTagName("img")[0].src,
  84. name, "indirect write");
  85. if (!iswrite) {
  86. is(inner.frames[3].location.hostname, outer.location.hostname,
  87. "Incorrect hostname for " + name + " indirect write")
  88. }
  89. checkURI(inner.document.getElementsByTagName("img")[0].src,
  90. name, "direct image load");
  91. }
  92. function doTest() {
  93. for (var num = 0; num < 5; ++num) {
  94. checkFrame(num);
  95. }
  96. SimpleTest.finish();
  97. }
  98. </script>
  99. </pre>
  100. <p id="display">
  101. <iframe
  102. src="http://example.org/tests/dom/html/test/bug445004-outer-rel.html"
  103. name="bug445004-outer-rel.html"></iframe>
  104. <iframe
  105. src="http://test1.example.org/tests/dom/html/test/bug445004-outer-rel.html"
  106. name="bug445004-outer-rel.html offsite"></iframe>
  107. <iframe
  108. src="http://example.org/tests/dom/html/test/bug445004-outer-abs.html"
  109. name="bug445004-outer-abs.html"></iframe>
  110. <iframe
  111. src="http://test1.example.org/tests/dom/html/test/bug445004-outer-abs.html"
  112. name="bug445004-outer-abs.html offsite"></iframe>
  113. <iframe
  114. src="http://example.org/tests/dom/html/test/bug445004-outer-write.html"
  115. name="bug445004-outer-write.html"></iframe>
  116. </p>
  117. </body>
  118. </html>