test_third_party.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!--
  2. Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/
  4. -->
  5. <html>
  6. <head>
  7. <title>Indexed Database Test</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. <script type="text/javascript;version=1.7">
  11. const BEHAVIOR_ACCEPT = 0;
  12. const BEHAVIOR_REJECTFOREIGN = 1;
  13. const BEHAVIOR_REJECT = 2;
  14. const BEHAVIOR_LIMITFOREIGN = 3;
  15. const testData = [
  16. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
  17. { host: "http://example.com", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
  18. { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
  19. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
  20. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
  21. { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
  22. { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
  23. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
  24. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },
  25. { host: "http://example.com", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
  26. { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
  27. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },
  28. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true },
  29. { host: "http://example.com", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
  30. { host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
  31. { host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true }
  32. ];
  33. const iframe1Path =
  34. window.location.pathname.replace("test_third_party.html",
  35. "third_party_iframe1.html");
  36. const iframe2URL =
  37. "http://" + window.location.host +
  38. window.location.pathname.replace("test_third_party.html",
  39. "third_party_iframe2.html");
  40. let testIndex = 0;
  41. let testRunning = false;
  42. function iframeLoaded() {
  43. let message = { source: "parent", href: iframe2URL };
  44. let iframe = document.getElementById("iframe1");
  45. iframe.contentWindow.postMessage(message.toSource(), "*");
  46. }
  47. function setiframe() {
  48. let iframe = document.getElementById("iframe1");
  49. if (!testRunning) {
  50. testRunning = true;
  51. iframe.addEventListener("load", iframeLoaded, false);
  52. }
  53. SpecialPowers.pushPrefEnv({
  54. 'set': [["network.cookie.cookieBehavior", testData[testIndex].cookieBehavior]]
  55. }, () => {
  56. iframe.src = testData[testIndex].host + iframe1Path;
  57. });
  58. // SpecialPowers.setIntPref("network.cookie.cookieBehavior", testData[testIndex].cookieBehavior);
  59. }
  60. function messageListener(event) {
  61. let message = eval(event.data);
  62. is(message.source, "iframe", "Good source");
  63. is(message.result, testData[testIndex].expectedResult, "Good result");
  64. if (testIndex < testData.length - 1) {
  65. testIndex++;
  66. setiframe();
  67. return;
  68. }
  69. SimpleTest.finish();
  70. }
  71. function runTest() {
  72. SimpleTest.waitForExplicitFinish();
  73. SpecialPowers.addPermission("indexedDB", true, document);
  74. window.addEventListener("message", messageListener, false);
  75. setiframe();
  76. }
  77. </script>
  78. </head>
  79. <body onload="runTest();">
  80. <iframe id="iframe1"></iframe>
  81. </body>
  82. </html>