test_same_site_cookies_about.html (4343B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Bug 1454721 - Add same-site cookie test for about:blank and about:srcdoc</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <img id="cookieImage"> 10 <iframe id="testframe"></iframe> 11 12 <script class="testbody" type="text/javascript"> 13 14 /* 15 * Description of the test: 16 * 1) We load an image from http://mochi.test which sets a same site cookie 17 * 2) We then load the following iframes: 18 * (a) cross-origin iframe 19 * (b) same-origin iframe 20 * which both load a: 21 * * nested about:srcdoc frame and nested about:blank frame 22 * * navigate about:srcdoc frame and navigate about:blank frame 23 * 3) We evaluate that the same-site cookie is available in the same-origin case. 24 */ 25 26 SimpleTest.waitForExplicitFinish(); 27 28 const SAME_ORIGIN = "http://mochi.test:8888/" 29 const CROSS_ORIGIN = "http://example.com/"; 30 const PATH = "tests/dom/security/test/general/file_same_site_cookies_about.sjs"; 31 32 let curTest = 0; 33 34 var tests = [ 35 // NAVIGATION TESTS 36 { 37 description: "nested same origin iframe about:srcdoc navigation [mochi.test -> mochi.test -> about:srcdoc -> mochi.test]", 38 frameSRC: SAME_ORIGIN + PATH + "?loadsrcdocframeNav", 39 result: "myKey=mySameSiteAboutCookie", // cookie should be set for baseline test 40 }, 41 { 42 description: "nested cross origin iframe about:srcdoc navigation [mochi.test -> example.com -> about:srcdoc -> mochi.test]", 43 frameSRC: CROSS_ORIGIN + PATH + "?loadsrcdocframeNav", 44 result: "", // no same-site cookie should be available 45 }, 46 { 47 description: "nested same origin iframe about:blank navigation [mochi.test -> mochi.test -> about:blank -> mochi.test]", 48 frameSRC: SAME_ORIGIN + PATH + "?loadblankframeNav", 49 result: "myKey=mySameSiteAboutCookie", // cookie should be set for baseline test 50 }, 51 { 52 description: "nested cross origin iframe about:blank navigation [mochi.test -> example.com -> about:blank -> mochi.test]", 53 frameSRC: CROSS_ORIGIN + PATH + "?loadblankframeNav", 54 result: "", // no same-site cookie should be available 55 }, 56 // INCLUSION TESTS 57 { 58 description: "nested same origin iframe about:srcdoc inclusion [mochi.test -> mochi.test -> about:srcdoc -> mochi.test]", 59 frameSRC: SAME_ORIGIN + PATH + "?loadsrcdocframeInc", 60 result: "myKey=mySameSiteAboutCookie", // cookie should be set for baseline test 61 }, 62 { 63 description: "nested cross origin iframe about:srcdoc inclusion [mochi.test -> example.com -> about:srcdoc -> mochi.test]", 64 frameSRC: CROSS_ORIGIN + PATH + "?loadsrcdocframeInc", 65 result: "", // no same-site cookie should be available 66 }, 67 { 68 description: "nested same origin iframe about:blank inclusion [mochi.test -> mochi.test -> about:blank -> mochi.test]", 69 frameSRC: SAME_ORIGIN + PATH + "?loadblankframeInc", 70 result: "myKey=mySameSiteAboutCookie", // cookie should be set for baseline test 71 }, 72 { 73 description: "nested cross origin iframe about:blank inclusion [mochi.test -> example.com -> about:blank -> mochi.test]", 74 frameSRC: CROSS_ORIGIN + PATH + "?loadblankframeInc", 75 result: "", // no same-site cookie should be available 76 }, 77 ]; 78 79 window.addEventListener("message", receiveMessage); 80 function receiveMessage(event) { 81 is(event.data.result, tests[curTest].result, tests[curTest].description); 82 curTest += 1; 83 84 // lets see if we ran all the tests 85 if (curTest == tests.length) { 86 window.removeEventListener("message", receiveMessage); 87 SimpleTest.finish(); 88 return; 89 } 90 // otherwise it's time to run the next test 91 setCookieAndInitTest(); 92 } 93 94 function setupQueryResultAndRunTest() { 95 let testframe = document.getElementById("testframe"); 96 testframe.src = tests[curTest].frameSRC + curTest; 97 } 98 99 function setCookieAndInitTest() { 100 var cookieImage = document.getElementById("cookieImage"); 101 cookieImage.onload = function() { 102 ok(true, "trying to set cookie for test (" + tests[curTest].description + ")"); 103 setupQueryResultAndRunTest(); 104 } 105 cookieImage.onerror = function() { 106 ok(false, "could not load image for test (" + tests[curTest].description + ")"); 107 } 108 cookieImage.src = SAME_ORIGIN + PATH + "?setSameSiteCookie" + curTest; 109 } 110 111 // fire up the test 112 setCookieAndInitTest(); 113 114 </script> 115 </body> 116 </html>