dom/tests/mochitest/localstorage/test_localStorageEnablePref.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>localStorage enable preference test</title>
michael@0 4
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7
michael@0 8 <script type="text/javascript">
michael@0 9
michael@0 10 SimpleTest.requestCompleteLog();
michael@0 11
michael@0 12 function checkException(func, exc)
michael@0 13 {
michael@0 14 var exceptionThrew = false;
michael@0 15 try {
michael@0 16 func();
michael@0 17 }
michael@0 18 catch (ex) {
michael@0 19 exceptionThrew = true;
michael@0 20 is(ex.name, exc, "Expected "+exc+" exception");
michael@0 21 if (ex.name != exc) {
michael@0 22 info("The exception which was thrown is: " + ex);
michael@0 23 }
michael@0 24 }
michael@0 25 ok(exceptionThrew, "Exception "+exc+" threw");
michael@0 26 }
michael@0 27
michael@0 28 var storage;
michael@0 29 function test1() {
michael@0 30 is(typeof(window.localStorage), "object", "Storage is present");
michael@0 31 storage = window.localStorage;
michael@0 32
michael@0 33 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", false]]}, test2);
michael@0 34 }
michael@0 35
michael@0 36 function test2() {
michael@0 37 is(window.localStorage, null, "Storage is null");
michael@0 38
michael@0 39 checkException(function() {storage.setItem("test", "value");}, "SecurityError");
michael@0 40
michael@0 41 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test3);
michael@0 42 }
michael@0 43
michael@0 44 function test3() {
michael@0 45 is(typeof(window.localStorage), "object", "Storage is present again");
michael@0 46 storage.setItem("test", "value");
michael@0 47 ok(storage.getItem("test"), "value", "value can be set");
michael@0 48 window.localStorage.clear();
michael@0 49 SimpleTest.finish();
michael@0 50 }
michael@0 51
michael@0 52 function doTest() {
michael@0 53 SpecialPowers.pushPrefEnv({"set": [["dom.storage.enabled", true]]}, test1);
michael@0 54 }
michael@0 55
michael@0 56 SimpleTest.waitForExplicitFinish();
michael@0 57
michael@0 58 </script>
michael@0 59
michael@0 60 </head>
michael@0 61
michael@0 62 <body onload="doTest();">
michael@0 63
michael@0 64 </body>
michael@0 65 </html>

mercurial