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