mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
[Australis] Bug 956285: test zoom label update on page navigation. r=Gijs
This commit is contained in:
parent
6a58b4476b
commit
fb3d2102b1
@ -14,6 +14,13 @@ add_task(function() {
|
||||
gBrowser.selectedTab = tab1;
|
||||
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");
|
||||
let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
|
||||
FullZoom.enlarge();
|
||||
@ -31,9 +38,16 @@ add_task(function() {
|
||||
yield zoomResetPromise;
|
||||
is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
|
||||
|
||||
CustomizableUI.reset();
|
||||
gBrowser.removeTab(tab2);
|
||||
gBrowser.removeTab(tab1);
|
||||
// Test zoom label updates while navigating pages in the same tab.
|
||||
FullZoom.enlarge();
|
||||
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) {
|
||||
|
@ -20,6 +20,7 @@ registerCleanupFunction(() => Services.prefs.clearUserPref("browser.uiCustomizat
|
||||
let {synthesizeDragStart, synthesizeDrop} = ChromeUtils;
|
||||
|
||||
const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
const kTabEventFailureTimeoutInMs = 20000;
|
||||
|
||||
function createDummyXULButton(id, label) {
|
||||
let btn = document.createElementNS(kNSXUL, "toolbarbutton");
|
||||
@ -304,3 +305,70 @@ function waitFor(aTimeout=100) {
|
||||
setTimeout(function() deferred.resolve(), aTimeout);
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user