browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const kTimeoutInMS = 20000;
michael@0 8
michael@0 9 // Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate.
michael@0 10 add_task(function() {
michael@0 11 CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR);
michael@0 12 let tab1 = gBrowser.addTab("about:mozilla");
michael@0 13 let tab2 = gBrowser.addTab("about:newtab");
michael@0 14 gBrowser.selectedTab = tab1;
michael@0 15 let zoomResetButton = document.getElementById("zoom-reset-button");
michael@0 16
michael@0 17 registerCleanupFunction(() => {
michael@0 18 info("Cleaning up.");
michael@0 19 CustomizableUI.reset();
michael@0 20 gBrowser.removeTab(tab2);
michael@0 21 gBrowser.removeTab(tab1);
michael@0 22 });
michael@0 23
michael@0 24 is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
michael@0 25 let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
michael@0 26 FullZoom.enlarge();
michael@0 27 yield zoomChangePromise;
michael@0 28 is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
michael@0 29
michael@0 30 let tabSelectPromise = promiseTabSelect();
michael@0 31 gBrowser.selectedTab = tab2;
michael@0 32 yield tabSelectPromise;
michael@0 33 is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:newtab");
michael@0 34
michael@0 35 gBrowser.selectedTab = tab1;
michael@0 36 let zoomResetPromise = promiseObserverNotification("browser-fullZoom:zoomReset");
michael@0 37 FullZoom.reset();
michael@0 38 yield zoomResetPromise;
michael@0 39 is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
michael@0 40
michael@0 41 // Test zoom label updates while navigating pages in the same tab.
michael@0 42 FullZoom.enlarge();
michael@0 43 yield zoomChangePromise;
michael@0 44 is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
michael@0 45 yield promiseTabLoadEvent(tab1, "about:home");
michael@0 46 is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
michael@0 47 yield promiseTabHistoryNavigation(-1, function() {
michael@0 48 return parseInt(zoomResetButton.label, 10) == 110;
michael@0 49 });
michael@0 50 is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
michael@0 51 });
michael@0 52
michael@0 53 function promiseObserverNotification(aObserver) {
michael@0 54 let deferred = Promise.defer();
michael@0 55 function notificationCallback(e) {
michael@0 56 Services.obs.removeObserver(notificationCallback, aObserver, false);
michael@0 57 clearTimeout(timeoutId);
michael@0 58 deferred.resolve();
michael@0 59 };
michael@0 60 let timeoutId = setTimeout(() => {
michael@0 61 Services.obs.removeObserver(notificationCallback, aObserver, false);
michael@0 62 deferred.reject("Notification '" + aObserver + "' did not happen within 20 seconds.");
michael@0 63 }, kTimeoutInMS);
michael@0 64 Services.obs.addObserver(notificationCallback, aObserver, false);
michael@0 65 return deferred.promise;
michael@0 66 }
michael@0 67
michael@0 68 function promiseTabSelect() {
michael@0 69 let deferred = Promise.defer();
michael@0 70 let container = window.gBrowser.tabContainer;
michael@0 71 let timeoutId = setTimeout(() => {
michael@0 72 container.removeEventListener("TabSelect", callback);
michael@0 73 deferred.reject("TabSelect did not happen within 20 seconds");
michael@0 74 }, kTimeoutInMS);
michael@0 75 function callback(e) {
michael@0 76 container.removeEventListener("TabSelect", callback);
michael@0 77 clearTimeout(timeoutId);
michael@0 78 executeSoon(deferred.resolve);
michael@0 79 };
michael@0 80 container.addEventListener("TabSelect", callback);
michael@0 81 return deferred.promise;
michael@0 82 }

mercurial