Bug 487656 - zoomed in by default while entering Private Browsing; r=dao,mconnor
This commit is contained in:
@@ -266,8 +266,19 @@ var FullZoom = {
|
||||
|
||||
// location change observer
|
||||
|
||||
onLocationChange: function FullZoom_onLocationChange(aURI, aBrowser) {
|
||||
if (!aURI)
|
||||
/**
|
||||
* Called when the location of a tab changes.
|
||||
* When that happens, we need to update the current zoom level if appropriate.
|
||||
*
|
||||
* @param aURI
|
||||
* A URI object representing the new location.
|
||||
* @param aIsTabSwitch
|
||||
* Whether this location change has happened because of a tab switch.
|
||||
* @param aBrowser
|
||||
* (optional) browser object displaying the document
|
||||
*/
|
||||
onLocationChange: function FullZoom_onLocationChange(aURI, aIsTabSwitch, aBrowser) {
|
||||
if (!aURI || (aIsTabSwitch && !this.siteSpecific))
|
||||
return;
|
||||
this._applyPrefToSetting(this._cps.getPref(aURI, this.name), aBrowser);
|
||||
},
|
||||
@@ -302,11 +313,6 @@ var FullZoom = {
|
||||
this._removePref();
|
||||
},
|
||||
|
||||
setSettingValue: function FullZoom_setSettingValue() {
|
||||
var value = this._cps.getPref(gBrowser.currentURI, this.name);
|
||||
this._applyPrefToSetting(value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the zoom level for the current tab.
|
||||
*
|
||||
@@ -329,12 +335,13 @@ var FullZoom = {
|
||||
_applyPrefToSetting: function FullZoom__applyPrefToSetting(aValue, aBrowser) {
|
||||
var browser = aBrowser || gBrowser.selectedBrowser;
|
||||
|
||||
if (!this.siteSpecific || gInPrintPreviewMode ||
|
||||
browser.contentDocument instanceof Ci.nsIImageDocument)
|
||||
return;
|
||||
var resetZoom = (!this.siteSpecific || gInPrintPreviewMode ||
|
||||
browser.contentDocument instanceof Ci.nsIImageDocument);
|
||||
|
||||
try {
|
||||
if (typeof aValue != "undefined")
|
||||
if (resetZoom)
|
||||
ZoomManager.setZoomForBrowser(browser, 1);
|
||||
else if (typeof aValue != "undefined")
|
||||
ZoomManager.setZoomForBrowser(browser, this._ensureValid(aValue));
|
||||
else if (typeof this.globalValue != "undefined")
|
||||
ZoomManager.setZoomForBrowser(browser, this.globalValue);
|
||||
|
||||
@@ -2558,7 +2558,6 @@ function onExitPrintPreview()
|
||||
{
|
||||
// restore chrome to original state
|
||||
gInPrintPreviewMode = false;
|
||||
FullZoom.setSettingValue();
|
||||
toggleAffectedChrome(false);
|
||||
}
|
||||
|
||||
@@ -4229,7 +4228,7 @@ var XULBrowserWindow = {
|
||||
// simulate all change notifications after switching tabs
|
||||
onUpdateCurrentBrowser: function (aStateFlags, aStatus, aMessage, aTotalProgress) {
|
||||
if (FullZoom.updateBackgroundTabs)
|
||||
FullZoom.onLocationChange(gBrowser.currentURI);
|
||||
FullZoom.onLocationChange(gBrowser.currentURI, true);
|
||||
var nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
|
||||
var loadingDone = aStateFlags & nsIWebProgressListener.STATE_STOP;
|
||||
// use a pseudo-object instead of a (potentially non-existing) channel for getting
|
||||
@@ -4296,7 +4295,7 @@ var TabsProgressListener = {
|
||||
onLocationChange: function (aBrowser, aWebProgress, aRequest, aLocationURI) {
|
||||
// Filter out any sub-frame loads
|
||||
if (aBrowser.contentWindow == aWebProgress.DOMWindow)
|
||||
FullZoom.onLocationChange(aLocationURI, aBrowser);
|
||||
FullZoom.onLocationChange(aLocationURI, false, aBrowser);
|
||||
},
|
||||
|
||||
onStatusChange: function (aBrowser, aWebProgress, aRequest, aStatus, aMessage) {
|
||||
|
||||
@@ -2,6 +2,8 @@ var gTestPage = "http://example.org/browser/browser/base/content/test/dummy_page
|
||||
var gTestImage = "http://example.org/browser/browser/base/content/test/moz.png";
|
||||
var gTab1, gTab2, gTab3;
|
||||
var gLevel;
|
||||
const kBack = 0;
|
||||
const kForward = 1;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
@@ -53,10 +55,74 @@ function imageLoaded() {
|
||||
gBrowser.selectedTab = gTab1;
|
||||
zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
|
||||
|
||||
finishTest();
|
||||
executeSoon(imageZoomSwitch);
|
||||
}
|
||||
|
||||
function imageZoomSwitch() {
|
||||
navigate(kBack, function() {
|
||||
navigate(kForward, function() {
|
||||
zoomTest(gTab1, 1, "Tab 1 should not be zoomed when an image loads");
|
||||
gBrowser.selectedTab = gTab2;
|
||||
zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected");
|
||||
|
||||
// Mac OS X does not support print preview, so skip those tests
|
||||
let isOSX = ("nsILocalFileMac" in Components.interfaces);
|
||||
if (isOSX)
|
||||
finishTest();
|
||||
else
|
||||
runPrintPreviewTests();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function runPrintPreviewTests() {
|
||||
// test print preview on image document
|
||||
testPrintPreview(gTab1, function() {
|
||||
// test print preview on HTML document
|
||||
testPrintPreview(gTab2, function() {
|
||||
// test print preview on image document with siteSpecific set to false
|
||||
gPrefService.setBoolPref("browser.zoom.siteSpecific", false);
|
||||
testPrintPreview(gTab1, function() {
|
||||
// test print preview of HTML document with siteSpecific set to false
|
||||
testPrintPreview(gTab2, function() {
|
||||
gPrefService.clearUserPref("browser.zoom.siteSpecific");
|
||||
finishTest();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testPrintPreview(aTab, aCallback) {
|
||||
gBrowser.selectedTab = aTab;
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.zoom;
|
||||
|
||||
function onEnterPP() {
|
||||
toggleAffectedChromeOrig.apply(null, arguments);
|
||||
|
||||
function onExitPP() {
|
||||
toggleAffectedChromeOrig.apply(null, arguments);
|
||||
toggleAffectedChrome = toggleAffectedChromeOrig;
|
||||
|
||||
zoomTest(aTab, level, "Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
}
|
||||
toggleAffectedChrome = onExitPP;
|
||||
PrintUtils.exitPrintPreview();
|
||||
}
|
||||
let toggleAffectedChromeOrig = toggleAffectedChrome;
|
||||
toggleAffectedChrome = onEnterPP;
|
||||
|
||||
let printPreview = new Function(document.getElementById("cmd_printPreview")
|
||||
.getAttribute("oncommand"));
|
||||
executeSoon(printPreview);
|
||||
}
|
||||
|
||||
function finishTest() {
|
||||
gBrowser.selectedTab = gTab1;
|
||||
FullZoom.reset();
|
||||
gBrowser.removeTab(gTab1);
|
||||
FullZoom.reset();
|
||||
@@ -77,3 +143,14 @@ function load(tab, url, cb) {
|
||||
}, true);
|
||||
tab.linkedBrowser.loadURI(url);
|
||||
}
|
||||
|
||||
function navigate(direction, cb) {
|
||||
gBrowser.addEventListener("pageshow", function(event) {
|
||||
gBrowser.removeEventListener("pageshow", arguments.callee, true);
|
||||
setTimeout(cb, 0);
|
||||
}, true);
|
||||
if (direction == kBack)
|
||||
gBrowser.goBack();
|
||||
else if (direction == kForward)
|
||||
gBrowser.goForward();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ _BROWSER_TEST_FILES = \
|
||||
browser_privatebrowsing_searchbar.js \
|
||||
browser_privatebrowsing_findbar.js \
|
||||
browser_privatebrowsing_zoom.js \
|
||||
browser_privatebrowsing_zoomrestore.js \
|
||||
browser_privatebrowsing_transition.js \
|
||||
browser_privatebrowsing_import.js \
|
||||
browser_privatebrowsing_crh.js \
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Private Browsing Tests.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Ehsan Akhgari.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
// This test makes sure that about:privatebrowsing does not appear zoomed in
|
||||
// if there is already a zoom site pref for about:blank (bug 487656).
|
||||
|
||||
function test() {
|
||||
// initialization
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
let cps = Cc["@mozilla.org/content-pref/service;1"].
|
||||
getService(Ci.nsIContentPrefService);
|
||||
waitForExplicitFinish();
|
||||
|
||||
let tabBlank = gBrowser.selectedTab;
|
||||
gBrowser.removeAllTabsBut(tabBlank);
|
||||
|
||||
let blankBrowser = gBrowser.getBrowserForTab(tabBlank);
|
||||
blankBrowser.addEventListener("load", function() {
|
||||
blankBrowser.removeEventListener("load", arguments.callee, true);
|
||||
|
||||
// change the zoom on the blank page
|
||||
FullZoom.enlarge();
|
||||
isnot(ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
|
||||
|
||||
// enter private browsing mode
|
||||
pb.privateBrowsingEnabled = true;
|
||||
let tabAboutPB = gBrowser.selectedTab;
|
||||
let browserAboutPB = gBrowser.getBrowserForTab(tabAboutPB);
|
||||
browserAboutPB.addEventListener("load", function() {
|
||||
browserAboutPB.removeEventListener("load", arguments.callee, true);
|
||||
setTimeout(function() {
|
||||
// make sure the zoom level is set to 1
|
||||
is(ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
|
||||
|
||||
// Mac OS X does not support print preview, so skip those tests
|
||||
let isOSX = ("nsILocalFileMac" in Components.interfaces);
|
||||
if (isOSX) {
|
||||
finishTest();
|
||||
return;
|
||||
}
|
||||
|
||||
// test print preview on HTML document
|
||||
testPrintPreview(browserAboutPB, function() {
|
||||
browserAboutPB.addEventListener("load", function() {
|
||||
browserAboutPB.removeEventListener("load", arguments.callee, true);
|
||||
|
||||
// test print preview on image document
|
||||
testPrintPreview(browserAboutPB, finishTest);
|
||||
}, true);
|
||||
browserAboutPB.loadURI("about:logo");
|
||||
});
|
||||
}, 0);
|
||||
}, true);
|
||||
}, true);
|
||||
blankBrowser.loadURI("about:blank");
|
||||
}
|
||||
|
||||
function finishTest() {
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
// leave private browsing mode
|
||||
pb.privateBrowsingEnabled = false;
|
||||
let tabBlank = gBrowser.selectedTab;
|
||||
let blankBrowser = gBrowser.getBrowserForTab(tabBlank);
|
||||
blankBrowser.addEventListener("load", function() {
|
||||
blankBrowser.removeEventListener("load", arguments.callee, true);
|
||||
|
||||
executeSoon(function() {
|
||||
// cleanup
|
||||
FullZoom.reset();
|
||||
finish();
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
|
||||
function testPrintPreview(aBrowser, aCallback) {
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.getZoomForBrowser(aBrowser);
|
||||
|
||||
function onEnterPP(aHide) {
|
||||
toggleAffectedChromeOrig(aHide);
|
||||
|
||||
function onExitPP(aHide) {
|
||||
toggleAffectedChromeOrig(aHide);
|
||||
toggleAffectedChrome = toggleAffectedChromeOrig;
|
||||
|
||||
is(ZoomManager.getZoomForBrowser(aBrowser), level,
|
||||
"Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
}
|
||||
toggleAffectedChrome = onExitPP;
|
||||
PrintUtils.exitPrintPreview();
|
||||
}
|
||||
let toggleAffectedChromeOrig = toggleAffectedChrome;
|
||||
toggleAffectedChrome = onEnterPP;
|
||||
|
||||
let printPreview = new Function(document.getElementById("cmd_printPreview")
|
||||
.getAttribute("oncommand"));
|
||||
executeSoon(printPreview);
|
||||
}
|
||||
@@ -190,6 +190,7 @@ var PrintUtils = {
|
||||
return printSettings;
|
||||
},
|
||||
|
||||
_originalZoomValue: null,
|
||||
_closeHandlerPP: null,
|
||||
_webProgressPP: null,
|
||||
_onEnterPP: null,
|
||||
@@ -218,11 +219,19 @@ var PrintUtils = {
|
||||
{
|
||||
gFocusedElement = document.commandDispatcher.focusedElement;
|
||||
|
||||
// Reset the zoom value and save it to be restored later.
|
||||
if (typeof ZoomManager == "object") {
|
||||
this._originalZoomValue = ZoomManager.zoom;
|
||||
ZoomManager.reset();
|
||||
}
|
||||
|
||||
var webBrowserPrint = this.getWebBrowserPrint(aWindow);
|
||||
var printSettings = this.getPrintSettings();
|
||||
try {
|
||||
webBrowserPrint.printPreview(printSettings, null, this._webProgressPP.value);
|
||||
} catch (e) {
|
||||
if (typeof ZoomManager == "object")
|
||||
ZoomManager.zoom = this._originalZoomValue;
|
||||
// Pressing cancel is expressed as an NS_ERROR_ABORT return value,
|
||||
// causing an exception to be thrown which we catch here.
|
||||
// Unfortunately this will also consume helpful failures, so add a
|
||||
@@ -280,7 +289,9 @@ var PrintUtils = {
|
||||
this._closeHandlerPP = null;
|
||||
|
||||
var webBrowserPrint = this.getWebBrowserPrint(aWindow);
|
||||
webBrowserPrint.exitPrintPreview();
|
||||
webBrowserPrint.exitPrintPreview();
|
||||
if (typeof ZoomManager == "object")
|
||||
ZoomManager.zoom = this._originalZoomValue;
|
||||
|
||||
// remove the print preview toolbar
|
||||
var printPreviewTB = document.getElementById("print-preview-toolbar");
|
||||
|
||||
Reference in New Issue
Block a user