tor-browser

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

browser_default_zoom.js (4955B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function test_init_default_zoom() {
      7  const TEST_PAGE_URL =
      8    "data:text/html;charset=utf-8,<body>test_init_default_zoom</body>";
      9 
     10  // Prepare the test tab
     11  info("Creating tab");
     12  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
     13  let tabBrowser = gBrowser.getBrowserForTab(tab);
     14  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);
     15 
     16  // 100% global zoom
     17  info("Getting default zoom");
     18  let defaultZoom = await FullZoomHelper.getGlobalValue();
     19  is(defaultZoom, 1, "Global zoom is init at 100%");
     20  // 100% tab zoom
     21  is(
     22    ZoomManager.getZoomForBrowser(tabBrowser),
     23    1,
     24    "Current zoom is init at 100%"
     25  );
     26  info("Removing tab");
     27  await FullZoomHelper.removeTabAndWaitForLocationChange();
     28 });
     29 
     30 add_task(async function test_set_default_zoom() {
     31  const TEST_PAGE_URL =
     32    "data:text/html;charset=utf-8,<body>test_set_default_zoom</body>";
     33 
     34  // Prepare the test tab
     35  info("Creating tab");
     36  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
     37  let tabBrowser = gBrowser.getBrowserForTab(tab);
     38  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);
     39 
     40  // 120% global zoom
     41  info("Changing default zoom");
     42  await FullZoomHelper.changeDefaultZoom(120);
     43  let defaultZoom = await FullZoomHelper.getGlobalValue();
     44  is(defaultZoom, 1.2, "Global zoom is at 120%");
     45 
     46  // 120% tab zoom
     47  await TestUtils.waitForCondition(() => {
     48    info("Current zoom is: " + ZoomManager.getZoomForBrowser(tabBrowser));
     49    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
     50  });
     51  is(
     52    ZoomManager.getZoomForBrowser(tabBrowser),
     53    1.2,
     54    "Current zoom matches changed default zoom"
     55  );
     56  info("Removing tab");
     57  await FullZoomHelper.removeTabAndWaitForLocationChange();
     58  await FullZoomHelper.changeDefaultZoom(100);
     59 });
     60 
     61 add_task(async function test_enlarge_reduce_reset_local_zoom() {
     62  const TEST_PAGE_URL =
     63    "data:text/html;charset=utf-8,<body>test_enlarge_reduce_reset_local_zoom</body>";
     64 
     65  // Prepare the test tab
     66  info("Creating tab");
     67  let tab = BrowserTestUtils.addTab(gBrowser, TEST_PAGE_URL);
     68  let tabBrowser = gBrowser.getBrowserForTab(tab);
     69  await FullZoomHelper.selectTabAndWaitForLocationChange(tab);
     70 
     71  // 120% global zoom
     72  info("Changing default zoom");
     73  await FullZoomHelper.changeDefaultZoom(120);
     74  let defaultZoom = await FullZoomHelper.getGlobalValue();
     75  is(defaultZoom, 1.2, "Global zoom is at 120%");
     76 
     77  await TestUtils.waitForCondition(() => {
     78    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
     79    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
     80  });
     81  is(
     82    ZoomManager.getZoomForBrowser(tabBrowser),
     83    1.2,
     84    "Current tab zoom matches default zoom"
     85  );
     86 
     87  await FullZoom.enlarge();
     88  info("Enlarged!");
     89  defaultZoom = await FullZoomHelper.getGlobalValue();
     90  info("Current global zoom is " + defaultZoom);
     91 
     92  // 133% tab zoom
     93  await TestUtils.waitForCondition(() => {
     94    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
     95    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.33;
     96  });
     97  is(
     98    ZoomManager.getZoomForBrowser(tabBrowser),
     99    1.33,
    100    "Increasing zoom changes zoom of current tab."
    101  );
    102  defaultZoom = await FullZoomHelper.getGlobalValue();
    103  // 120% global zoom
    104  is(
    105    defaultZoom,
    106    1.2,
    107    "Increasing zoom of current tab doesn't change default zoom."
    108  );
    109  info("Reducing...");
    110  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    111  await FullZoom.reduce(); // 120% tab zoom
    112  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    113  await FullZoom.reduce(); // 110% tab zoom
    114  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    115  await FullZoom.reduce(); // 100% tab zoom
    116  info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    117 
    118  await TestUtils.waitForCondition(() => {
    119    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    120    return ZoomManager.getZoomForBrowser(tabBrowser) == 1;
    121  });
    122  is(
    123    ZoomManager.getZoomForBrowser(tabBrowser),
    124    1,
    125    "Decreasing zoom changes zoom of current tab."
    126  );
    127  defaultZoom = await FullZoomHelper.getGlobalValue();
    128  // 120% global zoom
    129  is(
    130    defaultZoom,
    131    1.2,
    132    "Decreasing zoom of current tab doesn't change default zoom."
    133  );
    134  info("Resetting...");
    135  FullZoom.reset(); // 120% tab zoom
    136  await TestUtils.waitForCondition(() => {
    137    info("Current tab zoom is ", ZoomManager.getZoomForBrowser(tabBrowser));
    138    return ZoomManager.getZoomForBrowser(tabBrowser) == 1.2;
    139  });
    140  is(
    141    ZoomManager.getZoomForBrowser(tabBrowser),
    142    1.2,
    143    "Reseting zoom causes current tab to zoom to default zoom."
    144  );
    145 
    146  // no reset necessary, it was performed as part of the test
    147  info("Removing tab");
    148  await FullZoomHelper.removeTabAndWaitForLocationChange();
    149 });