dom/tests/mochitest/bugs/test_bug346659.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=346659
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 346659</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 10 </head>
michael@0 11 <body>
michael@0 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=346659">Mozilla Bug 346659</a>
michael@0 13 <p id="display"></p>
michael@0 14 <div id="content" style="display: none">
michael@0 15
michael@0 16 </div>
michael@0 17 <pre id="test">
michael@0 18 <script type="application/javascript">
michael@0 19
michael@0 20 /** Test for Bug 346659 **/
michael@0 21 // do the tests in two batches, because otherwise the popup blocker kills off
michael@0 22 // our test because it opens too many windows.
michael@0 23 var numTestsSet1 = 6;
michael@0 24 var numTestsSet2 = 4;
michael@0 25 var numTestsSet3 = 2;
michael@0 26 var complete = 0;
michael@0 27 SimpleTest.waitForExplicitFinish();
michael@0 28
michael@0 29 var wins = [];
michael@0 30
michael@0 31 function r(base, tail) {
michael@0 32 return base.replace(/\/[^\/]*$/, "/" + tail);
michael@0 33 }
michael@0 34
michael@0 35 function handleCmd(evt) {
michael@0 36 var cmd;
michael@0 37 try {
michael@0 38 cmd = JSON.parse(evt.data);
michael@0 39 } catch (e) {
michael@0 40 // Not json
michael@0 41 return false;
michael@0 42 }
michael@0 43
michael@0 44 // Grab privileges so we can access cross-domain windows
michael@0 45 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
michael@0 46
michael@0 47 if ("load" in cmd) {
michael@0 48 var testNum = cmd.load;
michael@0 49 var win = wins[testNum];
michael@0 50 win.childWin.x = testNum;
michael@0 51 if (win.childWin.opener == win) {
michael@0 52 if ("xsite" in cmd) {
michael@0 53 var loc = r(window.location.href, "bug346659-opener-echoer.html");
michael@0 54 } else {
michael@0 55 var loc = r(win.location.href, "bug346659-opener-echoer.html");
michael@0 56 }
michael@0 57 } else {
michael@0 58 if ("xsite" in cmd) {
michael@0 59 var loc = r(window.location.href, "bug346659-parent-echoer.html");
michael@0 60 } else {
michael@0 61 var loc = r(win.location.href, "bug346659-parent-echoer.html");
michael@0 62 }
michael@0 63 }
michael@0 64 win.childWin.location.href = loc;
michael@0 65 wins[testNum] = null;
michael@0 66 } else if ("write" in cmd) {
michael@0 67 var testNum = cmd.write;
michael@0 68 var win = wins[testNum];
michael@0 69 win.childWin.x = testNum;
michael@0 70 try {
michael@0 71 if (win.childWin.opener == win) {
michael@0 72 win.childWin.document.write('<script>window.opener.opener.postMessage(window.opener.testNum + " - " + window.x, "http://mochi.test:8888/"); window.opener.close(); window.close();<' + '/script>');
michael@0 73 } else {
michael@0 74 win.childWin.document.write('<script>window.parent.opener.postMessage(window.parent.testNum + " - " + window.x, "http://mochi.test:8888/"); window.parent.close();<' + '/script>');
michael@0 75 }
michael@0 76 } catch (e if (e.name == "SecurityError" && e.code == 18)) {
michael@0 77 // Security error on cross-site write() is fine
michael@0 78 if (win.childWin.opener == win) {
michael@0 79 win.childWin.close();
michael@0 80 }
michael@0 81 win.close()
michael@0 82 handleTestEnd();
michael@0 83 }
michael@0 84 wins[testNum] = null;
michael@0 85 }
michael@0 86 return true;
michael@0 87 }
michael@0 88
michael@0 89 function messageReceiver(evt) {
michael@0 90 // First try to detect a load/write command
michael@0 91 if (handleCmd(evt)) {
michael@0 92 return;
michael@0 93 }
michael@0 94
michael@0 95 var testNumber = parseInt(evt.data);
michael@0 96 var testResult = evt.data.substring(3 + Math.floor(Math.log(testNumber) * Math.LOG10E + 1));
michael@0 97
michael@0 98 switch (testNumber) {
michael@0 99 case 1:
michael@0 100 is(testResult, 1, "Props on new window should be preserved when loading");
michael@0 101 break;
michael@0 102 case 2:
michael@0 103 is(testResult, 2, "Props on new window should be preserved when writing");
michael@0 104 break;
michael@0 105 case 3:
michael@0 106 is(testResult, 3, "Props on window opened from new window should be preserved when loading");
michael@0 107 break;
michael@0 108 case 4:
michael@0 109 is(testResult, 4, "Props on window opened from new window should be preserved when writing");
michael@0 110 break;
michael@0 111 case 5:
michael@0 112 is(testResult, "undefined", "Props on new window's child should go away when loading");
michael@0 113 break;
michael@0 114 case 6:
michael@0 115 is(testResult, "undefined", "Props on new window's child should go away when writing");
michael@0 116 break;
michael@0 117 case 7:
michael@0 118 is(testResult, 7, "Props on different-domain window opened from different-domain new window can stay");
michael@0 119 break;
michael@0 120 case 9:
michael@0 121 is(testResult, "undefined", "Props on different-domain new window's child should go away when loading");
michael@0 122 break;
michael@0 123 case 11:
michael@0 124 is(testResult, "undefined", "Props on same-domain window opened from different-domain new window should go away when loading");
michael@0 125 break;
michael@0 126 case 12:
michael@0 127 is(testResult, "undefined", "Props on different-domain new window's same-domain child should go away when loading");
michael@0 128 break;
michael@0 129 default:
michael@0 130 ok(0, "unexpected test number (" + testNumber + ") when data is " + evt.data);
michael@0 131 }
michael@0 132
michael@0 133 handleTestEnd();
michael@0 134 }
michael@0 135
michael@0 136 function handleTestEnd() {
michael@0 137 function gc() {
michael@0 138 SpecialPowers.DOMWindowUtils.garbageCollect();
michael@0 139 }
michael@0 140 if (numTestsSet1) {
michael@0 141 if (!--numTestsSet1) {
michael@0 142 // gc to get rid of all the old windows
michael@0 143 gc(); gc(); gc();
michael@0 144 setTimeout(startSecondBatch, 0);
michael@0 145 }
michael@0 146 } else if (numTestsSet2) {
michael@0 147 if (!--numTestsSet2) {
michael@0 148 // gc to get rid of all the old windows
michael@0 149 gc(); gc(); gc();
michael@0 150 setTimeout(startThirdBatch, 0);
michael@0 151 }
michael@0 152 } else if (!--numTestsSet3) {
michael@0 153 SimpleTest.finish();
michael@0 154 }
michael@0 155 }
michael@0 156 window.addEventListener("message", messageReceiver, false);
michael@0 157
michael@0 158 var win = window.open("");
michael@0 159 win.x = 1;
michael@0 160 win.location.href = "bug346659-echoer.html";
michael@0 161
michael@0 162 win = window.open("");
michael@0 163 win.x = 2;
michael@0 164 win.document.write('<script> window.opener.postMessage("2 - " + window.x, window.location.href); window.close(); </' + 'script>');
michael@0 165
michael@0 166 wins[3] = window.open('bug346659-opener.html?{"load":3}');
michael@0 167 wins[4] = window.open('bug346659-opener.html?{"write":4}');
michael@0 168 wins[5] = window.open('bug346659-parent.html?{"load":5}');
michael@0 169 wins[6] = window.open('bug346659-parent.html?{"write":6}');
michael@0 170
michael@0 171 is(location.host, "mochi.test:8888", "Unexpected host");
michael@0 172
michael@0 173 function startSecondBatch() {
michael@0 174 var baseurl = window.location.href.replace(/mochi\.test:8888/, "example.com");
michael@0 175 wins[7] = window.open(r(baseurl, 'bug346659-opener.html?{"load":7}'));
michael@0 176 wins[8] = window.open(r(baseurl, 'bug346659-opener.html?{"write":8}'));
michael@0 177 wins[9] = window.open(r(baseurl, 'bug346659-parent.html?{"load":9}'));
michael@0 178 wins[10] = window.open(r(baseurl, 'bug346659-parent.html?{"write":10}'));
michael@0 179 }
michael@0 180
michael@0 181 function startThirdBatch() {
michael@0 182 var baseurl = window.location.href.replace(/mochi\.test:8888/, "example.com");
michael@0 183 wins[11] = window.open(r(baseurl, 'bug346659-opener.html?{"load":11,"xsite":true}'));
michael@0 184 wins[12] = window.open(r(baseurl, 'bug346659-parent.html?{"load":12,"xsite":true}'));
michael@0 185 }
michael@0 186 </script>
michael@0 187 </pre>
michael@0 188 </body>
michael@0 189 </html>

mercurial