test_bug346659.html (4721B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=346659 5 --> 6 <head> 7 <title>Test for Bug 346659</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=346659">Mozilla Bug 346659</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 20 /** Test for Bug 346659 */ 21 var numTests = 11; 22 SimpleTest.requestLongerTimeout(2); // test takes a long time on android and b2g emulators 23 SimpleTest.waitForExplicitFinish(); 24 25 const xorigBase = window.location.href.replace(location.host, "example.com"); 26 const makeXOrig = tail => xorigBase.replace(/\/[^\/]*$/, "/" + tail); 27 28 const tests = [ 29 { 30 func: testId => { 31 const win = window.open(`bug346659-echoer.html?${testId}`); 32 win.x = testId; 33 }, 34 expectPreserveProp: true, 35 descr: 'Props on new window should be preserved when loading' 36 }, 37 { 38 func: testId => { 39 const win = window.open(""); 40 win.x = testId; 41 win.document.write(`<script> window.opener.postMessage("${testId} - " + window.x, '*'); window.close(); </scr`+`ipt>`); 42 }, 43 expectPreserveProp: true, 44 descr: 'Props on new window should be preserved when writing' 45 }, 46 { 47 func: testId => window.open(`file_bug346659.html?testId=${testId}&type=popup`), 48 expectPreserveProp: true, 49 descr: 'Props on window opened from new window should be preserved when loading' 50 }, 51 { 52 func: testId => window.open(`file_bug346659.html?testId=${testId}&type=popup&method=write`), 53 expectPreserveProp: true, 54 descr: 'Props on window opened from new window should be preserved when writing' 55 }, 56 { 57 func: testId => window.open(`file_bug346659.html?testId=${testId}&type=iframe`), 58 expectPreserveProp: true, 59 descr: "Props on new window's child should be preserved when loading" 60 }, 61 { 62 func: testId => window.open(`file_bug346659.html?testId=${testId}&type=iframe&method=write`), 63 expectPreserveProp: true, 64 descr: "Props on new window's child should not go away when writing" 65 }, 66 { 67 func: testId => window.open(makeXOrig(`file_bug346659.html?testId=${testId}&type=popup`)), 68 expectPreserveProp: true, 69 descr: 'Props on different-domain window opened from different-domain new window can stay' 70 }, 71 { 72 func: testId => window.open(makeXOrig(`file_bug346659.html?testId=${testId}&type=iframe`)), 73 expectPreserveProp: true, 74 descr: "Props on different-domain new window's child should be preserved when loading" 75 }, 76 { 77 func: testId => window.open(makeXOrig(`file_bug346659.html?testId=${testId}&type=popup&childHost=${location.host}`)), 78 expectPreserveProp: false, 79 descr: "Props on same-domain window opened from different-domain new window should go away when loading" 80 }, 81 { 82 func: testId => window.open(makeXOrig(`file_bug346659.html?testId=${testId}&type=iframe&childHost=${location.host}`)), 83 expectPreserveProp: false, 84 descr: "Props on different-domain new window's same-domain child should go away when loading" 85 }, 86 { 87 func: testId => { 88 win = window.open("about:blank"); 89 win.x = testId; 90 win.location = new URL(`bug346659-echoer.html?${testId}`, document.baseURI); 91 }, 92 expectPreserveProp: false, 93 descr: 'Props should go away when replacing the initial about:blank' 94 }, 95 ]; 96 97 function runTests() { 98 const remainingTests = new Map(); 99 100 window.addEventListener("message", ({ data }) => { 101 if (data.type == 'error') { 102 throw new Error(evt.data.msg); 103 } 104 105 // evt.data has the format 'testNumber - testResult' 106 const testId = parseInt(data); 107 const property = data.substring(3 + Math.floor(Math.log(testId) * Math.LOG10E + 1)); 108 109 const test = remainingTests.get(testId); 110 ok(test, `Test number ${testId} is known and still remaining`); 111 if (test.expectPreserveProp) { 112 is(property, `${testId}`, `${testId}: ${test.descr}`); 113 } else { 114 is(property, 'undefined', `${testId}: ${test.descr}`); 115 } 116 117 remainingTests.delete(testId); 118 if (remainingTests.size == 0) { 119 SimpleTest.finish(); 120 } 121 }); 122 123 let testId = 1; 124 for (const test of tests) { 125 if (!test.func || !test.descr || test.expectPreserveProp == 'undefined') { 126 throw new Error('Invalid test'); 127 } 128 test.func(testId); 129 remainingTests.set(testId, test); 130 ++testId; 131 } 132 } 133 134 // The xorigin tests load http://example.com and from it load http://mochi.test 135 SpecialPowers.pushPrefEnv({"set": [["dom.security.https_first", false]]}, runTests); 136 </script> 137 </pre> 138 </body> 139 </html>