browser/base/content/test/general/browser_bug423833.js

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 /* Tests for proper behaviour of "Show this frame" context menu options */
michael@0 2
michael@0 3 // Two frames, one with text content, the other an error page
michael@0 4 var invalidPage = 'http://127.0.0.1:55555/';
michael@0 5 var validPage = 'http://example.com/';
michael@0 6 var testPage = 'data:text/html,<frameset cols="400,400"><frame src="' + validPage + '"><frame src="' + invalidPage + '"></frameset>';
michael@0 7
michael@0 8 // Store the tab and window created in tests 2 and 3 respectively
michael@0 9 var test2tab;
michael@0 10 var test3window;
michael@0 11
michael@0 12 // We use setInterval instead of setTimeout to avoid race conditions on error doc loads
michael@0 13 var intervalID;
michael@0 14
michael@0 15 function test() {
michael@0 16 waitForExplicitFinish();
michael@0 17
michael@0 18 gBrowser.selectedTab = gBrowser.addTab();
michael@0 19 gBrowser.selectedBrowser.addEventListener("load", test1Setup, true);
michael@0 20 content.location = testPage;
michael@0 21 }
michael@0 22
michael@0 23 function test1Setup() {
michael@0 24 if (content.frames.length < 2 ||
michael@0 25 content.frames[1].location != invalidPage)
michael@0 26 // The error frame hasn't loaded yet
michael@0 27 return;
michael@0 28
michael@0 29 gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true);
michael@0 30
michael@0 31 var badFrame = content.frames[1];
michael@0 32 document.popupNode = badFrame.document.firstChild;
michael@0 33
michael@0 34 var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
michael@0 35 var contextMenu = new nsContextMenu(contentAreaContextMenu);
michael@0 36
michael@0 37 // We'd like to use another load listener here, but error pages don't fire load events
michael@0 38 contextMenu.showOnlyThisFrame();
michael@0 39 intervalID = setInterval(testShowOnlyThisFrame, 3000);
michael@0 40 }
michael@0 41
michael@0 42 function testShowOnlyThisFrame() {
michael@0 43 if (content.location.href == testPage)
michael@0 44 // This is a stale event from the original page loading
michael@0 45 return;
michael@0 46
michael@0 47 // We should now have loaded the error page frame content directly
michael@0 48 // in the tab, make sure the URL is right.
michael@0 49 clearInterval(intervalID);
michael@0 50
michael@0 51 is(content.location.href, invalidPage, "Should navigate to page url, not about:neterror");
michael@0 52
michael@0 53 // Go back to the frames page
michael@0 54 gBrowser.addEventListener("load", test2Setup, true);
michael@0 55 content.location = testPage;
michael@0 56 }
michael@0 57
michael@0 58 function test2Setup() {
michael@0 59 if (content.frames.length < 2 ||
michael@0 60 content.frames[1].location != invalidPage)
michael@0 61 // The error frame hasn't loaded yet
michael@0 62 return;
michael@0 63
michael@0 64 gBrowser.removeEventListener("load", test2Setup, true);
michael@0 65
michael@0 66 // Now let's do the whole thing again, but this time for "Open frame in new tab"
michael@0 67 var badFrame = content.frames[1];
michael@0 68
michael@0 69 document.popupNode = badFrame.document.firstChild;
michael@0 70
michael@0 71 var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
michael@0 72 var contextMenu = new nsContextMenu(contentAreaContextMenu);
michael@0 73
michael@0 74 gBrowser.tabContainer.addEventListener("TabOpen", function (event) {
michael@0 75 test2tab = event.target;
michael@0 76 gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, false);
michael@0 77 }, false);
michael@0 78 contextMenu.openFrameInTab();
michael@0 79 ok(test2tab, "openFrameInTab() opened a tab");
michael@0 80
michael@0 81 gBrowser.selectedTab = test2tab;
michael@0 82
michael@0 83 intervalID = setInterval(testOpenFrameInTab, 3000);
michael@0 84 }
michael@0 85
michael@0 86 function testOpenFrameInTab() {
michael@0 87 if (gBrowser.contentDocument.location.href == "about:blank")
michael@0 88 // Wait another cycle
michael@0 89 return;
michael@0 90
michael@0 91 clearInterval(intervalID);
michael@0 92
michael@0 93 // We should now have the error page in a new, active tab.
michael@0 94 is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror");
michael@0 95
michael@0 96 // Clear up the new tab, and punt to test 3
michael@0 97 gBrowser.removeCurrentTab();
michael@0 98
michael@0 99 test3Setup();
michael@0 100 }
michael@0 101
michael@0 102 function test3Setup() {
michael@0 103 // One more time, for "Open frame in new window"
michael@0 104 var badFrame = content.frames[1];
michael@0 105 document.popupNode = badFrame.document.firstChild;
michael@0 106
michael@0 107 var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
michael@0 108 var contextMenu = new nsContextMenu(contentAreaContextMenu);
michael@0 109
michael@0 110 Services.ww.registerNotification(function (aSubject, aTopic, aData) {
michael@0 111 if (aTopic == "domwindowopened")
michael@0 112 test3window = aSubject;
michael@0 113 Services.ww.unregisterNotification(arguments.callee);
michael@0 114 });
michael@0 115
michael@0 116 contextMenu.openFrame();
michael@0 117
michael@0 118 intervalID = setInterval(testOpenFrame, 3000);
michael@0 119 }
michael@0 120
michael@0 121 function testOpenFrame() {
michael@0 122 if (!test3window || test3window.content.location.href == "about:blank") {
michael@0 123 info("testOpenFrame: Wait another cycle");
michael@0 124 return;
michael@0 125 }
michael@0 126
michael@0 127 clearInterval(intervalID);
michael@0 128
michael@0 129 is(test3window.content.location.href, invalidPage, "New window should have page url, not about:neterror");
michael@0 130
michael@0 131 test3window.close();
michael@0 132 cleanup();
michael@0 133 }
michael@0 134
michael@0 135 function cleanup() {
michael@0 136 gBrowser.removeCurrentTab();
michael@0 137 finish();
michael@0 138 }

mercurial