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