browser_alltabslistener.js
Go to the documentation of this file.
1 const Ci = Components.interfaces;
2 
3 const gCompleteState = Ci.nsIWebProgressListener.STATE_STOP +
4  Ci.nsIWebProgressListener.STATE_IS_NETWORK;
5 
7  onProgressChange: function (aWebProgress, aRequest,
8  aCurSelfProgress, aMaxSelfProgress,
9  aCurTotalProgress, aMaxTotalProgress) {
10  },
11 
12  onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) {
13  var state = "onStateChange";
14  info("FrontProgress: " + state + " 0x" + aStateFlags.toString(16));
15  ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
16  is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
17  gFrontNotificationsPos++;
18  },
19 
20  onLocationChange: function (aWebProgress, aRequest, aLocationURI) {
21  var state = "onLocationChange";
22  info("FrontProgress: " + state + " " + aLocationURI.spec);
23  ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
24  is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
25  gFrontNotificationsPos++;
26  },
27 
28  onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage) {
29  },
30 
31  onSecurityChange: function (aWebProgress, aRequest, aState) {
32  var state = "onSecurityChange";
33  info("FrontProgress: " + state + " 0x" + aState.toString(16));
34  ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
35  is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
36  gFrontNotificationsPos++;
37  }
38 }
39 
40 var gAllProgressListener = {
41  onProgressChange: function (aBrowser, aWebProgress, aRequest,
42  aCurSelfProgress, aMaxSelfProgress,
43  aCurTotalProgress, aMaxTotalProgress) {
44  },
45 
46  onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
47  var state = "onStateChange";
48  info("AllProgress: " + state + " 0x" + aStateFlags.toString(16));
49  ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
50  ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
51  is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
53 
54  if ((aStateFlags & gCompleteState) == gCompleteState) {
55  ok(gAllNotificationsPos == gAllNotifications.length, "Saw the expected number of notifications");
56  ok(gFrontNotificationsPos == gFrontNotifications.length, "Saw the expected number of frontnotifications");
57  executeSoon(gNextTest);
58  }
59  },
60 
61  onLocationChange: function (aBrowser, aWebProgress, aRequest, aLocationURI) {
62  var state = "onLocationChange";
63  info("AllProgress: " + state + " " + aLocationURI.spec);
64  ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
65  ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
66  is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
68  },
69 
70  onStatusChange: function (aBrowser, aWebProgress, aRequest, aStatus, aMessage) {
71  var state = "onStatusChange";
72  ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
73  },
74 
75  onSecurityChange: function (aBrowser, aWebProgress, aRequest, aState) {
76  var state = "onSecurityChange";
77  info("AllProgress: " + state + " 0x" + aState.toString(16));
78  ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
79  ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
80  is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
82  }
83 }
84 
87 var gTestPage = "/browser/browser/base/content/test/alltabslistener.html";
89 
90 function test() {
92 
93  gBackgroundTab = gBrowser.addTab("about:blank");
94  gForegroundTab = gBrowser.addTab("about:blank");
95  gBackgroundBrowser = gBrowser.getBrowserForTab(gBackgroundTab);
96  gForegroundBrowser = gBrowser.getBrowserForTab(gForegroundTab);
97  gBrowser.selectedTab = gForegroundTab;
98 
99  // We must wait until the about:blank page has completed loading before
100  // starting tests or we get notifications from that
101  gForegroundBrowser.addEventListener("load", startTests, true);
102 }
103 
104 function runTest(browser, url, next) {
105  gFrontNotificationsPos = 0;
106  gAllNotificationsPos = 0;
107  gNextTest = next;
108  gTestBrowser = browser;
109  browser.loadURI(url);
110 }
111 
112 function startTests() {
113  gForegroundBrowser.removeEventListener("load", startTests, true);
114  executeSoon(startTest1);
115 }
116 
117 function startTest1() {
118  info("\nTest 1");
119  gBrowser.addProgressListener(gFrontProgressListener);
120  gBrowser.addTabsProgressListener(gAllProgressListener);
121 
122  gAllNotifications = [
123  "onStateChange",
124  "onLocationChange",
125  "onSecurityChange",
126  "onStateChange"
127  ];
128  gFrontNotifications = gAllNotifications;
129  runTest(gForegroundBrowser, "http://example.org" + gTestPage, startTest2);
130 }
131 
132 function startTest2() {
133  info("\nTest 2");
134  gAllNotifications = [
135  "onStateChange",
136  "onLocationChange",
137  "onSecurityChange",
138  "onSecurityChange",
139  "onStateChange"
140  ];
141  gFrontNotifications = gAllNotifications;
142  runTest(gForegroundBrowser, "https://example.com" + gTestPage, startTest3);
143 }
144 
145 function startTest3() {
146  info("\nTest 3");
147  gAllNotifications = [
148  "onStateChange",
149  "onLocationChange",
150  "onSecurityChange",
151  "onStateChange"
152  ];
153  gFrontNotifications = [];
154  runTest(gBackgroundBrowser, "http://example.org" + gTestPage, startTest4);
155 }
156 
157 function startTest4() {
158  info("\nTest 4");
159  gAllNotifications = [
160  "onStateChange",
161  "onLocationChange",
162  "onSecurityChange",
163  "onSecurityChange",
164  "onStateChange"
165  ];
166  gFrontNotifications = [];
167  runTest(gBackgroundBrowser, "https://example.com" + gTestPage, startTest5);
168 }
169 
170 function startTest5() {
171  info("\nTest 5");
172  // Switch the foreground browser
175  // Avoid the onLocationChange this will fire
176  gBrowser.removeProgressListener(gFrontProgressListener);
177  gBrowser.selectedTab = gForegroundTab;
178  gBrowser.addProgressListener(gFrontProgressListener);
179 
180  gAllNotifications = [
181  "onStateChange",
182  "onLocationChange",
183  "onSecurityChange",
184  "onStateChange"
185  ];
186  gFrontNotifications = gAllNotifications;
187  runTest(gForegroundBrowser, "http://example.org" + gTestPage, startTest6);
188 }
189 
190 function startTest6() {
191  info("\nTest 6");
192  gAllNotifications = [
193  "onStateChange",
194  "onLocationChange",
195  "onSecurityChange",
196  "onStateChange"
197  ];
198  gFrontNotifications = [];
199  runTest(gBackgroundBrowser, "http://example.org" + gTestPage, finishTest);
200 }
201 
202 function finishTest() {
203  gBrowser.removeProgressListener(gFrontProgressListener);
204  gBrowser.removeTabsProgressListener(gAllProgressListener);
205  gBrowser.removeTab(gBackgroundTab);
206  gBrowser.removeTab(gForegroundTab);
207  finish();
208 }
function startTest2()
const Ci
var gAllNotificationsPos
function finishTest()
const gCompleteState
var gAllNotifications
var gBackgroundBrowser
var gTestBrowser
var gBackgroundTab
function runTest(browser, url, next)
function startTest1()
function startTest6()
var gFrontProgressListener
function startTest3()
waitForExplicitFinish()
function url(spec)
_updateTextAndScrollDataForTab aBrowser
function startTests()
function startTest4()
var gForegroundBrowser
ContinuingWebProgressListener prototype onStateChange
var gFrontNotificationsPos
function test()
var browser
Definition: openLocation.js:42
restoreWindow aState
var gForegroundTab
function next()
function startTest5()