|
1 var gPageA = null; |
|
2 var gPageB = null; |
|
3 |
|
4 // cached data from events |
|
5 var gTabOpenPageA = null; |
|
6 var gTabOpenPageB = null; |
|
7 var gTabOpenCount = 0; |
|
8 var gTabCloseCount = 0; |
|
9 var gTabMoveCount = 0; |
|
10 var gPageLoadCount = 0; |
|
11 |
|
12 var rootDir = getRootDirectory(gTestPath); |
|
13 const CHROMEROOT = rootDir; |
|
14 |
|
15 function test() { |
|
16 waitForExplicitFinish(); |
|
17 |
|
18 var windows = Application.windows; |
|
19 ok(windows, "Check access to browser windows"); |
|
20 is(windows.length, 1, "There should be one browser window open"); |
|
21 |
|
22 var activeWin = Application.activeWindow; |
|
23 activeWin.events.addListener("TabOpen", onTabOpen); |
|
24 activeWin.events.addListener("TabClose", onTabClose); |
|
25 activeWin.events.addListener("TabMove", onTabMove); |
|
26 |
|
27 gPageA = activeWin.open(makeURI(CHROMEROOT + "ContentA.html")); |
|
28 gPageA.events.addListener("load", onPageAFirstLoad); |
|
29 |
|
30 is(activeWin.tabs.length, 2, "Checking length of 'Browser.tabs' after opening 1 additional tab"); |
|
31 |
|
32 function onPageAFirstLoad(event) { |
|
33 gPageA.events.removeListener("load", onPageAFirstLoad); |
|
34 is(gPageA.uri.spec, event.data.uri.spec, "Checking event browser tab is equal to page A"); |
|
35 |
|
36 gPageB = activeWin.open(makeURI(CHROMEROOT + "ContentB.html")); |
|
37 gPageB.events.addListener("load", delayAfterOpen); |
|
38 gPageB.focus(); |
|
39 |
|
40 is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening a second additional tab"); |
|
41 is(activeWin.activeTab.index, gPageB.index, "Checking 'Browser.activeTab' after setting focus"); |
|
42 } |
|
43 |
|
44 function delayAfterOpen() { |
|
45 executeSoon(afterOpen); |
|
46 } |
|
47 |
|
48 // need to wait for the url's to be refreshed during the load |
|
49 function afterOpen(event) { |
|
50 gPageB.events.removeListener("load", delayAfterOpen); |
|
51 // check actuals |
|
52 is(gPageA.uri.spec, CHROMEROOT + "ContentA.html", "Checking 'BrowserTab.uri' after opening"); |
|
53 is(gPageB.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after opening"); |
|
54 |
|
55 // check event |
|
56 is(gTabOpenCount, 2, "Checking event handler for tab open"); |
|
57 // check cached values from TabOpen event |
|
58 is(gPageA.uri.spec, gTabOpenPageA.uri.spec, "Checking first browser tab open is equal to page A"); |
|
59 is(gPageB.uri.spec, gTabOpenPageB.uri.spec, "Checking second browser tab open is equal to page B"); |
|
60 |
|
61 // test document access |
|
62 var test1 = gPageA.document.getElementById("test1"); |
|
63 ok(test1, "Checking existence of element in content DOM"); |
|
64 is(test1.innerHTML, "A", "Checking content of element in content DOM"); |
|
65 |
|
66 // test moving tab |
|
67 is(gTabMoveCount, 0, "Checking initial tab move count"); |
|
68 |
|
69 // move the tab |
|
70 gPageA.moveToEnd(); |
|
71 is(gPageA.index, 2, "Checking index after moving tab"); |
|
72 |
|
73 // check event |
|
74 is(gTabMoveCount, 1, "Checking event handler for tab move"); |
|
75 |
|
76 gBrowser.addProgressListener({ |
|
77 onStateChange: function (webProgress, request, stateFlags, status) { |
|
78 info("onStateChange: " + stateFlags); |
|
79 |
|
80 const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW + |
|
81 Ci.nsIWebProgressListener.STATE_IS_NETWORK + |
|
82 Ci.nsIWebProgressListener.STATE_STOP; |
|
83 if ((stateFlags & complete) == complete) { |
|
84 gBrowser.removeProgressListener(this); |
|
85 onPageBLoadComplete(); |
|
86 } |
|
87 }, |
|
88 onLocationChange: function () 0, |
|
89 onProgressChange: function () 0, |
|
90 onStatusChange: function () 0, |
|
91 onSecurityChange: function () 0 |
|
92 }); |
|
93 |
|
94 // test loading new content with a frame into a tab |
|
95 // the event will be checked in onPageBLoadComplete |
|
96 gPageB.events.addListener("load", onPageBLoadWithFrames); |
|
97 gPageB.load(makeURI(CHROMEROOT + "ContentWithFrames.html")); |
|
98 } |
|
99 |
|
100 function onPageBLoadWithFrames(event) { |
|
101 gPageLoadCount++; |
|
102 info("onPageBLoadWithFrames: " + gPageLoadCount); |
|
103 } |
|
104 |
|
105 function onPageBLoadComplete() { |
|
106 gPageB.events.removeListener("load", onPageBLoadWithFrames); |
|
107 // check page load with frame event |
|
108 is(gPageLoadCount, 1, "Checking load count after loading new content with a frame"); |
|
109 |
|
110 // test loading new content into a tab |
|
111 // the event will be checked in onPageASecondLoad |
|
112 gPageA.events.addListener("load", onPageASecondLoad); |
|
113 gPageA.load(makeURI(CHROMEROOT + "ContentB.html")); |
|
114 } |
|
115 |
|
116 function onPageASecondLoad(event) { |
|
117 gPageA.events.removeListener("load", onPageASecondLoad); |
|
118 is(gPageA.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after loading new content"); |
|
119 |
|
120 // start testing closing tabs |
|
121 // the event will be checked in afterClose |
|
122 // use executeSoon so the onPageASecondLoad |
|
123 // has a chance to finish first |
|
124 gPageA.close(); |
|
125 gPageB.close(); |
|
126 |
|
127 is(gTabCloseCount, 2, "Checking that tabs closed"); |
|
128 is(activeWin.tabs.length, 1, "Checking length of 'Browser.tabs' after closing 2 tabs"); |
|
129 finish(); |
|
130 } |
|
131 } |
|
132 function onTabOpen(event) { |
|
133 gTabOpenCount++; |
|
134 |
|
135 // cache these values so we can check them later (after loading completes) |
|
136 if (gTabOpenCount == 1) |
|
137 gTabOpenPageA = event.data; |
|
138 |
|
139 if (gTabOpenCount == 2) |
|
140 gTabOpenPageB = event.data; |
|
141 } |
|
142 function onTabClose(event) { |
|
143 gTabCloseCount++; |
|
144 } |
|
145 |
|
146 function onTabMove(event) { |
|
147 gTabMoveCount++; |
|
148 } |