1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug423833.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 1.4 +/* Tests for proper behaviour of "Show this frame" context menu options */ 1.5 + 1.6 +// Two frames, one with text content, the other an error page 1.7 +var invalidPage = 'http://127.0.0.1:55555/'; 1.8 +var validPage = 'http://example.com/'; 1.9 +var testPage = 'data:text/html,<frameset cols="400,400"><frame src="' + validPage + '"><frame src="' + invalidPage + '"></frameset>'; 1.10 + 1.11 +// Store the tab and window created in tests 2 and 3 respectively 1.12 +var test2tab; 1.13 +var test3window; 1.14 + 1.15 +// We use setInterval instead of setTimeout to avoid race conditions on error doc loads 1.16 +var intervalID; 1.17 + 1.18 +function test() { 1.19 + waitForExplicitFinish(); 1.20 + 1.21 + gBrowser.selectedTab = gBrowser.addTab(); 1.22 + gBrowser.selectedBrowser.addEventListener("load", test1Setup, true); 1.23 + content.location = testPage; 1.24 +} 1.25 + 1.26 +function test1Setup() { 1.27 + if (content.frames.length < 2 || 1.28 + content.frames[1].location != invalidPage) 1.29 + // The error frame hasn't loaded yet 1.30 + return; 1.31 + 1.32 + gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true); 1.33 + 1.34 + var badFrame = content.frames[1]; 1.35 + document.popupNode = badFrame.document.firstChild; 1.36 + 1.37 + var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); 1.38 + var contextMenu = new nsContextMenu(contentAreaContextMenu); 1.39 + 1.40 + // We'd like to use another load listener here, but error pages don't fire load events 1.41 + contextMenu.showOnlyThisFrame(); 1.42 + intervalID = setInterval(testShowOnlyThisFrame, 3000); 1.43 +} 1.44 + 1.45 +function testShowOnlyThisFrame() { 1.46 + if (content.location.href == testPage) 1.47 + // This is a stale event from the original page loading 1.48 + return; 1.49 + 1.50 + // We should now have loaded the error page frame content directly 1.51 + // in the tab, make sure the URL is right. 1.52 + clearInterval(intervalID); 1.53 + 1.54 + is(content.location.href, invalidPage, "Should navigate to page url, not about:neterror"); 1.55 + 1.56 + // Go back to the frames page 1.57 + gBrowser.addEventListener("load", test2Setup, true); 1.58 + content.location = testPage; 1.59 +} 1.60 + 1.61 +function test2Setup() { 1.62 + if (content.frames.length < 2 || 1.63 + content.frames[1].location != invalidPage) 1.64 + // The error frame hasn't loaded yet 1.65 + return; 1.66 + 1.67 + gBrowser.removeEventListener("load", test2Setup, true); 1.68 + 1.69 + // Now let's do the whole thing again, but this time for "Open frame in new tab" 1.70 + var badFrame = content.frames[1]; 1.71 + 1.72 + document.popupNode = badFrame.document.firstChild; 1.73 + 1.74 + var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); 1.75 + var contextMenu = new nsContextMenu(contentAreaContextMenu); 1.76 + 1.77 + gBrowser.tabContainer.addEventListener("TabOpen", function (event) { 1.78 + test2tab = event.target; 1.79 + gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false); 1.80 + }, false); 1.81 + contextMenu.openFrameInTab(); 1.82 + ok(test2tab, "openFrameInTab() opened a tab"); 1.83 + 1.84 + gBrowser.selectedTab = test2tab; 1.85 + 1.86 + intervalID = setInterval(testOpenFrameInTab, 3000); 1.87 +} 1.88 + 1.89 +function testOpenFrameInTab() { 1.90 + if (gBrowser.contentDocument.location.href == "about:blank") 1.91 + // Wait another cycle 1.92 + return; 1.93 + 1.94 + clearInterval(intervalID); 1.95 + 1.96 + // We should now have the error page in a new, active tab. 1.97 + is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror"); 1.98 + 1.99 + // Clear up the new tab, and punt to test 3 1.100 + gBrowser.removeCurrentTab(); 1.101 + 1.102 + test3Setup(); 1.103 +} 1.104 + 1.105 +function test3Setup() { 1.106 + // One more time, for "Open frame in new window" 1.107 + var badFrame = content.frames[1]; 1.108 + document.popupNode = badFrame.document.firstChild; 1.109 + 1.110 + var contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); 1.111 + var contextMenu = new nsContextMenu(contentAreaContextMenu); 1.112 + 1.113 + Services.ww.registerNotification(function (aSubject, aTopic, aData) { 1.114 + if (aTopic == "domwindowopened") 1.115 + test3window = aSubject; 1.116 + Services.ww.unregisterNotification(arguments.callee); 1.117 + }); 1.118 + 1.119 + contextMenu.openFrame(); 1.120 + 1.121 + intervalID = setInterval(testOpenFrame, 3000); 1.122 +} 1.123 + 1.124 +function testOpenFrame() { 1.125 + if (!test3window || test3window.content.location.href == "about:blank") { 1.126 + info("testOpenFrame: Wait another cycle"); 1.127 + return; 1.128 + } 1.129 + 1.130 + clearInterval(intervalID); 1.131 + 1.132 + is(test3window.content.location.href, invalidPage, "New window should have page url, not about:neterror"); 1.133 + 1.134 + test3window.close(); 1.135 + cleanup(); 1.136 +} 1.137 + 1.138 +function cleanup() { 1.139 + gBrowser.removeCurrentTab(); 1.140 + finish(); 1.141 +}