michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const kTimeoutInMS = 20000; michael@0: michael@0: // Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate. michael@0: add_task(function() { michael@0: CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR); michael@0: let tab1 = gBrowser.addTab("about:mozilla"); michael@0: let tab2 = gBrowser.addTab("about:newtab"); michael@0: gBrowser.selectedTab = tab1; michael@0: let zoomResetButton = document.getElementById("zoom-reset-button"); michael@0: michael@0: registerCleanupFunction(() => { michael@0: info("Cleaning up."); michael@0: CustomizableUI.reset(); michael@0: gBrowser.removeTab(tab2); michael@0: gBrowser.removeTab(tab1); michael@0: }); michael@0: michael@0: is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla"); michael@0: let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange"); michael@0: FullZoom.enlarge(); michael@0: yield zoomChangePromise; michael@0: is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla"); michael@0: michael@0: let tabSelectPromise = promiseTabSelect(); michael@0: gBrowser.selectedTab = tab2; michael@0: yield tabSelectPromise; michael@0: is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:newtab"); michael@0: michael@0: gBrowser.selectedTab = tab1; michael@0: let zoomResetPromise = promiseObserverNotification("browser-fullZoom:zoomReset"); michael@0: FullZoom.reset(); michael@0: yield zoomResetPromise; michael@0: is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla"); michael@0: michael@0: // Test zoom label updates while navigating pages in the same tab. michael@0: FullZoom.enlarge(); michael@0: yield zoomChangePromise; michael@0: is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla"); michael@0: yield promiseTabLoadEvent(tab1, "about:home"); michael@0: is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home"); michael@0: yield promiseTabHistoryNavigation(-1, function() { michael@0: return parseInt(zoomResetButton.label, 10) == 110; michael@0: }); michael@0: is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla"); michael@0: }); michael@0: michael@0: function promiseObserverNotification(aObserver) { michael@0: let deferred = Promise.defer(); michael@0: function notificationCallback(e) { michael@0: Services.obs.removeObserver(notificationCallback, aObserver, false); michael@0: clearTimeout(timeoutId); michael@0: deferred.resolve(); michael@0: }; michael@0: let timeoutId = setTimeout(() => { michael@0: Services.obs.removeObserver(notificationCallback, aObserver, false); michael@0: deferred.reject("Notification '" + aObserver + "' did not happen within 20 seconds."); michael@0: }, kTimeoutInMS); michael@0: Services.obs.addObserver(notificationCallback, aObserver, false); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function promiseTabSelect() { michael@0: let deferred = Promise.defer(); michael@0: let container = window.gBrowser.tabContainer; michael@0: let timeoutId = setTimeout(() => { michael@0: container.removeEventListener("TabSelect", callback); michael@0: deferred.reject("TabSelect did not happen within 20 seconds"); michael@0: }, kTimeoutInMS); michael@0: function callback(e) { michael@0: container.removeEventListener("TabSelect", callback); michael@0: clearTimeout(timeoutId); michael@0: executeSoon(deferred.resolve); michael@0: }; michael@0: container.addEventListener("TabSelect", callback); michael@0: return deferred.promise; michael@0: }