tor-browser

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

browser_viewport_zoom_toggle.js (3075B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Verify full zoom levels inherit RDM full zoom after exiting RDM.
      7 
      8 const TEST_URL = "https://example.com/";
      9 
     10 function getZoomForBrowser(browser) {
     11  return ZoomManager.getZoomForBrowser(browser);
     12 }
     13 
     14 function setZoomForBrowser(browser, zoom) {
     15  ZoomManager.setZoomForBrowser(browser, zoom);
     16 }
     17 
     18 addRDMTask(
     19  null,
     20  async function () {
     21    const INITIAL_ZOOM_LEVEL = 1;
     22    const PRE_RDM_ZOOM_LEVEL = 1.5;
     23    const MID_RDM_ZOOM_LEVEL = 2;
     24 
     25    const tab = await addTab(TEST_URL);
     26    const browser = tab.linkedBrowser;
     27 
     28    await navigateTo(TEST_URL);
     29 
     30    // Get the initial zoom level.
     31    const initialOuterZoom = getZoomForBrowser(browser);
     32    is(
     33      initialOuterZoom,
     34      INITIAL_ZOOM_LEVEL,
     35      "Initial outer zoom should be " + INITIAL_ZOOM_LEVEL + "."
     36    );
     37 
     38    // Change the zoom level before we open RDM.
     39    setZoomForBrowser(browser, PRE_RDM_ZOOM_LEVEL);
     40 
     41    const preRDMOuterZoom = getZoomForBrowser(browser);
     42    is(
     43      preRDMOuterZoom,
     44      PRE_RDM_ZOOM_LEVEL,
     45      "Pre-RDM outer zoom should be " + PRE_RDM_ZOOM_LEVEL + "."
     46    );
     47 
     48    // Start RDM on the tab. This will fundamentally change the way that browser behaves.
     49    // It will now pass all of its messages through to the RDM docshell, meaning that when
     50    // we request zoom level from it now, we are getting the RDM zoom level.
     51    const { ui } = await openRDM(tab);
     52    await waitForDeviceAndViewportState(ui);
     53 
     54    const uiDocShell = ui.toolWindow.docShell;
     55 
     56    // Bug 1541692: openRDM behaves differently in the test harness than it does
     57    // interactively. Interactively, many features of the container docShell -- including
     58    // zoom -- are copied over to the RDM browser. In the test harness, this seems to first
     59    // reset the docShell before toggling RDM, which makes checking the initial zoom of the
     60    // RDM pane not useful.
     61 
     62    const preZoomUIZoom = uiDocShell.browsingContext.fullZoom;
     63    is(
     64      preZoomUIZoom,
     65      INITIAL_ZOOM_LEVEL,
     66      "Pre-zoom UI zoom should be " + INITIAL_ZOOM_LEVEL + "."
     67    );
     68 
     69    // Set the zoom level. This should tunnel to the inner browser and leave the UI alone.
     70    setZoomForBrowser(browser, MID_RDM_ZOOM_LEVEL);
     71 
     72    // The UI zoom should be unchanged by this.
     73    const postZoomUIZoom = uiDocShell.browsingContext.fullZoom;
     74    is(
     75      postZoomUIZoom,
     76      preZoomUIZoom,
     77      "UI zoom should be unchanged by RDM zoom."
     78    );
     79 
     80    // The RDM zoom should be changed.
     81    const finalRDMZoom = getZoomForBrowser(browser);
     82    is(
     83      finalRDMZoom,
     84      MID_RDM_ZOOM_LEVEL,
     85      "RDM zoom should be " + MID_RDM_ZOOM_LEVEL + "."
     86    );
     87 
     88    // Leave RDM. This should cause the outer pane to take on the full zoom of the RDM pane.
     89    await closeRDM(tab);
     90 
     91    const finalOuterZoom = getZoomForBrowser(browser);
     92    is(
     93      finalOuterZoom,
     94      finalRDMZoom,
     95      "Final outer zoom should match last RDM zoom."
     96    );
     97 
     98    await removeTab(tab);
     99  },
    100  { onlyPrefAndTask: true }
    101 );