Ticket #13749: 0001-Bug-13749.1-regression-tests-for-first-party-isolati.patch

File 0001-Bug-13749.1-regression-tests-for-first-party-isolati.patch, 6.6 KB (added by arthuredelstein, 5 years ago)
  • new file dom/tests/mochitest/localstorage/firstParty.html

    From 937577429e092841890d6a2308b4192f2a8c99d0 Mon Sep 17 00:00:00 2001
    From: Arthur Edelstein <arthuredelstein@gmail.com>
    Date: Wed, 10 Dec 2014 17:35:12 -0800
    Subject: [PATCH] Bug #13749.1: regression tests for first party isolation of
     localStorage
    
    ---
     dom/tests/mochitest/localstorage/firstParty.html   | 16 +++++
     .../mochitest/localstorage/firstPartyInner.html    | 25 ++++++++
     dom/tests/mochitest/localstorage/mochitest.ini     |  3 +
     .../test_localStorageByFirstParty.html             | 73 ++++++++++++++++++++++
     4 files changed, 117 insertions(+)
     create mode 100644 dom/tests/mochitest/localstorage/firstParty.html
     create mode 100644 dom/tests/mochitest/localstorage/firstPartyInner.html
     create mode 100644 dom/tests/mochitest/localstorage/test_localStorageByFirstParty.html
    
    diff --git a/dom/tests/mochitest/localstorage/firstParty.html b/dom/tests/mochitest/localstorage/firstParty.html
    new file mode 100644
    index 0000000..7bf2539
    - +  
     1<html xmlns="http://www.w3.org/1999/xhtml">
     2  <script>
     3    window.onload = function () {
     4      var inner = document.getElementById("inner");
     5      window.addEventListener("message", function (event) {
     6        opener.postMessage(event.data, "http://mochi.test:8888");
     7      });
     8      inner.src = "http://example.net/tests/dom/tests/mochitest/localstorage/firstPartyInner.html" +
     9                  location.search + "&host=" + encodeURIComponent(location.protocol + "//" + location.host);
     10    };
     11  </script>
     12  <body>
     13    <div>firstParty.html</div>
     14    <iframe id="inner" width=400 height=200></iframe>
     15  </body>
     16</html>
  • new file dom/tests/mochitest/localstorage/firstPartyInner.html

    diff --git a/dom/tests/mochitest/localstorage/firstPartyInner.html b/dom/tests/mochitest/localstorage/firstPartyInner.html
    new file mode 100644
    index 0000000..1b24d2b
    - +  
     1<html xmlns="http://www.w3.org/1999/xhtml">
     2  <body>
     3    <div>firstPartyInner.html</div>
     4    <pre id="result"></pre>
     5    <script>
     6      var request = new URLSearchParams(location.search.substring(1)),
     7          expected = request.get("expected"),
     8          prescribed = request.get("prescribed"),
     9          host = decodeURIComponent(request.get("host")),
     10          found = localStorage.getItem("firstPartyTest"),
     11          resultDiv = document.getElementById("result"),
     12          show = function (x) { resultDiv.innerHTML += x + "\n"; };
     13      show("host: " + host);
     14      if (expected) {
     15        show("expected: " + expected);
     16        show("found: " + found);
     17      }
     18      if (prescribed) {
     19        localStorage.setItem("firstPartyTest", prescribed);
     20        show("wrote: " + prescribed);
     21      }
     22      parent.postMessage(expected ? (found === expected) : true, host);
     23    </script>
     24  </body>
     25</html>
  • dom/tests/mochitest/localstorage/mochitest.ini

    diff --git a/dom/tests/mochitest/localstorage/mochitest.ini b/dom/tests/mochitest/localstorage/mochitest.ini
    index 3b3c50c..6d258f3 100644
    a b  
    11[DEFAULT]
    22support-files =
     3  firstParty.html
     4  firstPartyInner.html
    35  frameAppIsolation.html
    46  frameChromeSlave.html
    57  frameKeySync.html
    skip-if = toolkit=='gonk' # b2g(4 failures) b2g-debug(debug-only failure) 
    3234[test_localStorageBase.html]
    3335skip-if = buildapp == 'b2g' || e10s # b2g(no storage chrome event received)
    3436[test_localStorageBaseSessionOnly.html]
     37[test_localStorageByFirstParty.html]
    3538skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))
    3639[test_localStorageCookieSettings.html]
    3740skip-if = (buildapp == 'b2g' && (toolkit != 'gonk' || debug))
  • new file dom/tests/mochitest/localstorage/test_localStorageByFirstParty.html

    diff --git a/dom/tests/mochitest/localstorage/test_localStorageByFirstParty.html b/dom/tests/mochitest/localstorage/test_localStorageByFirstParty.html
    new file mode 100644
    index 0000000..6858303
    - +  
     1<html xmlns="http://www.w3.org/1999/xhtml">
     2<head>
     3<title>localStorage by first party test</title>
     4
     5<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     7
     8<script type="application/javascript;version=1.7">
     9
     10// This series of unit tests ensures that, when the "privacy.thirdparty.isolate" pref
     11// is set to 2 (active), we should have a separate localStorage for each first-party
     12// (URL bar domain). If the pref is set to 0 (inactive), then two iframes with the
     13// same origin but different first-party domains will share localStorage.
     14
     15let originalPrefValue = SpecialPowers.getIntPref("privacy.thirdparty.isolate");
     16
     17let mapToUriParameters = aMap =>
     18  Object.keys(aMap).map(k => encodeURIComponent(k) + "=" +
     19                             encodeURIComponent(aMap[k])).join("&");
     20
     21let steps = [
     22  // When first party isolation is turned off, we expect that DOM storage will be
     23  // the same for two iframes at http://example.net.
     24  { domain : "example.com", prescribed : "test1", pref : 0 },
     25  { domain : "example.org", prescribed : "test2" },
     26  { domain : "example.com", expected : "test2", prescribed : "test3" },
     27  { domain : "example.org", expected : "test3", prescribed : "test4" },
     28  // When first party isolation is turned on, we expect two separate DOM storage
     29  // silos for two iframes both at http://example.net but contained in pages
     30  // with different first party domains.
     31  { domain : "example.com", prescribed : "test1", pref : 2 },
     32  { domain : "example.org", prescribed : "test2" },
     33  { domain : "example.com", expected : "test1", prescribed : "test3" },
     34  { domain : "example.org", expected : "test2", prescribed : "test4" }
     35];
     36
     37let runStep = function (i) {
     38  if (i < steps.length) {
     39    let step = steps[i],
     40        { domain, pref } = step;
     41    if (pref !== undefined) {
     42      SpecialPowers.setIntPref("privacy.thirdparty.isolate", pref);
     43    }
     44    window.open("http://" + domain +
     45                "/tests/dom/tests/mochitest/localstorage/firstParty.html?" +
     46                mapToUriParameters(step), "_blank");
     47  } else if (i == steps.length) {
     48    SpecialPowers.setIntPref("privacy.thirdparty.isolate", originalPrefValue);
     49    SimpleTest.finish();
     50  }
     51};
     52
     53let startTest = function () {
     54  let i = 0;
     55  window.addEventListener("message", function (event) {
     56    // Get the result of the last step.
     57    is(event.data, true, "correct DOM storage isolation");
     58    // Run the next step.
     59    runStep(++i);
     60  });
     61  runStep(0);
     62};
     63
     64SimpleTest.waitForExplicitFinish();
     65
     66</script>
     67
     68</head>
     69
     70<body onload="startTest();">
     71
     72</body>
     73</html>