tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_934951_zoom_in_toolbar.js (2641B)


      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/. */
      4 /* eslint-disable mozilla/no-arbitrary-setTimeout */
      5 
      6 "use strict";
      7 
      8 let gZoomResetButton;
      9 
     10 async function waitForZoom(zoom) {
     11  if (parseInt(gZoomResetButton.label) == zoom) {
     12    return;
     13  }
     14  await promiseAttributeMutation(gZoomResetButton, "label", v => {
     15    return parseInt(v) == zoom;
     16  });
     17 }
     18 
     19 // Bug 934951 - Zoom controls percentage label doesn't update when it's in the toolbar and you navigate.
     20 add_task(async function () {
     21  CustomizableUI.addWidgetToArea("zoom-controls", CustomizableUI.AREA_NAVBAR);
     22  gZoomResetButton = document.getElementById("zoom-reset-button");
     23  let tab1 = BrowserTestUtils.addTab(gBrowser, "about:mozilla");
     24  await BrowserTestUtils.browserLoaded(tab1.linkedBrowser);
     25  let tab2 = BrowserTestUtils.addTab(gBrowser, "about:robots");
     26  await BrowserTestUtils.browserLoaded(tab2.linkedBrowser);
     27  gBrowser.selectedTab = tab1;
     28 
     29  registerCleanupFunction(() => {
     30    info("Cleaning up.");
     31    CustomizableUI.reset();
     32    gBrowser.removeTab(tab2);
     33    gBrowser.removeTab(tab1);
     34  });
     35 
     36  is(
     37    parseInt(gZoomResetButton.label, 10),
     38    100,
     39    "Default zoom is 100% for about:mozilla"
     40  );
     41  FullZoom.enlarge();
     42  await waitForZoom(110);
     43  is(
     44    parseInt(gZoomResetButton.label, 10),
     45    110,
     46    "Zoom is changed to 110% for about:mozilla"
     47  );
     48 
     49  let tabSelectPromise = TestUtils.topicObserved(
     50    "browser-fullZoom:location-change"
     51  );
     52  gBrowser.selectedTab = tab2;
     53  await tabSelectPromise;
     54  await waitForZoom(100);
     55  is(
     56    parseInt(gZoomResetButton.label, 10),
     57    100,
     58    "Default zoom is 100% for about:robots"
     59  );
     60 
     61  gBrowser.selectedTab = tab1;
     62  await waitForZoom(110);
     63  FullZoom.reset();
     64  await waitForZoom(100);
     65  is(
     66    parseInt(gZoomResetButton.label, 10),
     67    100,
     68    "Default zoom is 100% for about:mozilla"
     69  );
     70 
     71  // Test zoom label updates while navigating pages in the same tab.
     72  FullZoom.enlarge();
     73  await waitForZoom(110);
     74  is(
     75    parseInt(gZoomResetButton.label, 10),
     76    110,
     77    "Zoom is changed to 110% for about:mozilla"
     78  );
     79  await BrowserTestUtils.loadURIString({
     80    browser: tab1.linkedBrowser,
     81    uriString: "about:home",
     82  });
     83  await waitForZoom(100);
     84  is(
     85    parseInt(gZoomResetButton.label, 10),
     86    100,
     87    "Default zoom is 100% for about:home"
     88  );
     89  gBrowser.selectedBrowser.goBack();
     90  await waitForZoom(110);
     91  is(
     92    parseInt(gZoomResetButton.label, 10),
     93    110,
     94    "Zoom is still 110% for about:mozilla"
     95  );
     96  FullZoom.reset();
     97 });