tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_localStorageFromChrome.xhtml (1933B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <head>
      3 <title>localStorage basic test</title>
      4 
      5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
      7 
      8 <script type="text/javascript">
      9 
     10 async function startTest()
     11 {
     12  await SpecialPowers.pushPrefEnv({"set": [["dom.storage.client_validation", false]]});
     13 
     14  var url = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html";
     15  var ios = Cc["@mozilla.org/network/io-service;1"]
     16    .getService(Ci.nsIIOService);
     17  var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
     18    .getService(Ci.nsIScriptSecurityManager);
     19  var dsm = Cc["@mozilla.org/dom/localStorage-manager;1"]
     20    .getService(Ci.nsIDOMStorageManager);
     21 
     22  var uri = ios.newURI(url);
     23  var principal = ssm.createContentPrincipal(uri, {});
     24  var storage = dsm.createStorage(window, principal, principal, "");
     25 
     26  storage.setItem("chromekey", "chromevalue");
     27 
     28  var aframe = document.getElementById("aframe");
     29  aframe.onload = function()
     30  {
     31    is(storage.getItem("chromekey"), "chromevalue");
     32    is(aframe.contentDocument.getElementById("data").innerHTML, "chromevalue");
     33    SimpleTest.finish();
     34  }
     35  aframe.src = "http://example.com/tests/dom/tests/mochitest/localstorage/frameChromeSlave.html";  
     36 
     37  // Additionally check that we do not crash when we access the localStorage
     38  // object in the owning chrome window (but we should throw).  See bug 485396.
     39  var exceptionCaught = false;
     40  try {
     41    localStorage;
     42  }
     43  catch (e) {
     44    is(e.result, Cr.NS_ERROR_NOT_AVAILABLE,
     45       "Testing that we get the expected exception.");
     46    exceptionCaught = true;
     47  }
     48  is(exceptionCaught, true, "Testing that an exception was thrown.");
     49 }
     50 
     51 SimpleTest.waitForExplicitFinish();
     52 
     53 </script>
     54 
     55 </head>
     56 
     57 <body onload="startTest();">
     58  <iframe src="" id="aframe"></iframe>
     59 </body>
     60 </html>