test_localStorageCookieSettings.html (1935B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>localStorage cookies settings test</title> 4 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="interOriginTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 9 </head> 10 <body> 11 12 <script type="text/javascript"> 13 14 SimpleTest.waitForExplicitFinish(); 15 16 // Set cookies behavior to "always reject". 17 SpecialPowers.pushPrefEnv({"set": [ 18 ["network.cookie.cookieBehavior", 2], 19 ]}, test1); 20 21 function test1() { 22 let w = window.open("windowProxy.html"); 23 w.onload = _ => { 24 try { 25 w.localStorage.setItem("contentkey", "test-value"); 26 ok(false, "Setting localStorageItem should throw a security exception"); 27 } 28 catch(ex) { 29 is(ex.name, "SecurityError", "Got security exception"); 30 } 31 32 w.close(); 33 34 // Set cookies behavior to "reject 3rd party" 35 SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 1]], }, test2); 36 } 37 } 38 39 function test2() { 40 let w = window.open("windowProxy.html"); 41 w.onload = _ => { 42 try { 43 w.localStorage.setItem("contentkey", "test-value"); 44 ok(true, "Setting localStorageItem should not throw a security exception"); 45 } 46 catch(ex) { 47 ok(false, "Setting localStorageItem should not throw a security exception"); 48 } 49 50 var fileTest = (location.protocol + "//example.com" + location.pathname) 51 .replace("test_l", "frameL"); 52 53 var myframe = w.document.createElement("iframe"); 54 w.document.body.appendChild(myframe); 55 myframe.src = fileTest; 56 57 w.onmessage = function(e) { 58 switch (e.data.type || "") { 59 case "ok": 60 ok(e.data.what, e.data.msg); 61 break; 62 case "finish": 63 w.close(); 64 SimpleTest.finish(); 65 break; 66 default: 67 ok(false, "Invalid type."); 68 } 69 }; 70 } 71 } 72 73 </script> 74 </body> 75 </html>