browser_privatebrowsing_zoomrestore.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Private Browsing Tests.
15  *
16  * The Initial Developer of the Original Code is
17  * Ehsan Akhgari.
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either of the GNU General Public License Version 2 or later (the "GPL"),
26  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 // This test makes sure that about:privatebrowsing does not appear zoomed in
39 // if there is already a zoom site pref for about:blank (bug 487656).
40 
41 function test() {
42  // initialization
43  let pb = Cc["@mozilla.org/privatebrowsing;1"].
44  getService(Ci.nsIPrivateBrowsingService);
45  let cps = Cc["@mozilla.org/content-pref/service;1"].
46  getService(Ci.nsIContentPrefService);
48 
49  let tabBlank = gBrowser.selectedTab;
50  gBrowser.removeAllTabsBut(tabBlank);
51 
52  let blankBrowser = gBrowser.getBrowserForTab(tabBlank);
53  blankBrowser.addEventListener("load", function() {
54  blankBrowser.removeEventListener("load", arguments.callee, true);
55 
56  // change the zoom on the blank page
57  FullZoom.enlarge();
58  isnot(ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
59 
60  // enter private browsing mode
61  pb.privateBrowsingEnabled = true;
62  let tabAboutPB = gBrowser.selectedTab;
63  let browserAboutPB = gBrowser.getBrowserForTab(tabAboutPB);
64  browserAboutPB.addEventListener("load", function() {
65  browserAboutPB.removeEventListener("load", arguments.callee, true);
66  setTimeout(function() {
67  // make sure the zoom level is set to 1
68  is(ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
69 
70  // Mac OS X does not support print preview, so skip those tests
71  let isOSX = ("nsILocalFileMac" in Components.interfaces);
72  if (isOSX) {
73  finishTest();
74  return;
75  }
76 
77  // test print preview on HTML document
78  testPrintPreview(browserAboutPB, function() {
79  browserAboutPB.addEventListener("load", function() {
80  browserAboutPB.removeEventListener("load", arguments.callee, true);
81 
82  // test print preview on image document
83  testPrintPreview(browserAboutPB, finishTest);
84  }, true);
85  browserAboutPB.loadURI("about:logo");
86  });
87  }, 0);
88  }, true);
89  }, true);
90  blankBrowser.loadURI("about:blank");
91 }
92 
93 function finishTest() {
94  let pb = Cc["@mozilla.org/privatebrowsing;1"].
95  getService(Ci.nsIPrivateBrowsingService);
96  // leave private browsing mode
97  pb.privateBrowsingEnabled = false;
98  let tabBlank = gBrowser.selectedTab;
99  let blankBrowser = gBrowser.getBrowserForTab(tabBlank);
100  blankBrowser.addEventListener("load", function() {
101  blankBrowser.removeEventListener("load", arguments.callee, true);
102 
103  executeSoon(function() {
104  // cleanup
105  FullZoom.reset();
106  finish();
107  });
108  }, true);
109 }
110 
111 function testPrintPreview(aBrowser, aCallback) {
112  FullZoom.enlarge();
113  let level = ZoomManager.getZoomForBrowser(aBrowser);
114 
115  function onEnterPP(aHide) {
116  toggleAffectedChromeOrig(aHide);
117 
118  function onExitPP(aHide) {
119  toggleAffectedChromeOrig(aHide);
120  toggleAffectedChrome = toggleAffectedChromeOrig;
121 
122  is(ZoomManager.getZoomForBrowser(aBrowser), level,
123  "Toggling print preview mode should not affect zoom level");
124 
125  FullZoom.reset();
126  aCallback();
127  }
128  toggleAffectedChrome = onExitPP;
129  PrintUtils.exitPrintPreview();
130  }
131  let toggleAffectedChromeOrig = toggleAffectedChrome;
132  toggleAffectedChrome = onEnterPP;
133 
134  let printPreview = new Function(document.getElementById("cmd_printPreview")
135  .getAttribute("oncommand"));
136  executeSoon(printPreview);
137 }
const Cc
var FullZoom
getService(Ci.sbIFaceplateManager)
waitForExplicitFinish()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
return!aWindow arguments!aWindow arguments[0]
_updateTextAndScrollDataForTab aBrowser
const Ci
function testPrintPreview(aBrowser, aCallback)
function toggleAffectedChrome(aHide)
Definition: browser.js:2560