test_sessionStorageClone.html (2679B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>sessionStorage clone equal origins</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 <script type="text/javascript"> 10 11 var currentTest = 1; 12 var currentStep = 1; 13 14 async function doNextTest() 15 { 16 // Make sure we do not unpartition storage inappropriately 17 await SpecialPowers.pushPrefEnv({ 18 set: [ 19 ["privacy.partition.always_partition_third_party_non_cookie_storage", true], 20 ["privacy.partition.always_partition_third_party_non_cookie_storage.exempt_sessionstorage", false], 21 ["privacy.restrict3rdpartystorage.heuristic.window_open", false], 22 ], 23 }); 24 25 // We must perform the first step of the test 26 // to prepare the land. 27 currentStep = 1; 28 doStep(); 29 30 switch (currentTest) 31 { 32 case 1: 33 // Open a window from the same origin and check data 34 // are copied but not further modified on our side 35 slaveOrigin = "http://mochi.test:8888"; 36 if (isXOrigin) { 37 slave = window.open(slaveOrigin + slavePath + "frameNotEqual.html"); 38 } else { 39 slave = window.open(slaveOrigin + slavePath + "frameEqual.html"); 40 } 41 break; 42 43 case 2: 44 slave.close(); 45 // Open a window from a different origin and check data 46 // are NOT copied and not modified on our side 47 slaveOrigin = "https://example.com"; 48 slave = window.open(slaveOrigin + slavePath + "frameNotEqual.html"); 49 break; 50 51 case 3: 52 slave.close(); 53 sessionStorage.clear(); 54 SimpleTest.finish(); 55 break; 56 } 57 58 ++currentTest; 59 } 60 61 function doStep() 62 { 63 switch (currentStep) 64 { 65 case 1: 66 sessionStorage.setItem("A", "1"); 67 sessionStorage.setItem("B", "2"); 68 is(sessionStorage.getItem("A"), "1", "A is 1 in the master"); 69 is(sessionStorage.getItem("B"), "2", "B is 2 in the master"); 70 is(sessionStorage.length, 2, "Num of items is 2"); 71 break; 72 73 case 3: 74 is(sessionStorage.getItem("A"), "1", "A is 1 in the master"); 75 is(sessionStorage.getItem("B"), "2", "B is 2 in the master"); 76 is(sessionStorage.getItem("C"), null, "C is null in the master"); 77 is(sessionStorage.length, 2, "Num of items is 2"); 78 79 sessionStorage.setItem("C", "4"); 80 is(sessionStorage.getItem("C"), "4", "C is 4 in the master"); 81 is(sessionStorage.length, 3, "Num of items is 3"); 82 break; 83 } 84 85 ++currentStep; 86 ++currentStep; 87 88 return true; 89 } 90 91 SimpleTest.waitForExplicitFinish(); 92 93 </script> 94 95 </head> 96 97 <body onload="doNextTest();"> 98 </body> 99 </html>