dom/tests/mochitest/localstorage/test_localStorageFromChrome.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial