test_triggeringprincipal_location_seturi.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  5. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  6. </head>
  7. <body>
  8. <script type="text/javascript">
  9. SimpleTest.waitForExplicitFinish();
  10. const SAME_ORIGIN_URI = "http://mochi.test:8888/tests/docshell/test/dummy_page.html";
  11. const CROSS_ORIGIN_URI = "http://example.com/tests/docshell/test/dummy_page.html";
  12. const NUMBER_OF_TESTS = 3;
  13. let testCounter = 0;
  14. function checkFinish() {
  15. testCounter++;
  16. if (testCounter < NUMBER_OF_TESTS) {
  17. return;
  18. }
  19. SimpleTest.finish();
  20. }
  21. // ---- test 1 ----
  22. let myFrame1 = document.createElement("iframe");
  23. myFrame1.src = SAME_ORIGIN_URI;
  24. myFrame1.addEventListener("load", checkLoadFrame1);
  25. document.documentElement.appendChild(myFrame1);
  26. function checkLoadFrame1() {
  27. myFrame1.removeEventListener('load', checkLoadFrame1, false);
  28. // window.location.href is no longer cross-origin accessible in gecko.
  29. is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, SAME_ORIGIN_URI,
  30. "initial same origin dummy loaded into frame1");
  31. SpecialPowers.wrap(myFrame1.contentWindow).location.hash = "#bar";
  32. is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, SAME_ORIGIN_URI + "#bar",
  33. "initial same origin dummy#bar loaded into iframe1");
  34. myFrame1.addEventListener("load", checkNavFrame1);
  35. myFrame1.src = CROSS_ORIGIN_URI;
  36. }
  37. function checkNavFrame1() {
  38. myFrame1.removeEventListener('load', checkNavFrame1, false);
  39. is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, CROSS_ORIGIN_URI,
  40. "cross origin dummy loaded into frame1");
  41. myFrame1.addEventListener("load", checkBackNavFrame1);
  42. myFrame1.src = SAME_ORIGIN_URI + "#bar";
  43. }
  44. function checkBackNavFrame1() {
  45. myFrame1.removeEventListener('load', checkBackNavFrame1, false);
  46. is(SpecialPowers.wrap(myFrame1.contentWindow).location.href, SAME_ORIGIN_URI + "#bar",
  47. "navagiating back to same origin dummy for frame1");
  48. checkFinish();
  49. }
  50. // ---- test 2 ----
  51. let myFrame2 = document.createElement("iframe");
  52. myFrame2.src = "about:blank";
  53. myFrame2.addEventListener("load", checkLoadFrame2);
  54. document.documentElement.appendChild(myFrame2);
  55. function checkLoadFrame2() {
  56. myFrame2.removeEventListener('load', checkLoadFrame2, false);
  57. is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank",
  58. "initial about:blank frame loaded");
  59. myFrame2.contentWindow.location.hash = "#foo";
  60. is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank#foo",
  61. "about:blank#foo frame loaded");
  62. myFrame2.addEventListener('load', checkHistoryFrame2);
  63. myFrame2.src = "about:blank";
  64. }
  65. function checkHistoryFrame2() {
  66. myFrame2.removeEventListener('load', checkHistoryFrame2, false);
  67. is(SpecialPowers.wrap(myFrame2.contentWindow).location.href, "about:blank",
  68. "about:blank frame loaded again");
  69. checkFinish();
  70. }
  71. // ---- test 3 ----
  72. let myFrame3 = document.createElement("frame");
  73. document.documentElement.appendChild(myFrame3);
  74. myFrame3.contentWindow.location.hash = "#foo";
  75. is(myFrame3.contentWindow.location.href, "about:blank#foo",
  76. "created history entry with about:blank#foo");
  77. checkFinish();
  78. </script>
  79. </body>
  80. </html>