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