browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/customizableui/test/browser_934951_zoom_in_toolbar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const kTimeoutInMS = 20000;
    1.11 +
    1.12 +// Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate.
    1.13 +add_task(function() {
    1.14 +  CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR);
    1.15 +  let tab1 = gBrowser.addTab("about:mozilla");
    1.16 +  let tab2 = gBrowser.addTab("about:newtab");
    1.17 +  gBrowser.selectedTab = tab1;
    1.18 +  let zoomResetButton = document.getElementById("zoom-reset-button");
    1.19 +
    1.20 +  registerCleanupFunction(() => {
    1.21 +    info("Cleaning up.");
    1.22 +    CustomizableUI.reset();
    1.23 +    gBrowser.removeTab(tab2);
    1.24 +    gBrowser.removeTab(tab1);
    1.25 +  });
    1.26 +
    1.27 +  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
    1.28 +  let zoomChangePromise = promiseObserverNotification("browser-fullZoom:zoomChange");
    1.29 +  FullZoom.enlarge();
    1.30 +  yield zoomChangePromise;
    1.31 +  is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
    1.32 +
    1.33 +  let tabSelectPromise = promiseTabSelect();
    1.34 +  gBrowser.selectedTab = tab2;
    1.35 +  yield tabSelectPromise;
    1.36 +  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:newtab");
    1.37 +
    1.38 +  gBrowser.selectedTab = tab1;
    1.39 +  let zoomResetPromise = promiseObserverNotification("browser-fullZoom:zoomReset");
    1.40 +  FullZoom.reset();
    1.41 +  yield zoomResetPromise;
    1.42 +  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:mozilla");
    1.43 +
    1.44 +  // Test zoom label updates while navigating pages in the same tab.
    1.45 +  FullZoom.enlarge();
    1.46 +  yield zoomChangePromise;
    1.47 +  is(parseInt(zoomResetButton.label, 10), 110, "Zoom is changed to 110% for about:mozilla");
    1.48 +  yield promiseTabLoadEvent(tab1, "about:home");
    1.49 +  is(parseInt(zoomResetButton.label, 10), 100, "Default zoom is 100% for about:home");
    1.50 +  yield promiseTabHistoryNavigation(-1, function() {
    1.51 +    return parseInt(zoomResetButton.label, 10) == 110;
    1.52 +  });
    1.53 +  is(parseInt(zoomResetButton.label, 10), 110, "Zoom is still 110% for about:mozilla");
    1.54 +});
    1.55 +
    1.56 +function promiseObserverNotification(aObserver) {
    1.57 +  let deferred = Promise.defer();
    1.58 +  function notificationCallback(e) {
    1.59 +    Services.obs.removeObserver(notificationCallback, aObserver, false);
    1.60 +    clearTimeout(timeoutId);
    1.61 +    deferred.resolve();
    1.62 +  };
    1.63 +  let timeoutId = setTimeout(() => {
    1.64 +    Services.obs.removeObserver(notificationCallback, aObserver, false);
    1.65 +    deferred.reject("Notification '" + aObserver + "' did not happen within 20 seconds.");
    1.66 +  }, kTimeoutInMS);
    1.67 +  Services.obs.addObserver(notificationCallback, aObserver, false);
    1.68 +  return deferred.promise;
    1.69 +}
    1.70 +
    1.71 +function promiseTabSelect() {
    1.72 +  let deferred = Promise.defer();
    1.73 +  let container = window.gBrowser.tabContainer;
    1.74 +  let timeoutId = setTimeout(() => {
    1.75 +    container.removeEventListener("TabSelect", callback);
    1.76 +    deferred.reject("TabSelect did not happen within 20 seconds");
    1.77 +  }, kTimeoutInMS);
    1.78 +  function callback(e) {
    1.79 +    container.removeEventListener("TabSelect", callback);
    1.80 +    clearTimeout(timeoutId);
    1.81 +    executeSoon(deferred.resolve);
    1.82 +  };
    1.83 +  container.addEventListener("TabSelect", callback);
    1.84 +  return deferred.promise;
    1.85 +}

mercurial