Back out 85f522534c5a (bug 829456) for apparently causing frequent failures in test_bug607464.html

CLOSED TREE
This commit is contained in:
Phil Ringnalda 2013-03-16 18:28:48 -07:00
Родитель e9aaf10590
Коммит 85888c8be6
16 изменённых файлов: 522 добавлений и 615 удалений

Просмотреть файл

@ -10,6 +10,15 @@
// From nsEventStateManager.cpp. // From nsEventStateManager.cpp.
const MOUSE_SCROLL_ZOOM = 3; const MOUSE_SCROLL_ZOOM = 3;
Cu.import('resource://gre/modules/ContentPrefInstance.jsm');
function getContentPrefs(aWindow) {
let context = aWindow ? aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext) : null;
return new ContentPrefInstance(context);
}
/** /**
* Controls the "full zoom" setting and its site-specific preferences. * Controls the "full zoom" setting and its site-specific preferences.
*/ */
@ -17,6 +26,17 @@ var FullZoom = {
// Identifies the setting in the content prefs database. // Identifies the setting in the content prefs database.
name: "browser.content.full-zoom", name: "browser.content.full-zoom",
// The global value (if any) for the setting. Lazily loaded from the service
// when first requested, then updated by the pref change listener as it changes.
// If there is no global value, then this should be undefined.
get globalValue() {
var globalValue = getContentPrefs(gBrowser.contentDocument.defaultView).getPref(null, this.name);
if (typeof globalValue != "undefined")
globalValue = this._ensureValid(globalValue);
delete this.globalValue;
return this.globalValue = globalValue;
},
// browser.zoom.siteSpecific preference cache // browser.zoom.siteSpecific preference cache
_siteSpecificPref: undefined, _siteSpecificPref: undefined,
@ -44,9 +64,7 @@ var FullZoom = {
window.addEventListener("DOMMouseScroll", this, false); window.addEventListener("DOMMouseScroll", this, false);
// Register ourselves with the service so we know when our pref changes. // Register ourselves with the service so we know when our pref changes.
this._cps2 = Cc["@mozilla.org/content-pref/service;1"]. getContentPrefs().addObserver(this.name, this);
getService(Ci.nsIContentPrefService2);
this._cps2.addObserverForName(this.name, this);
this._siteSpecificPref = this._siteSpecificPref =
gPrefService.getBoolPref("browser.zoom.siteSpecific"); gPrefService.getBoolPref("browser.zoom.siteSpecific");
@ -59,7 +77,7 @@ var FullZoom = {
destroy: function FullZoom_destroy() { destroy: function FullZoom_destroy() {
gPrefService.removeObserver("browser.zoom.", this); gPrefService.removeObserver("browser.zoom.", this);
this._cps2.removeObserverForName(this.name, this); getContentPrefs().removeObserver(this.name, this);
window.removeEventListener("DOMMouseScroll", this, false); window.removeEventListener("DOMMouseScroll", this, false);
}, },
@ -140,49 +158,33 @@ var FullZoom = {
// nsIContentPrefObserver // nsIContentPrefObserver
onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue) { onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue) {
this._onContentPrefChanged(aGroup, aValue); let contentPrefs = getContentPrefs(gBrowser.contentDocument.defaultView);
if (aGroup == contentPrefs.grouper.group(gBrowser.currentURI))
this._applyPrefToSetting(aValue);
else if (aGroup == null) {
this.globalValue = this._ensureValid(aValue);
// If the current page doesn't have a site-specific preference,
// then its zoom should be set to the new global preference now that
// the global preference has changed.
if (!contentPrefs.hasPref(gBrowser.currentURI, this.name))
this._applyPrefToSetting();
}
}, },
onContentPrefRemoved: function FullZoom_onContentPrefRemoved(aGroup, aName) { onContentPrefRemoved: function FullZoom_onContentPrefRemoved(aGroup, aName) {
this._onContentPrefChanged(aGroup, undefined); let contentPrefs = getContentPrefs(gBrowser.contentDocument.defaultView);
}, if (aGroup == contentPrefs.grouper.group(gBrowser.currentURI))
this._applyPrefToSetting();
else if (aGroup == null) {
this.globalValue = undefined;
/** // If the current page doesn't have a site-specific preference,
* Appropriately updates the zoom level after a content preference has // then its zoom should be set to the default preference now that
* changed. // the global preference has changed.
* if (!contentPrefs.hasPref(gBrowser.currentURI, this.name))
* @param aGroup The group of the changed preference. this._applyPrefToSetting();
* @param aValue The new value of the changed preference. Pass undefined to
* indicate the preference's removal.
*/
_onContentPrefChanged: function FullZoom__onContentPrefChanged(aGroup, aValue) {
if (!gBrowser.currentURI)
return;
let domain = this._cps2.extractDomain(gBrowser.currentURI.spec);
if (aGroup) {
if (aGroup == domain)
this._applyPrefToSetting(aValue);
return;
} }
this._globalValue = aValue === undefined ? aValue :
this._ensureValid(aValue);
// If the current page doesn't have a site-specific preference, then its
// zoom should be set to the new global preference now that the global
// preference has changed.
let hasPref = false;
let ctxt = this._loadContextFromWindow(gBrowser.contentWindow);
this._cps2.getByDomainAndName(gBrowser.currentURI.spec, this.name, ctxt, {
handleResult: function () hasPref = true,
handleCompletion: function () {
if (!hasPref &&
gBrowser.currentURI &&
this._cps2.extractDomain(gBrowser.currentURI.spec) == domain)
this._applyPrefToSetting();
}.bind(this)
});
}, },
// location change observer // location change observer
@ -199,16 +201,12 @@ var FullZoom = {
* (optional) browser object displaying the document * (optional) browser object displaying the document
*/ */
onLocationChange: function FullZoom_onLocationChange(aURI, aIsTabSwitch, aBrowser) { onLocationChange: function FullZoom_onLocationChange(aURI, aIsTabSwitch, aBrowser) {
if (!aURI || (aIsTabSwitch && !this.siteSpecific)) { if (!aURI || (aIsTabSwitch && !this.siteSpecific))
this._notifyOnLocationChange();
return; return;
}
// Avoid the cps roundtrip and apply the default/global pref. // Avoid the cps roundtrip and apply the default/global pref.
if (aURI.spec == "about:blank") { if (aURI.spec == "about:blank") {
this._applyPrefToSetting(undefined, aBrowser, function () { this._applyPrefToSetting(undefined, aBrowser);
this._notifyOnLocationChange();
}.bind(this));
return; return;
} }
@ -217,32 +215,24 @@ var FullZoom = {
// Media documents should always start at 1, and are not affected by prefs. // Media documents should always start at 1, and are not affected by prefs.
if (!aIsTabSwitch && browser.contentDocument.mozSyntheticDocument) { if (!aIsTabSwitch && browser.contentDocument.mozSyntheticDocument) {
ZoomManager.setZoomForBrowser(browser, 1); ZoomManager.setZoomForBrowser(browser, 1);
this._notifyOnLocationChange();
return; return;
} }
let ctxt = this._loadContextFromWindow(browser.contentWindow); let contentPrefs = getContentPrefs(gBrowser.contentDocument.defaultView);
let pref = this._cps2.getCachedByDomainAndName(aURI.spec, this.name, ctxt); if (contentPrefs.hasCachedPref(aURI, this.name)) {
if (pref) { let zoomValue = contentPrefs.getPref(aURI, this.name);
this._applyPrefToSetting(pref.value, browser, function () { this._applyPrefToSetting(zoomValue, browser);
this._notifyOnLocationChange(); } else {
}.bind(this)); var self = this;
return; contentPrefs.getPref(aURI, this.name, function (aResult) {
} // Check that we're still where we expect to be in case this took a while.
// Null check currentURI, since the window may have been destroyed before
let value = undefined; // we were called.
this._cps2.getByDomainAndName(aURI.spec, this.name, ctxt, { if (browser.currentURI && aURI.equals(browser.currentURI)) {
handleResult: function (resultPref) value = resultPref.value, self._applyPrefToSetting(aResult, browser);
handleCompletion: function () {
if (browser.currentURI &&
this._cps2.extractDomain(browser.currentURI.spec) ==
this._cps2.extractDomain(aURI.spec)) {
this._applyPrefToSetting(value, browser, function () {
this._notifyOnLocationChange();
}.bind(this));
} }
}.bind(this) });
}); }
}, },
// update state of zoom type menu item // update state of zoom type menu item
@ -256,43 +246,23 @@ var FullZoom = {
//**************************************************************************// //**************************************************************************//
// Setting & Pref Manipulation // Setting & Pref Manipulation
/** reduce: function FullZoom_reduce() {
* Reduces the zoom level of the page in the current browser.
*
* @param callback Optional. If given, it's asynchronously called when the
* zoom update completes.
*/
reduce: function FullZoom_reduce(callback) {
ZoomManager.reduce(); ZoomManager.reduce();
this._applySettingToPref(callback); this._applySettingToPref();
}, },
/** enlarge: function FullZoom_enlarge() {
* Enlarges the zoom level of the page in the current browser.
*
* @param callback Optional. If given, it's asynchronously called when the
* zoom update completes.
*/
enlarge: function FullZoom_enlarge(callback) {
ZoomManager.enlarge(); ZoomManager.enlarge();
this._applySettingToPref(callback); this._applySettingToPref();
}, },
/** reset: function FullZoom_reset() {
* Sets the zoom level of the page in the current browser to the global zoom if (typeof this.globalValue != "undefined")
* level. ZoomManager.zoom = this.globalValue;
* else
* @param callback Optional. If given, it's asynchronously called when the ZoomManager.reset();
* zoom update completes.
*/ this._removePref();
reset: function FullZoom_reset(callback) {
this._getGlobalValue(gBrowser.contentWindow, function (value) {
if (value === undefined)
ZoomManager.reset();
else
ZoomManager.zoom = value;
this._removePref(callback);
});
}, },
/** /**
@ -313,78 +283,38 @@ var FullZoom = {
* So when we apply new zoom values to the browser, we simply set the zoom. * So when we apply new zoom values to the browser, we simply set the zoom.
* We don't check first to see if the new value is the same as the current * We don't check first to see if the new value is the same as the current
* one. * one.
* **/
* @param aValue The zoom level value. _applyPrefToSetting: function FullZoom__applyPrefToSetting(aValue, aBrowser) {
* @param aBrowser The browser containing the page whose zoom level is to be if ((!this.siteSpecific) || gInPrintPreviewMode)
* set. If falsey, the currently selected browser is used.
* @param aCallback Optional. If given, it's asynchronously called when
* complete.
*/
_applyPrefToSetting: function FullZoom__applyPrefToSetting(aValue, aBrowser, aCallback) {
if (!this.siteSpecific || gInPrintPreviewMode) {
this._executeSoon(aCallback);
return; return;
}
var browser = aBrowser || (gBrowser && gBrowser.selectedBrowser); var browser = aBrowser || (gBrowser && gBrowser.selectedBrowser);
if (browser.contentDocument.mozSyntheticDocument) { try {
this._executeSoon(aCallback); if (browser.contentDocument.mozSyntheticDocument)
return; return;
}
if (aValue !== undefined) { if (typeof aValue != "undefined")
ZoomManager.setZoomForBrowser(browser, this._ensureValid(aValue)); ZoomManager.setZoomForBrowser(browser, this._ensureValid(aValue));
this._executeSoon(aCallback); else if (typeof this.globalValue != "undefined")
return; ZoomManager.setZoomForBrowser(browser, this.globalValue);
else
ZoomManager.setZoomForBrowser(browser, 1);
} }
catch(ex) {}
this._getGlobalValue(browser.contentWindow, function (value) {
if (gBrowser.selectedBrowser == browser)
ZoomManager.setZoomForBrowser(browser, value === undefined ? 1 : value);
this._executeSoon(aCallback);
});
}, },
/** _applySettingToPref: function FullZoom__applySettingToPref() {
* Saves the zoom level of the page in the current browser to the content if (!this.siteSpecific || gInPrintPreviewMode ||
* prefs store. content.document.mozSyntheticDocument)
*
* @param callback Optional. If given, it's asynchronously called when done.
*/
_applySettingToPref: function FullZoom__applySettingToPref(callback) {
if (!this.siteSpecific ||
gInPrintPreviewMode ||
content.document.mozSyntheticDocument) {
this._executeSoon(callback);
return; return;
}
this._cps2.set(gBrowser.currentURI.spec, this.name, ZoomManager.zoom, var zoomLevel = ZoomManager.zoom;
this._loadContextFromWindow(gBrowser.contentWindow), { getContentPrefs(gBrowser.contentDocument.defaultView).setPref(gBrowser.currentURI, this.name, zoomLevel);
handleCompletion: function () {
if (callback)
callback();
}
});
}, },
/** _removePref: function FullZoom__removePref() {
* Removes from the content prefs store the zoom level of the current browser. if (!(content.document.mozSyntheticDocument))
* getContentPrefs(gBrowser.contentDocument.defaultView).removePref(gBrowser.currentURI, this.name);
* @param callback Optional. If given, it's asynchronously called when done.
*/
_removePref: function FullZoom__removePref(callback) {
if (content.document.mozSyntheticDocument) {
this._executeSoon(callback);
return;
}
let ctxt = this._loadContextFromWindow(gBrowser.contentWindow);
this._cps2.removeByDomainAndName(gBrowser.currentURI.spec, this.name, ctxt, {
handleCompletion: function () {
if (callback)
callback();
}
});
}, },
@ -392,8 +322,6 @@ var FullZoom = {
// Utilities // Utilities
_ensureValid: function FullZoom__ensureValid(aValue) { _ensureValid: function FullZoom__ensureValid(aValue) {
// Note that undefined is a valid value for aValue that indicates a known-
// not-to-exist value.
if (isNaN(aValue)) if (isNaN(aValue))
return 1; return 1;
@ -404,68 +332,5 @@ var FullZoom = {
return ZoomManager.MAX; return ZoomManager.MAX;
return aValue; return aValue;
}, }
/**
* Gets the global browser.content.full-zoom content preference.
*
* WARNING: callback may be called synchronously or asynchronously. The
* reason is that it's usually desirable to avoid turns of the event loop
* where possible, since they can lead to visible, jarring jumps in zoom
* level. It's not always possible to avoid them, though. As a convenience,
* then, this method takes a callback and returns nothing.
*
* @param window The content window pertaining to the zoom.
* @param callback Synchronously or asynchronously called when done. It's
* bound to this object (FullZoom) and passed the preference
* value.
*/
_getGlobalValue: function FullZoom__getGlobalValue(window, callback) {
// * !("_globalValue" in this) => global value not yet cached.
// * this._globalValue === undefined => global value known not to exist.
// * Otherwise, this._globalValue is a number, the global value.
if ("_globalValue" in this) {
callback.call(this, this._globalValue);
return;
}
let value = undefined;
this._cps2.getGlobal(this.name, this._loadContextFromWindow(window), {
handleResult: function (pref) value = pref.value,
handleCompletion: function () {
this._globalValue = this._ensureValid(value);
callback.call(this, this._globalValue);
}.bind(this)
});
},
/**
* Gets the load context from the given window.
*
* @param window The window whose load context will be returned.
* @return The nsILoadContext of the given window.
*/
_loadContextFromWindow: function FullZoom__loadContextFromWindow(window) {
return window.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebNavigation).
QueryInterface(Ci.nsILoadContext);
},
/**
* Asynchronously broadcasts a "browser-fullZoom:locationChange" notification
* so that tests can select tabs, load pages, etc. and be notified when the
* zoom levels on those pages change. The notification is always asynchronous
* so that observers are guaranteed a consistent behavior.
*/
_notifyOnLocationChange: function FullZoom__notifyOnLocationChange() {
this._executeSoon(function () {
Services.obs.notifyObservers(null, "browser-fullZoom:locationChange", "");
});
},
_executeSoon: function FullZoom__executeSoon(callback) {
if (!callback)
return;
Services.tm.mainThread.dispatch(callback, Ci.nsIThread.DISPATCH_NORMAL);
},
}; };

Просмотреть файл

@ -8,82 +8,136 @@ const FORWARD = 1;
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
Task.spawn(function () { gTab1 = gBrowser.addTab(gTestPage);
gTab1 = gBrowser.addTab(gTestPage); gTab2 = gBrowser.addTab();
gTab2 = gBrowser.addTab(); gTab3 = gBrowser.addTab();
gTab3 = gBrowser.addTab(); gBrowser.selectedTab = gTab1;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); load(gTab1, gTestPage, function () {
yield FullZoomHelper.load(gTab1, gTestPage); load(gTab2, gTestPage, secondPageLoaded);
yield FullZoomHelper.load(gTab2, gTestPage); });
}).then(secondPageLoaded, FullZoomHelper.failAndContinue(finish));
} }
function secondPageLoaded() { function secondPageLoaded() {
Task.spawn(function () { zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1");
FullZoomHelper.zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1"); zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
FullZoomHelper.zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1"); zoomTest(gTab3, 1, "Initial zoom of tab 3 should be 1");
FullZoomHelper.zoomTest(gTab3, 1, "Initial zoom of tab 3 should be 1");
// Now have three tabs, two with the test page, one blank. Tab 1 is selected // Now have three tabs, two with the test page, one blank. Tab 1 is selected
// Zoom tab 1 // Zoom tab 1
yield FullZoomHelper.enlarge(); FullZoom.enlarge();
gLevel = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1)); gLevel = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1));
ok(gLevel > 1, "New zoom for tab 1 should be greater than 1"); ok(gLevel > 1, "New zoom for tab 1 should be greater than 1");
FullZoomHelper.zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2"); zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2");
FullZoomHelper.zoomTest(gTab3, 1, "Zooming tab 1 should not affect tab 3"); zoomTest(gTab3, 1, "Zooming tab 1 should not affect tab 3");
yield FullZoomHelper.load(gTab3, gTestPage); load(gTab3, gTestPage, thirdPageLoaded);
}).then(thirdPageLoaded, FullZoomHelper.failAndContinue(finish));
} }
function thirdPageLoaded() { function thirdPageLoaded() {
Task.spawn(function () { zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
FullZoomHelper.zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed"); zoomTest(gTab2, 1, "Tab 2 should still not be affected");
FullZoomHelper.zoomTest(gTab2, 1, "Tab 2 should still not be affected"); zoomTest(gTab3, gLevel, "Tab 3 should have zoomed as it was loading in the background");
FullZoomHelper.zoomTest(gTab3, gLevel, "Tab 3 should have zoomed as it was loading in the background");
// Switching to tab 2 should update its zoom setting. // Switching to tab 2 should update its zoom setting.
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab2); afterZoom(function() {
FullZoomHelper.zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed"); zoomTest(gTab1, gLevel, "Tab 1 should still be zoomed");
FullZoomHelper.zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now"); zoomTest(gTab2, gLevel, "Tab 2 should be zoomed now");
FullZoomHelper.zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed"); zoomTest(gTab3, gLevel, "Tab 3 should still be zoomed");
yield FullZoomHelper.load(gTab1, gTestImage); load(gTab1, gTestImage, imageLoaded);
}).then(imageLoaded, FullZoomHelper.failAndContinue(finish)); });
gBrowser.selectedTab = gTab2;
} }
function imageLoaded() { function imageLoaded() {
Task.spawn(function () { zoomTest(gTab1, 1, "Zoom should be 1 when image was loaded in the background");
FullZoomHelper.zoomTest(gTab1, 1, "Zoom should be 1 when image was loaded in the background"); gBrowser.selectedTab = gTab1;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
FullZoomHelper.zoomTest(gTab1, 1, "Zoom should still be 1 when tab with image is selected");
}).then(imageZoomSwitch, FullZoomHelper.failAndContinue(finish)); executeSoon(imageZoomSwitch);
} }
function imageZoomSwitch() { function imageZoomSwitch() {
Task.spawn(function () { navigate(BACK, function () {
yield FullZoomHelper.navigate(BACK); navigate(FORWARD, function () {
yield FullZoomHelper.navigate(FORWARD); zoomTest(gTab1, 1, "Tab 1 should not be zoomed when an image loads");
FullZoomHelper.zoomTest(gTab1, 1, "Tab 1 should not be zoomed when an image loads");
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab2); afterZoom(function() {
FullZoomHelper.zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected"); zoomTest(gTab1, 1, "Tab 1 should still not be zoomed when deselected");
}).then(finishTest, FullZoomHelper.failAndContinue(finish)); finishTest();
});
gBrowser.selectedTab = gTab2;
});
});
} }
var finishTestStarted = false; var finishTestStarted = false;
function finishTest() { function finishTest() {
Task.spawn(function () { ok(!finishTestStarted, "finishTest called more than once");
ok(!finishTestStarted, "finishTest called more than once"); finishTestStarted = true;
finishTestStarted = true; gBrowser.selectedTab = gTab1;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); FullZoom.reset();
yield FullZoomHelper.reset(); gBrowser.removeTab(gTab1);
gBrowser.removeTab(gTab1); FullZoom.reset();
yield FullZoomHelper.reset(); gBrowser.removeTab(gTab2);
gBrowser.removeTab(gTab2); FullZoom.reset();
yield FullZoomHelper.reset(); gBrowser.removeTab(gTab3);
gBrowser.removeTab(gTab3); finish();
}).then(finish, FullZoomHelper.failAndContinue(finish)); }
function zoomTest(tab, val, msg) {
is(ZoomManager.getZoomForBrowser(tab.linkedBrowser), val, msg);
}
function load(tab, url, cb) {
let didLoad = false;
let didZoom = false;
tab.linkedBrowser.addEventListener("load", function (event) {
event.currentTarget.removeEventListener("load", arguments.callee, true);
didLoad = true;
if (didZoom)
executeSoon(cb);
}, true);
afterZoom(function() {
didZoom = true;
if (didLoad)
executeSoon(cb);
});
tab.linkedBrowser.loadURI(url);
}
function navigate(direction, cb) {
let didPs = false;
let didZoom = false;
gBrowser.addEventListener("pageshow", function (event) {
gBrowser.removeEventListener("pageshow", arguments.callee, true);
didPs = true;
if (didZoom)
executeSoon(cb);
}, true);
afterZoom(function() {
didZoom = true;
if (didPs)
executeSoon(cb);
});
if (direction == BACK)
gBrowser.goBack();
else if (direction == FORWARD)
gBrowser.goForward();
}
function afterZoom(cb) {
let oldSZFB = ZoomManager.setZoomForBrowser;
ZoomManager.setZoomForBrowser = function(browser, value) {
oldSZFB.call(ZoomManager, browser, value);
ZoomManager.setZoomForBrowser = oldSZFB;
executeSoon(cb);
};
} }

Просмотреть файл

@ -1,42 +1,62 @@
var tabElm, zoomLevel; var tabElm, zoomLevel;
function start_test_prefNotSet() { function start_test_prefNotSet() {
Task.spawn(function () { is(ZoomManager.zoom, 1, "initial zoom level should be 1");
is(ZoomManager.zoom, 1, "initial zoom level should be 1"); FullZoom.enlarge();
yield FullZoomHelper.enlarge();
//capture the zoom level to test later //capture the zoom level to test later
zoomLevel = ZoomManager.zoom; zoomLevel = ZoomManager.zoom;
isnot(zoomLevel, 1, "zoom level should have changed"); isnot(zoomLevel, 1, "zoom level should have changed");
yield FullZoomHelper.load(gBrowser.selectedTab, "http://mochi.test:8888/browser/browser/base/content/test/moz.png"); afterZoomAndLoad(continue_test_prefNotSet);
}).then(continue_test_prefNotSet, FullZoomHelper.failAndContinue(finish)); content.location =
"http://mochi.test:8888/browser/browser/base/content/test/moz.png";
} }
function continue_test_prefNotSet () { function continue_test_prefNotSet () {
Task.spawn(function () { is(ZoomManager.zoom, 1, "zoom level pref should not apply to an image");
is(ZoomManager.zoom, 1, "zoom level pref should not apply to an image"); FullZoom.reset();
yield FullZoomHelper.reset();
yield FullZoomHelper.load(gBrowser.selectedTab, "http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html"); afterZoomAndLoad(end_test_prefNotSet);
}).then(end_test_prefNotSet, FullZoomHelper.failAndContinue(finish)); content.location =
"http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html";
} }
function end_test_prefNotSet() { function end_test_prefNotSet() {
Task.spawn(function () { is(ZoomManager.zoom, zoomLevel, "the zoom level should have persisted");
is(ZoomManager.zoom, zoomLevel, "the zoom level should have persisted");
// Reset the zoom so that other tests have a fresh zoom level // Reset the zoom so that other tests have a fresh zoom level
yield FullZoomHelper.reset(); FullZoom.reset();
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
}).then(finish, FullZoomHelper.failAndContinue(finish)); finish();
} }
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
Task.spawn(function () { tabElm = gBrowser.addTab();
tabElm = gBrowser.addTab(); gBrowser.selectedTab = tabElm;
yield FullZoomHelper.selectTabAndWaitForLocationChange(tabElm);
yield FullZoomHelper.load(tabElm, "http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html"); afterZoomAndLoad(start_test_prefNotSet);
}).then(start_test_prefNotSet, FullZoomHelper.failAndContinue(finish)); content.location =
"http://mochi.test:8888/browser/browser/base/content/test/zoom_test.html";
}
function afterZoomAndLoad(cb) {
let didLoad = false;
let didZoom = false;
tabElm.linkedBrowser.addEventListener("load", function() {
tabElm.linkedBrowser.removeEventListener("load", arguments.callee, true);
didLoad = true;
if (didZoom)
executeSoon(cb);
}, true);
let oldSZFB = ZoomManager.setZoomForBrowser;
ZoomManager.setZoomForBrowser = function(browser, value) {
oldSZFB.call(ZoomManager, browser, value);
ZoomManager.setZoomForBrowser = oldSZFB;
didZoom = true;
if (didLoad)
executeSoon(cb);
};
} }

Просмотреть файл

@ -1,32 +1,49 @@
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
Task.spawn(function () { let testPage = "http://example.org/browser/browser/base/content/test/dummy_page.html";
let testPage = "http://example.org/browser/browser/base/content/test/dummy_page.html"; let tab1 = gBrowser.selectedTab = gBrowser.addTab();
let tab1 = gBrowser.addTab(); tab1.linkedBrowser.addEventListener("load", (function(event) {
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab1); event.currentTarget.removeEventListener("load", arguments.callee, true);
yield FullZoomHelper.load(tab1, testPage);
let tab2 = gBrowser.addTab(); let tab2 = gBrowser.addTab();
yield FullZoomHelper.load(tab2, testPage); tab2.linkedBrowser.addEventListener("load", (function(event) {
event.currentTarget.removeEventListener("load", arguments.callee, true);
yield FullZoomHelper.enlarge(); FullZoom.enlarge();
let tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser); let tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser);
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab2); afterZoom(function() {
let tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser); let tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
is(tab2Zoom, tab1Zoom, "Zoom should affect background tabs"); is(tab2Zoom, tab1Zoom, "Zoom should affect background tabs");
gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", false); gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", false);
yield FullZoomHelper.reset(); FullZoom.reset();
gBrowser.selectedTab = tab1; gBrowser.selectedTab = tab1;
tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser); tab1Zoom = ZoomManager.getZoomForBrowser(tab1.linkedBrowser);
tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser); tab2Zoom = ZoomManager.getZoomForBrowser(tab2.linkedBrowser);
isnot(tab1Zoom, tab2Zoom, "Zoom should not affect background tabs"); isnot(tab1Zoom, tab2Zoom, "Zoom should not affect background tabs");
if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs")) if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs"); gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
gBrowser.removeTab(tab1); gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2); gBrowser.removeTab(tab2);
}).then(finish, FullZoomHelper.failAndContinue(finish)); finish();
});
gBrowser.selectedTab = tab2;
}), true);
tab2.linkedBrowser.loadURI(testPage);
}), true);
content.location = testPage;
}
function afterZoom(cb) {
let oldAPTS = FullZoom._applyPrefToSetting;
FullZoom._applyPrefToSetting = function(value, browser) {
if (!value)
value = undefined;
oldAPTS.call(FullZoom, value, browser);
FullZoom._applyPrefToSetting = oldAPTS;
executeSoon(cb);
};
} }

Просмотреть файл

@ -13,22 +13,19 @@ function test() {
const TEST_PAGE_URL = 'data:text/html,<body><iframe src=""></iframe></body>'; const TEST_PAGE_URL = 'data:text/html,<body><iframe src=""></iframe></body>';
const TEST_IFRAME_URL = "http://test2.example.org/"; const TEST_IFRAME_URL = "http://test2.example.org/";
Task.spawn(function () { // Prepare the test tab
// Prepare the test tab gBrowser.selectedTab = gBrowser.addTab();
let tab = gBrowser.addTab(); let testBrowser = gBrowser.selectedBrowser;
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab);
let testBrowser = tab.linkedBrowser; testBrowser.addEventListener("load", function () {
testBrowser.removeEventListener("load", arguments.callee, true);
yield FullZoomHelper.load(tab, TEST_PAGE_URL);
// Change the zoom level and then save it so we can compare it to the level // Change the zoom level and then save it so we can compare it to the level
// after loading the sub-document. // after loading the sub-document.
yield FullZoomHelper.enlarge(); FullZoom.enlarge();
var zoomLevel = ZoomManager.zoom; var zoomLevel = ZoomManager.zoom;
// Start the sub-document load. // Start the sub-document load.
let deferred = Promise.defer();
executeSoon(function () { executeSoon(function () {
testBrowser.addEventListener("load", function (e) { testBrowser.addEventListener("load", function (e) {
testBrowser.removeEventListener("load", arguments.callee, true); testBrowser.removeEventListener("load", arguments.callee, true);
@ -37,10 +34,11 @@ function test() {
is(ZoomManager.zoom, zoomLevel, "zoom is retained after sub-document load"); is(ZoomManager.zoom, zoomLevel, "zoom is retained after sub-document load");
gBrowser.removeCurrentTab(); gBrowser.removeCurrentTab();
deferred.resolve(); finish();
}, true); }, true);
content.document.querySelector("iframe").src = TEST_IFRAME_URL; content.document.querySelector("iframe").src = TEST_IFRAME_URL;
}); });
yield deferred.promise; }, true);
}).then(finish, FullZoomHelper.failAndContinue(finish));
content.location = TEST_PAGE_URL;
} }

Просмотреть файл

@ -4,36 +4,59 @@
const TEST_PAGE = "/browser/browser/base/content/test/dummy_page.html"; const TEST_PAGE = "/browser/browser/base/content/test/dummy_page.html";
var gTestTab, gBgTab, gTestZoom; var gTestTab, gBgTab, gTestZoom;
function afterZoomAndLoad(aCallback, aTab) {
let didLoad = false;
let didZoom = false;
aTab.linkedBrowser.addEventListener("load", function() {
aTab.linkedBrowser.removeEventListener("load", arguments.callee, true);
didLoad = true;
if (didZoom)
executeSoon(aCallback);
}, true);
let oldAPTS = FullZoom._applyPrefToSetting;
FullZoom._applyPrefToSetting = function(value, browser) {
if (!value)
value = undefined;
oldAPTS.call(FullZoom, value, browser);
// Don't reset _applyPrefToSetting until we've seen the about:blank load(s)
if (browser && browser.currentURI.spec.startsWith("http:")) {
FullZoom._applyPrefToSetting = oldAPTS;
didZoom = true;
}
if (didLoad && didZoom)
executeSoon(aCallback);
};
}
function testBackgroundLoad() { function testBackgroundLoad() {
Task.spawn(function () { is(ZoomManager.zoom, gTestZoom, "opening a background tab should not change foreground zoom");
is(ZoomManager.zoom, gTestZoom, "opening a background tab should not change foreground zoom");
gBrowser.removeTab(gBgTab); gBrowser.removeTab(gBgTab);
yield FullZoomHelper.reset(); FullZoom.reset();
gBrowser.removeTab(gTestTab); gBrowser.removeTab(gTestTab);
}).then(finish, FullZoomHelper.failAndContinue(finish));
finish();
} }
function testInitialZoom() { function testInitialZoom() {
Task.spawn(function () { is(ZoomManager.zoom, 1, "initial zoom level should be 1");
is(ZoomManager.zoom, 1, "initial zoom level should be 1"); FullZoom.enlarge();
yield FullZoomHelper.enlarge();
gTestZoom = ZoomManager.zoom; gTestZoom = ZoomManager.zoom;
isnot(gTestZoom, 1, "zoom level should have changed"); isnot(gTestZoom, 1, "zoom level should have changed");
gBgTab = gBrowser.addTab(); afterZoomAndLoad(testBackgroundLoad,
yield FullZoomHelper.load(gBgTab, "http://mochi.test:8888" + TEST_PAGE); gBgTab = gBrowser.loadOneTab("http://mochi.test:8888" + TEST_PAGE,
}).then(testBackgroundLoad, FullZoomHelper.failAndContinue(finish)); {inBackground: true}));
} }
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
Task.spawn(function () { gTestTab = gBrowser.addTab();
gTestTab = gBrowser.addTab(); gBrowser.selectedTab = gTestTab;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTestTab);
yield FullZoomHelper.load(gTestTab, "http://example.org" + TEST_PAGE); afterZoomAndLoad(testInitialZoom, gTestTab);
}).then(testInitialZoom, FullZoomHelper.failAndContinue(finish)); content.location = "http://example.org" + TEST_PAGE;
} }

Просмотреть файл

@ -1,5 +1,3 @@
var tab;
function test() { function test() {
// ---------- // ----------
@ -7,34 +5,53 @@ function test() {
waitForExplicitFinish(); waitForExplicitFinish();
let oldOLC = FullZoom.onLocationChange;
FullZoom.onLocationChange = function(aURI, aIsTabSwitch, aBrowser) {
// Ignore calls that are not about tab switching on this test
if (aIsTabSwitch)
oldOLC.call(FullZoom, aURI, aIsTabSwitch, aBrowser);
};
gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", true); gPrefService.setBoolPref("browser.zoom.updateBackgroundTabs", true);
gPrefService.setBoolPref("browser.zoom.siteSpecific", true); gPrefService.setBoolPref("browser.zoom.siteSpecific", true);
let oldAPTS = FullZoom._applyPrefToSetting;
let uri = "http://example.org/browser/browser/base/content/test/dummy_page.html"; let uri = "http://example.org/browser/browser/base/content/test/dummy_page.html";
Task.spawn(function () { let tab = gBrowser.addTab();
tab = gBrowser.addTab(); tab.linkedBrowser.addEventListener("load", function(event) {
yield FullZoomHelper.load(tab, uri); tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Test - Trigger a tab switch that should update the zoom level // Test - Trigger a tab switch that should update the zoom level
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab); FullZoom._applyPrefToSetting = function() {
ok(true, "applyPrefToSetting was called"); ok(true, "applyPrefToSetting was called");
}).then(endTest, FullZoomHelper.failAndContinue(endTest)); endTest();
}
gBrowser.selectedTab = tab;
}, true);
tab.linkedBrowser.loadURI(uri);
// -------------
// Test clean-up
function endTest() {
FullZoom._applyPrefToSetting = oldAPTS;
FullZoom.onLocationChange = oldOLC;
gBrowser.removeTab(tab);
oldAPTS = null;
oldOLC = null;
tab = null;
if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
if (gPrefService.prefHasUserValue("browser.zoom.siteSpecific"))
gPrefService.clearUserPref("browser.zoom.siteSpecific");
finish();
}
} }
// -------------
// Test clean-up
function endTest() {
gBrowser.removeTab(tab);
tab = null;
if (gPrefService.prefHasUserValue("browser.zoom.updateBackgroundTabs"))
gPrefService.clearUserPref("browser.zoom.updateBackgroundTabs");
if (gPrefService.prefHasUserValue("browser.zoom.siteSpecific"))
gPrefService.clearUserPref("browser.zoom.siteSpecific");
finish();
}

Просмотреть файл

@ -13,22 +13,25 @@ function test() {
gBrowser.removeTab(tab2); gBrowser.removeTab(tab2);
}); });
Task.spawn(function () { tab1 = gBrowser.addTab(TEST_IMAGE);
tab1 = gBrowser.addTab(); tab2 = gBrowser.addTab();
tab2 = gBrowser.addTab(); gBrowser.selectedTab = tab1;
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab1);
yield FullZoomHelper.load(tab1, TEST_IMAGE);
tab1.linkedBrowser.addEventListener("load", function onload() {
tab1.linkedBrowser.removeEventListener("load", onload, true);
is(ZoomManager.zoom, 1, "initial zoom level for first should be 1"); is(ZoomManager.zoom, 1, "initial zoom level for first should be 1");
yield FullZoomHelper.enlarge(); FullZoom.enlarge();
let zoom = ZoomManager.zoom; let zoom = ZoomManager.zoom;
isnot(zoom, 1, "zoom level should have changed"); isnot(zoom, 1, "zoom level should have changed");
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab2); gBrowser.selectedTab = tab2;
is(ZoomManager.zoom, 1, "initial zoom level for second tab should be 1"); is(ZoomManager.zoom, 1, "initial zoom level for second tab should be 1");
yield FullZoomHelper.selectTabAndWaitForLocationChange(tab1); gBrowser.selectedTab = tab1;
is(ZoomManager.zoom, zoom, "zoom level for first tab should not have changed"); is(ZoomManager.zoom, zoom, "zoom level for first tab should not have changed");
}).then(finish, FullZoomHelper.failAndContinue(finish));
finish();
}, true);
} }

Просмотреть файл

@ -9,73 +9,133 @@ const TEST_VIDEO = "http://example.org/browser/browser/base/content/test/video.o
var gTab1, gTab2, gLevel1, gLevel2; var gTab1, gTab2, gLevel1, gLevel2;
function test() { function test() {
Task.spawn(function () { waitForExplicitFinish();
waitForExplicitFinish();
gTab1 = gBrowser.addTab(); gTab1 = gBrowser.addTab();
gTab2 = gBrowser.addTab(); gTab2 = gBrowser.addTab();
gBrowser.selectedTab = gTab1;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); load(gTab1, TEST_PAGE, function() {
yield FullZoomHelper.load(gTab1, TEST_PAGE); load(gTab2, TEST_VIDEO, zoomTab1);
yield FullZoomHelper.load(gTab2, TEST_VIDEO); });
}).then(zoomTab1, FullZoomHelper.failAndContinue(finish));
} }
function zoomTab1() { function zoomTab1() {
Task.spawn(function () { is(gBrowser.selectedTab, gTab1, "Tab 1 is selected");
is(gBrowser.selectedTab, gTab1, "Tab 1 is selected"); zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1");
FullZoomHelper.zoomTest(gTab1, 1, "Initial zoom of tab 1 should be 1"); zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
FullZoomHelper.zoomTest(gTab2, 1, "Initial zoom of tab 2 should be 1");
yield FullZoomHelper.enlarge(); FullZoom.enlarge();
gLevel1 = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1)); gLevel1 = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab1));
ok(gLevel1 > 1, "New zoom for tab 1 should be greater than 1"); ok(gLevel1 > 1, "New zoom for tab 1 should be greater than 1");
FullZoomHelper.zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2"); zoomTest(gTab2, 1, "Zooming tab 1 should not affect tab 2");
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab2); gBrowser.selectedTab = gTab2;
FullZoomHelper.zoomTest(gTab2, 1, "Tab 2 is still unzoomed after it is selected"); zoomTest(gTab2, 1, "Tab 2 is still unzoomed after it is selected");
FullZoomHelper.zoomTest(gTab1, gLevel1, "Tab 1 is still zoomed"); zoomTest(gTab1, gLevel1, "Tab 1 is still zoomed");
}).then(zoomTab2, FullZoomHelper.failAndContinue(finish));
zoomTab2();
} }
function zoomTab2() { function zoomTab2() {
Task.spawn(function () { is(gBrowser.selectedTab, gTab2, "Tab 2 is selected");
is(gBrowser.selectedTab, gTab2, "Tab 2 is selected");
yield FullZoomHelper.reduce(); FullZoom.reduce();
let gLevel2 = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab2)); let gLevel2 = ZoomManager.getZoomForBrowser(gBrowser.getBrowserForTab(gTab2));
ok(gLevel2 < 1, "New zoom for tab 2 should be less than 1"); ok(gLevel2 < 1, "New zoom for tab 2 should be less than 1");
FullZoomHelper.zoomTest(gTab1, gLevel1, "Zooming tab 2 should not affect tab 1"); zoomTest(gTab1, gLevel1, "Zooming tab 2 should not affect tab 1");
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); afterZoom(function() {
FullZoomHelper.zoomTest(gTab1, gLevel1, "Tab 1 should have the same zoom after it's selected"); zoomTest(gTab1, gLevel1, "Tab 1 should have the same zoom after it's selected");
}).then(testNavigation, FullZoomHelper.failAndContinue(finish));
testNavigation();
});
gBrowser.selectedTab = gTab1;
} }
function testNavigation() { function testNavigation() {
Task.spawn(function () { load(gTab1, TEST_VIDEO, function() {
yield FullZoomHelper.load(gTab1, TEST_VIDEO); zoomTest(gTab1, 1, "Zoom should be 1 when a video was loaded");
FullZoomHelper.zoomTest(gTab1, 1, "Zoom should be 1 when a video was loaded"); navigate(BACK, function() {
yield FullZoomHelper.navigate(FullZoomHelper.BACK); zoomTest(gTab1, gLevel1, "Zoom should be restored when a page is loaded");
FullZoomHelper.zoomTest(gTab1, gLevel1, "Zoom should be restored when a page is loaded"); navigate(FORWARD, function() {
yield FullZoomHelper.navigate(FullZoomHelper.FORWARD); zoomTest(gTab1, 1, "Zoom should be 1 again when navigating back to a video");
FullZoomHelper.zoomTest(gTab1, 1, "Zoom should be 1 again when navigating back to a video"); finishTest();
}).then(finishTest, FullZoomHelper.failAndContinue(finish)); });
});
});
} }
var finishTestStarted = false; var finishTestStarted = false;
function finishTest() { function finishTest() {
Task.spawn(function () { ok(!finishTestStarted, "finishTest called more than once");
ok(!finishTestStarted, "finishTest called more than once"); finishTestStarted = true;
finishTestStarted = true;
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab1); gBrowser.selectedTab = gTab1;
yield FullZoomHelper.reset(); FullZoom.reset();
gBrowser.removeTab(gTab1); gBrowser.removeTab(gTab1);
yield FullZoomHelper.selectTabAndWaitForLocationChange(gTab2);
yield FullZoomHelper.reset(); gBrowser.selectedTab = gTab2;
gBrowser.removeTab(gTab2); FullZoom.reset();
}).then(finish, FullZoomHelper.failAndContinue(finish)); gBrowser.removeTab(gTab2);
finish();
}
function zoomTest(tab, val, msg) {
is(ZoomManager.getZoomForBrowser(tab.linkedBrowser), val, msg);
}
function load(tab, url, cb) {
let didLoad = false;
let didZoom = false;
tab.linkedBrowser.addEventListener("load", function onload(event) {
event.currentTarget.removeEventListener("load", onload, true);
didLoad = true;
if (didZoom)
executeSoon(cb);
}, true);
afterZoom(function() {
didZoom = true;
if (didLoad)
executeSoon(cb);
});
tab.linkedBrowser.loadURI(url);
}
const BACK = 0;
const FORWARD = 1;
function navigate(direction, cb) {
let didPs = false;
let didZoom = false;
gBrowser.addEventListener("pageshow", function onpageshow(event) {
gBrowser.removeEventListener("pageshow", onpageshow, true);
didPs = true;
if (didZoom)
executeSoon(cb);
}, true);
afterZoom(function() {
didZoom = true;
if (didPs)
executeSoon(cb);
});
if (direction == BACK)
gBrowser.goBack();
else if (direction == FORWARD)
gBrowser.goForward();
}
function afterZoom(cb) {
let oldSZFB = ZoomManager.setZoomForBrowser;
ZoomManager.setZoomForBrowser = function(browser, value) {
oldSZFB.call(ZoomManager, browser, value);
ZoomManager.setZoomForBrowser = oldSZFB;
executeSoon(cb);
};
} }

Просмотреть файл

@ -261,107 +261,3 @@ function promiseHistoryClearedState(aURIs, aShouldBeCleared) {
return deferred.promise; return deferred.promise;
} }
let FullZoomHelper = {
selectTabAndWaitForLocationChange: function selectTabAndWaitForLocationChange(tab) {
let deferred = Promise.defer();
if (tab && gBrowser.selectedTab == tab) {
deferred.resolve();
return deferred.promise;
}
if (tab)
gBrowser.selectedTab = tab;
Services.obs.addObserver(function obs() {
Services.obs.removeObserver(obs, "browser-fullZoom:locationChange");
deferred.resolve();
}, "browser-fullZoom:locationChange", false);
return deferred.promise;
},
load: function load(tab, url) {
let deferred = Promise.defer();
let didLoad = false;
let didZoom = false;
tab.linkedBrowser.addEventListener("load", function (event) {
event.currentTarget.removeEventListener("load", arguments.callee, true);
didLoad = true;
if (didZoom)
deferred.resolve();
}, true);
// Don't select background tabs. That way tests can use this method on
// background tabs without having them automatically be selected. Just wait
// for the zoom to change on the current tab if it's `tab`.
if (tab == gBrowser.selectedTab) {
this.selectTabAndWaitForLocationChange(null).then(function () {
didZoom = true;
if (didLoad)
deferred.resolve();
});
}
else
didZoom = true;
tab.linkedBrowser.loadURI(url);
return deferred.promise;
},
zoomTest: function zoomTest(tab, val, msg) {
is(ZoomManager.getZoomForBrowser(tab.linkedBrowser), val, msg);
},
enlarge: function enlarge() {
let deferred = Promise.defer();
FullZoom.enlarge(function () deferred.resolve());
return deferred.promise;
},
reduce: function reduce() {
let deferred = Promise.defer();
FullZoom.reduce(function () deferred.resolve());
return deferred.promise;
},
reset: function reset() {
let deferred = Promise.defer();
FullZoom.reset(function () deferred.resolve());
return deferred.promise;
},
BACK: 0,
FORWARD: 1,
navigate: function navigate(direction) {
let deferred = Promise.defer();
let didPs = false;
let didZoom = false;
gBrowser.addEventListener("pageshow", function (event) {
gBrowser.removeEventListener("pageshow", arguments.callee, true);
didPs = true;
if (didZoom)
deferred.resolve();
}, true);
if (direction == this.BACK)
gBrowser.goBack();
else if (direction == this.FORWARD)
gBrowser.goForward();
this.selectTabAndWaitForLocationChange(null).then(function () {
didZoom = true;
if (didPs)
deferred.resolve();
});
return deferred.promise;
},
failAndContinue: function failAndContinue(func) {
return function (err) {
ok(false, err);
func();
};
},
};

Просмотреть файл

@ -25,29 +25,27 @@ function test() {
let mozillaZoom = aWindow.ZoomManager.zoom; let mozillaZoom = aWindow.ZoomManager.zoom;
// change the zoom on the mozilla page // change the zoom on the mozilla page
aWindow.FullZoom.enlarge(function () { aWindow.FullZoom.enlarge();
// make sure the zoom level has been changed // make sure the zoom level has been changed
isnot(aWindow.ZoomManager.zoom, mozillaZoom, "Zoom level can be changed"); isnot(aWindow.ZoomManager.zoom, mozillaZoom, "Zoom level can be changed");
mozillaZoom = aWindow.ZoomManager.zoom; mozillaZoom = aWindow.ZoomManager.zoom;
// switch to about: tab // switch to about: tab
aWindow.gBrowser.selectedTab = tabAbout; aWindow.gBrowser.selectedTab = tabAbout;
// switch back to mozilla tab // switch back to mozilla tab
aWindow.gBrowser.selectedTab = tabMozilla; aWindow.gBrowser.selectedTab = tabMozilla;
// make sure the zoom level has not changed // make sure the zoom level has not changed
is(aWindow.ZoomManager.zoom, mozillaZoom, is(aWindow.ZoomManager.zoom, mozillaZoom,
"Entering private browsing should not reset the zoom on a tab"); "Entering private browsing should not reset the zoom on a tab");
// cleanup // cleanup
aWindow.FullZoom.reset(function () { aWindow.FullZoom.reset();
aWindow.gBrowser.removeTab(tabMozilla); aWindow.gBrowser.removeTab(tabMozilla);
aWindow.gBrowser.removeTab(tabAbout); aWindow.gBrowser.removeTab(tabAbout);
aWindow.close(); aWindow.close();
aCallback(); aCallback();
});
});
}, true); }, true);
mozillaBrowser.contentWindow.location = "about:mozilla"; mozillaBrowser.contentWindow.location = "about:mozilla";
}, true); }, true);

Просмотреть файл

@ -16,14 +16,12 @@ function test() {
aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
if (aIsZoomedWindow) { if (aIsZoomedWindow) {
// change the zoom on the blank page // change the zoom on the blank page
aWindow.FullZoom.enlarge(function () { aWindow.FullZoom.enlarge();
isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed"); isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed");
aCallback(); } else {
}); // make sure the zoom level is set to 1
return; is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
} }
// make sure the zoom level is set to 1
is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset");
aCallback(); aCallback();
}, true); }, true);
@ -33,18 +31,10 @@ function test() {
function finishTest() { function finishTest() {
// cleanup // cleanup
let numWindows = windowsToReset.length;
if (!numWindows) {
finish();
return;
}
windowsToReset.forEach(function(win) { windowsToReset.forEach(function(win) {
win.FullZoom.reset(function onReset() { win.FullZoom.reset();
numWindows--;
if (!numWindows)
finish();
});
}); });
finish();
} }
function testOnWindow(options, callback) { function testOnWindow(options, callback) {

Просмотреть файл

@ -63,7 +63,7 @@ interface nsIContentPref;
* nsIContentPrefCallback2 below for more information about callbacks. * nsIContentPrefCallback2 below for more information about callbacks.
*/ */
[scriptable, uuid(133608c7-f812-41ca-bc1c-62a4eb95e52a)] [scriptable, uuid(51e1d34a-5e9d-4b77-b14c-0f8346e264ca)]
interface nsIContentPrefService2 : nsISupports interface nsIContentPrefService2 : nsISupports
{ {
/** /**
@ -318,17 +318,6 @@ interface nsIContentPrefService2 : nsISupports
*/ */
void removeObserverForName(in AString name, void removeObserverForName(in AString name,
in nsIContentPrefObserver observer); in nsIContentPrefObserver observer);
/**
* Extracts and returns the domain from the given string representation of a
* URI. This is how the API extracts domains from URIs passed to it.
*
* @param str The string representation of a URI, like
* "http://example.com/foo/bar".
* @return If the given string is a valid URI, the domain of that URI is
* returned. Otherwise, the string itself is returned.
*/
AString extractDomain(in AString str);
}; };
/** /**
@ -347,7 +336,7 @@ interface nsIContentPrefCallback2 : nsISupports
/** /**
* Called when an error occurs. This may be called multiple times before * Called when an error occurs. This may be called multiple times before
* handleCompletion is called. * onComplete is called.
* *
* @param error A number in Components.results describing the error. * @param error A number in Components.results describing the error.
*/ */

Просмотреть файл

@ -682,10 +682,6 @@ ContentPrefService2.prototype = {
this._cps.removeObserver(name, observer); this._cps.removeObserver(name, observer);
}, },
extractDomain: function CPS2_extractDomain(str) {
return this._parseGroup(str);
},
/** /**
* Tests use this as a backchannel by calling it directly. * Tests use this as a backchannel by calling it directly.
* *

Просмотреть файл

@ -1,18 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
let tests = {
"http://example.com": "example.com",
"http://example.com/": "example.com",
"http://example.com/foo/bar/baz": "example.com",
"http://subdomain.example.com/foo/bar/baz": "subdomain.example.com",
"http://qix.quux.example.com/foo/bar/baz": "qix.quux.example.com",
"not a url": "not a url",
};
let cps = Cc["@mozilla.org/content-pref/service;1"].
getService(Ci.nsIContentPrefService2);
for (let url in tests)
do_check_eq(cps.extractDomain(url), tests[url]);
}

Просмотреть файл

@ -12,4 +12,3 @@ tail =
[test_getCached.js] [test_getCached.js]
[test_getCachedSubdomains.js] [test_getCachedSubdomains.js]
[test_observers.js] [test_observers.js]
[test_extractDomain.js]