43 const kTestPage1 =
"data:text/html,<body%20onbeforeunload='return%20false;'>first</body>";
44 const kTestPage2 =
"data:text/html,<body%20onbeforeunload='return%20false;'>second</body>";
45 let
pb =
Cc[
"@mozilla.org/privatebrowsing;1"]
46 .getService(
Ci.nsIPrivateBrowsingService);
54 let dialogWin = aSubject.QueryInterface(
Ci.nsIDOMWindow);
57 if (this.acceptDialog-- > 0)
58 button = dialogWin.document.documentElement.getButton(
"accept").click();
59 else if (this.rejectDialog-- > 0)
60 button = dialogWin.document.documentElement.getButton(
"cancel").click();
64 Cc[
"@mozilla.org/observer-service;1"]
65 .getService(
Ci.nsIObserverService)
66 .addObserver(promptHelper,
"common-dialog-loaded",
false);
69 let browser1 = gBrowser.getBrowserForTab(gBrowser.addTab());
70 browser1.addEventListener(
"load",
function() {
71 browser1.removeEventListener(
"load",
arguments.callee,
true);
73 let browser2 = gBrowser.getBrowserForTab(gBrowser.addTab());
74 browser2.addEventListener(
"load",
function() {
75 browser2.removeEventListener(
"load",
arguments.callee,
true);
77 promptHelper.rejectDialog = 1;
78 pb.privateBrowsingEnabled =
true;
80 ok(!pb.privateBrowsingEnabled,
"Private browsing mode should not have been activated");
81 is(promptHelper.confirmCalls, 1,
"Only one confirm box should be shown");
82 is(gBrowser.tabContainer.childNodes.length, 3,
83 "No tabs should be closed because private browsing mode transition was canceled");
84 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec,
"about:blank",
85 "The first tab should be a blank tab");
86 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild.nextSibling).currentURI.spec, kTestPage1,
87 "The middle tab should be the same one we opened");
88 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, kTestPage2,
89 "The last tab should be the same one we opened");
90 is(promptHelper.rejectDialog, 0,
"Only one confirm dialog should have been rejected");
92 promptHelper.confirmCalls = 0;
93 promptHelper.acceptDialog = 2;
94 pb.privateBrowsingEnabled =
true;
96 ok(pb.privateBrowsingEnabled,
"Private browsing mode should have been activated");
97 is(promptHelper.confirmCalls, 2,
"Only two confirm boxes should be shown");
98 is(gBrowser.tabContainer.childNodes.length, 1,
99 "Incorrect number of tabs after transition into private browsing");
100 gBrowser.selectedBrowser.addEventListener(
"load",
function() {
101 gBrowser.selectedBrowser.removeEventListener(
"load",
arguments.callee,
true);
103 is(gBrowser.selectedBrowser.currentURI.spec,
"about:privatebrowsing",
104 "Incorrect page displayed after private browsing transition");
105 is(promptHelper.acceptDialog, 0,
"Two confirm dialogs should have been accepted");
107 gBrowser.selectedBrowser.addEventListener(
"load",
function() {
108 gBrowser.selectedBrowser.removeEventListener(
"load",
arguments.callee,
true);
110 gBrowser.selectedTab = gBrowser.addTab();
111 gBrowser.selectedBrowser.addEventListener(
"load",
function() {
112 gBrowser.selectedBrowser.removeEventListener(
"load",
arguments.callee,
true);
114 promptHelper.confirmCalls = 0;
115 promptHelper.rejectDialog = 1;
116 pb.privateBrowsingEnabled =
false;
118 ok(pb.privateBrowsingEnabled,
"Private browsing mode should not have been deactivated");
119 is(promptHelper.confirmCalls, 1,
"Only one confirm box should be shown");
120 is(gBrowser.tabContainer.childNodes.length, 2,
121 "No tabs should be closed because private browsing mode transition was canceled");
122 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec, kTestPage1,
123 "The first tab should be the same one we opened");
124 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, kTestPage2,
125 "The last tab should be the same one we opened");
126 is(promptHelper.rejectDialog, 0,
"Only one confirm dialog should have been rejected");
128 promptHelper.confirmCalls = 0;
129 promptHelper.acceptDialog = 2;
130 pb.privateBrowsingEnabled =
false;
132 ok(!pb.privateBrowsingEnabled,
"Private browsing mode should have been deactivated");
133 is(promptHelper.confirmCalls, 2,
"Only two confirm boxes should be shown");
134 is(gBrowser.tabContainer.childNodes.length, 3,
135 "Incorrect number of tabs after transition into private browsing");
138 function waitForLoad(
event) {
139 gBrowser.removeEventListener(
"load",
arguments.callee,
true);
144 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild).currentURI.spec,
"about:blank",
145 "The first tab should be a blank tab");
146 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.firstChild.nextSibling).currentURI.spec, kTestPage1,
147 "The middle tab should be the same one we opened");
148 is(gBrowser.getBrowserForTab(gBrowser.tabContainer.lastChild).currentURI.spec, kTestPage2,
149 "The last tab should be the same one we opened");
150 is(promptHelper.acceptDialog, 0,
"Two confirm dialogs should have been accepted");
151 is(promptHelper.acceptDialog, 0,
"Two prompts should have been raised");
153 promptHelper.acceptDialog = 2;
154 gBrowser.removeTab(gBrowser.tabContainer.lastChild);
155 gBrowser.removeTab(gBrowser.tabContainer.lastChild);
159 for (let
i = 0;
i < gBrowser.browsers.length; ++
i)
160 gBrowser.browsers[
i].addEventListener(
"load", waitForLoad,
true);
162 gBrowser.selectedBrowser.loadURI(kTestPage2);
164 gBrowser.selectedBrowser.loadURI(kTestPage1);
167 browser2.loadURI(kTestPage2);
169 browser1.loadURI(kTestPage1);
return!aWindow arguments!aWindow arguments[0]
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe