Mozilla Bug 387706

\n" +
    "\n" +
    "

" + description + "

\n" + ""; return contents; } /** Finish the test, but don't finish twice if we timed out. */ function finish() { if (!finished) { finished = true; SimpleTest.finish(); } } var xhtmlns = "http://www.w3.org/1999/xhtml"; function insert(el) { var content = $("content"); content.parentNode.insertBefore(el, content); } var LOAD_TIMEOUT = 5000; function setupBlank() { var aboutBlankFrame = document.createElementNS(xhtmlns, "iframe"); aboutBlankFrame.setAttribute("src", "about:blank"); insert(aboutBlankFrame); aboutBlankWindow = aboutBlankFrame.contentWindow; var doc = aboutBlankWindow.document; doc.open(); doc.write(getContents("This was about:blank #1", "about:blank-response")); doc.close(); // I don't believe anything guarantees sync parsing, so we have to wait for // the new window to poke us to actually do the test. :-\ // Catch recalcitrant browsers that fail inside the iframe document code. setTimeout(blankFailed, LOAD_TIMEOUT); } function blankFailed() { if (!aboutBlankResponseReceived && !finished) { ok(false, "test timed out (postMessage not accessible on window.parent in " + "the first about:blank iframe?)"); finish(); } } function setupBlank2() { var aboutBlank2Frame = document.createElementNS(xhtmlns, "iframe"); aboutBlank2Frame.addEventListener("load", nextTest, false); aboutBlank2Frame.setAttribute("src", "about:blank"); insert(aboutBlank2Frame); } // Could use window.btoa here, but that's not standardized, and we want to be // able to run these tests against browsers that don't support it. var dataURI = "data:text/html;base64," + b64(getContents("A data: URL", "data-response")); function setupData() { var dataFrame = document.createElementNS(xhtmlns, "iframe"); dataFrame.setAttribute("src", dataURI); insert(dataFrame); dataWindow = dataFrame.contentWindow; // ...and wait again for the window to load... // Catch recalcitrant browsers that fail inside the iframe document code. setTimeout(dataFailed, LOAD_TIMEOUT); } function dataFailed() { if (!dataResponseReceived && !finished) { ok(false, "test timed out (postMessage not accessible on window.parent in " + "the data: iframe?)"); finish(); } } var count = 0; function nextTest() { switch (count++) { case 0: testBlank(); break; case 1: testBlank2(); break; case 2: testData(); break; default: ok(false, "unreached"); break; } } function testBlank() { aboutBlankWindow.postMessage("from-opener", "http://localhost:8888"); } function testBlank2() { // For some reason we can't access this across browsers prior to the iframe // loading, so set its value here. aboutBlank2Window = window.frames[1]; var doc = aboutBlank2Window.document; doc.body.textContent = "This was about:blank #2"; var script = doc.createElement("script"); script.textContent = "window.parent.postMessage('about:blank2-response', " + " 'http://localhost:8888');"; doc.body.appendChild(script); } function testData() { dataWindow.postMessage("from-opener", "http://localhost:8888"); } window.addEventListener("message", messageReceiver, false); addLoadEvent(setupBlank); ]]>