tor-browser

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

browser_test_zoom.js (4252B)


      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 
      5 "use strict";
      6 
      7 /* import-globals-from ../../mochitest/layout.js */
      8 
      9 Services.scriptloader.loadSubScript(
     10  "chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
     11  this
     12 );
     13 
     14 async function testContentBounds(browser, acc) {
     15  let [expectedX, expectedY, expectedWidth, expectedHeight] =
     16    await getContentBoundsForDOMElm(browser, getAccessibleDOMNodeID(acc));
     17 
     18  let contentDPR = await getContentDPR(browser);
     19  let [x, y, width, height] = getBounds(acc, contentDPR);
     20  let prettyAccName = prettyName(acc);
     21  is(x, expectedX, "Wrong x coordinate of " + prettyAccName);
     22  is(y, expectedY, "Wrong y coordinate of " + prettyAccName);
     23  is(width, expectedWidth, "Wrong width of " + prettyAccName);
     24  Assert.greaterOrEqual(
     25    height,
     26    expectedHeight,
     27    "Wrong height of " + prettyAccName
     28  );
     29 }
     30 
     31 async function runTests(browser, accDoc) {
     32  let p1 = findAccessibleChildByID(accDoc, "p1");
     33  let p2 = findAccessibleChildByID(accDoc, "p2");
     34  let imgmap = findAccessibleChildByID(accDoc, "imgmap");
     35  if (!imgmap.childCount) {
     36    // An image map may not be available even after the doc and image load
     37    // is complete. We don't recieve any DOM events for this change either,
     38    // so we need to wait for a REORDER.
     39    await waitForEvent(EVENT_REORDER, "imgmap");
     40  }
     41  let area = imgmap.firstChild;
     42 
     43  await testContentBounds(browser, p1);
     44  await testContentBounds(browser, p2);
     45  await testContentBounds(browser, area);
     46 
     47  await SpecialPowers.spawn(browser, [], () => {
     48    const { Layout } = ChromeUtils.importESModule(
     49      "chrome://mochitests/content/browser/accessible/tests/browser/Layout.sys.mjs"
     50    );
     51    Layout.zoomDocument(content.document, 2.0);
     52  });
     53 
     54  await testContentBounds(browser, p1);
     55  await testContentBounds(browser, p2);
     56  await testContentBounds(browser, area);
     57 }
     58 
     59 /**
     60 * Test accessible boundaries when page is zoomed
     61 */
     62 addAccessibleTask(
     63  `
     64 <p id="p1">para 1</p><p id="p2">para 2</p>
     65 <map name="atoz_map" id="map">
     66  <area id="area1" href="http://mozilla.org"
     67        coords=17,0,30,14" alt="mozilla.org" shape="rect">
     68 </map>
     69 <img id="imgmap" width="447" height="15"
     70     usemap="#atoz_map"
     71     src="http://example.com/a11y/accessible/tests/mochitest/letters.gif">`,
     72  runTests,
     73  { iframe: true, remoteIframe: true }
     74 );
     75 
     76 /**
     77 * Test accessible bounds after APZ.
     78 */
     79 addAccessibleTask(
     80  `
     81  <div id="test" style="background:green; height: 100px; width: 100px;">I am square</div>
     82  `,
     83  async function (browser, accDoc) {
     84    const test = findAccessibleChildByID(accDoc, "test");
     85 
     86    info("Verifying initial bounds");
     87    await testContentBounds(browser, test, 100, 100);
     88    let contentDPR = await getContentDPR(browser);
     89    const [, , width, height] = getBounds(test, contentDPR);
     90 
     91    info("Pinch zooming...");
     92    await SpecialPowers.spawn(browser, [], async () => {
     93      const visualScrollPromise = new Promise(resolve => {
     94        content.window.visualViewport.addEventListener("scroll", resolve, {
     95          once: true,
     96        });
     97      });
     98      const utils = SpecialPowers.getDOMWindowUtils(content.window);
     99      utils.setResolutionAndScaleTo(2);
    100      utils.scrollToVisual(
    101        200,
    102        200,
    103        utils.UPDATE_TYPE_MAIN_THREAD,
    104        utils.SCROLL_MODE_INSTANT
    105      );
    106      await visualScrollPromise;
    107    });
    108 
    109    info("Verifying scaled bounds");
    110    contentDPR = await getContentDPR(browser);
    111    const [newX, newY, newWidth, newHeight] = getBounds(test, contentDPR);
    112    // We pinch zoom to the right of the square,
    113    // which means its coords become off-screen
    114    // (negative).
    115    Assert.less(newX, 0, "X coord should be smaller than 0");
    116    Assert.less(newY, 0, "Y coord should be smaller than 0");
    117    // Because we zoomed in, width and height should
    118    // be larger than they were before.
    119    Assert.greater(newWidth, width, "Width should be larger than old width");
    120    Assert.greater(
    121      newHeight,
    122      height,
    123      "Height should be larger than old height"
    124    );
    125  },
    126  { iframe: true, remoteIframe: true }
    127 );