michael@0: /* Tests for proper behaviour of "Show this frame" context menu options */ michael@0: michael@0: // Two frames, one with text content, the other an error page michael@0: var invalidPage = 'http://127.0.0.1:55555/'; michael@0: var validPage = 'http://example.com/'; michael@0: var testPage = 'data:text/html,'; michael@0: michael@0: // Store the tab and window created in tests 2 and 3 respectively michael@0: var test2tab; michael@0: var test3window; michael@0: michael@0: // We use setInterval instead of setTimeout to avoid race conditions on error doc loads michael@0: var intervalID; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.selectedBrowser.addEventListener("load", test1Setup, true); michael@0: content.location = testPage; michael@0: } michael@0: michael@0: function test1Setup() { michael@0: if (content.frames.length < 2 || michael@0: content.frames[1].location != invalidPage) michael@0: // The error frame hasn't loaded yet michael@0: return; michael@0: michael@0: gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true); michael@0: michael@0: var badFrame = content.frames[1]; michael@0: document.popupNode = badFrame.document.firstChild; michael@0: michael@0: var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); michael@0: var contextMenu = new nsContextMenu(contentAreaContextMenu); michael@0: michael@0: // We'd like to use another load listener here, but error pages don't fire load events michael@0: contextMenu.showOnlyThisFrame(); michael@0: intervalID = setInterval(testShowOnlyThisFrame, 3000); michael@0: } michael@0: michael@0: function testShowOnlyThisFrame() { michael@0: if (content.location.href == testPage) michael@0: // This is a stale event from the original page loading michael@0: return; michael@0: michael@0: // We should now have loaded the error page frame content directly michael@0: // in the tab, make sure the URL is right. michael@0: clearInterval(intervalID); michael@0: michael@0: is(content.location.href, invalidPage, "Should navigate to page url, not about:neterror"); michael@0: michael@0: // Go back to the frames page michael@0: gBrowser.addEventListener("load", test2Setup, true); michael@0: content.location = testPage; michael@0: } michael@0: michael@0: function test2Setup() { michael@0: if (content.frames.length < 2 || michael@0: content.frames[1].location != invalidPage) michael@0: // The error frame hasn't loaded yet michael@0: return; michael@0: michael@0: gBrowser.removeEventListener("load", test2Setup, true); michael@0: michael@0: // Now let's do the whole thing again, but this time for "Open frame in new tab" michael@0: var badFrame = content.frames[1]; michael@0: michael@0: document.popupNode = badFrame.document.firstChild; michael@0: michael@0: var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); michael@0: var contextMenu = new nsContextMenu(contentAreaContextMenu); michael@0: michael@0: gBrowser.tabContainer.addEventListener("TabOpen", function (event) { michael@0: test2tab = event.target; michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false); michael@0: }, false); michael@0: contextMenu.openFrameInTab(); michael@0: ok(test2tab, "openFrameInTab() opened a tab"); michael@0: michael@0: gBrowser.selectedTab = test2tab; michael@0: michael@0: intervalID = setInterval(testOpenFrameInTab, 3000); michael@0: } michael@0: michael@0: function testOpenFrameInTab() { michael@0: if (gBrowser.contentDocument.location.href == "about:blank") michael@0: // Wait another cycle michael@0: return; michael@0: michael@0: clearInterval(intervalID); michael@0: michael@0: // We should now have the error page in a new, active tab. michael@0: is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror"); michael@0: michael@0: // Clear up the new tab, and punt to test 3 michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: test3Setup(); michael@0: } michael@0: michael@0: function test3Setup() { michael@0: // One more time, for "Open frame in new window" michael@0: var badFrame = content.frames[1]; michael@0: document.popupNode = badFrame.document.firstChild; michael@0: michael@0: var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); michael@0: var contextMenu = new nsContextMenu(contentAreaContextMenu); michael@0: michael@0: Services.ww.registerNotification(function (aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowopened") michael@0: test3window = aSubject; michael@0: Services.ww.unregisterNotification(arguments.callee); michael@0: }); michael@0: michael@0: contextMenu.openFrame(); michael@0: michael@0: intervalID = setInterval(testOpenFrame, 3000); michael@0: } michael@0: michael@0: function testOpenFrame() { michael@0: if (!test3window || test3window.content.location.href == "about:blank") { michael@0: info("testOpenFrame: Wait another cycle"); michael@0: return; michael@0: } michael@0: michael@0: clearInterval(intervalID); michael@0: michael@0: is(test3window.content.location.href, invalidPage, "New window should have page url, not about:neterror"); michael@0: michael@0: test3window.close(); michael@0: cleanup(); michael@0: } michael@0: michael@0: function cleanup() { michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }