[Australis] Bug 956285: test zoom label update on page navigation. r=Gijs
This commit is contained in:
@@ -14,6 +14,13 @@ add_task(function() {
|
|||||||
gBrowser.selectedTab = tab1;
|
gBrowser.selectedTab = tab1;
|
||||||
let zoomResetButton = document.getElementById("zoom-reset-button");
|
let zoomResetButton = document.getElementById("zoom-reset-button");
|
||||||
|
|
||||||
|
registerCleanupFunction(() => {
|
||||||
|
info("Cleaning up.");
|
||||||
|
CustomizableUI.reset();
|
||||||
|
gBrowser.removeTab(tab2);
|
||||||
|
gBrowser.removeTab(tab1);
|
||||||
|
});
|
||||||
|
|
||||||
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
|
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
|
||||||
let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
|
let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
|
||||||
FullZoom.enlarge();
|
FullZoom.enlarge();
|
||||||
@@ -31,9 +38,16 @@ add_task(function() {
|
|||||||
yield zoomResetPromise;
|
yield zoomResetPromise;
|
||||||
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
|
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
|
||||||
|
|
||||||
CustomizableUI.reset();
|
// Test zoom label updates while navigating pages in the same tab.
|
||||||
gBrowser.removeTab(tab2);
|
FullZoom.enlarge();
|
||||||
gBrowser.removeTab(tab1);
|
yield zoomChangePromise;
|
||||||
|
is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
|
||||||
|
yield promiseTabLoadEvent(tab1, "about:home");
|
||||||
|
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
|
||||||
|
yield promiseTabHistoryNavigation(-1, function() {
|
||||||
|
return parseInt(zoomResetButton.label, 10) == 110;
|
||||||
|
});
|
||||||
|
is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
|
||||||
});
|
});
|
||||||
|
|
||||||
function promiseObserverNotification(aObserver) {
|
function promiseObserverNotification(aObserver) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUti
|
|||||||
let {synthesizeDragStart, synthesizeDrop} = ChromeUtils;
|
let {synthesizeDragStart, synthesizeDrop} = ChromeUtils;
|
||||||
|
|
||||||
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||||
|
const kTabEventFailureTimeoutInMs = 20000;
|
||||||
|
|
||||||
function createDummyXULButton(id, label) {
|
function createDummyXULButton(id, label) {
|
||||||
let btn = document.createElementNS(kNSXUL, "toolbarbutton");
|
let btn = document.createElementNS(kNSXUL, "toolbarbutton");
|
||||||
@@ -301,3 +302,70 @@ function waitFor(aTimeout=100) {
|
|||||||
setTimeout(function() deferred.resolve(), aTimeout);
|
setTimeout(function() deferred.resolve(), aTimeout);
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a load in an existing tab and waits for it to finish (via some event).
|
||||||
|
*
|
||||||
|
* @param aTab The tab to load into.
|
||||||
|
* @param aUrl The url to load.
|
||||||
|
* @param aEventType The load event type to wait for. Defaults to "load".
|
||||||
|
* @return {Promise} resolved when the event is handled.
|
||||||
|
*/
|
||||||
|
function promiseTabLoadEvent(aTab, aURL, aEventType="load") {
|
||||||
|
let deferred = Promise.defer();
|
||||||
|
info("Wait for tab event: " + aEventType);
|
||||||
|
|
||||||
|
let timeoutId = setTimeout(() => {
|
||||||
|
aTab.linkedBrowser.removeEventListener(aEventType, onTabLoad, true);
|
||||||
|
deferred.reject("TabSelect did not happen within " + kTabEventFailureTimeoutInMs + "ms");
|
||||||
|
}, kTabEventFailureTimeoutInMs);
|
||||||
|
|
||||||
|
function onTabLoad(event) {
|
||||||
|
if (event.originalTarget != aTab.linkedBrowser.contentDocument ||
|
||||||
|
event.target.location.href == "about:blank") {
|
||||||
|
info("skipping spurious load event");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
aTab.linkedBrowser.removeEventListener(aEventType, onTabLoad, true);
|
||||||
|
info("Tab event received: " + aEventType);
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
aTab.linkedBrowser.addEventListener(aEventType, onTabLoad, true, true);
|
||||||
|
aTab.linkedBrowser.loadURI(aURL);
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate back or forward in tab history and wait for it to finish.
|
||||||
|
*
|
||||||
|
* @param aDirection Number to indicate to move backward or forward in history.
|
||||||
|
* @param aConditionFn Function that returns the result of an evaluated condition
|
||||||
|
* that needs to be `true` to resolve the promise.
|
||||||
|
* @return {Promise} resolved when navigation has finished.
|
||||||
|
*/
|
||||||
|
function promiseTabHistoryNavigation(aDirection = -1, aConditionFn) {
|
||||||
|
let deferred = Promise.defer();
|
||||||
|
|
||||||
|
let timeoutId = setTimeout(() => {
|
||||||
|
gBrowser.removeEventListener("pageshow", listener, true);
|
||||||
|
deferred.reject("Pageshow did not happen within " + kTabEventFailureTimeoutInMs + "ms");
|
||||||
|
}, kTabEventFailureTimeoutInMs);
|
||||||
|
|
||||||
|
function listener(event) {
|
||||||
|
gBrowser.removeEventListener("pageshow", listener, true);
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
|
if (aConditionFn) {
|
||||||
|
waitForCondition(aConditionFn).then(() => deferred.resolve(),
|
||||||
|
aReason => deferred.reject(aReason));
|
||||||
|
} else {
|
||||||
|
deferred.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gBrowser.addEventListener("pageshow", listener, true);
|
||||||
|
|
||||||
|
content.history.go(aDirection);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user