tor-browser

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

browser_navigator_clipboard_touch.js (3417B)


      1 /* -*- Mode: JavaScript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 "use strict";
      8 
      9 const kContentFileUrl =
     10  kBaseUrlForContent + "simple_navigator_clipboard_readText.html";
     11 
     12 // @param aBrowser browser object of the content tab.
     13 // @param aContentElementId the ID of the element to be tapped.
     14 function promiseTouchTapContent(aBrowser, aContentElementId) {
     15  return SpecialPowers.spawn(
     16    aBrowser,
     17    [aContentElementId],
     18    async _contentElementId => {
     19      await content.wrappedJSObject.waitUntilApzStable();
     20 
     21      const contentElement = content.document.getElementById(_contentElementId);
     22      let promise = new Promise(resolve => {
     23        contentElement.addEventListener(
     24          "click",
     25          function (e) {
     26            resolve({ x: e.screenX, y: e.screenY });
     27          },
     28          { once: true }
     29        );
     30      });
     31 
     32      EventUtils.synthesizeTouchAtCenter(
     33        contentElement,
     34        { asyncEnabled: true },
     35        content.window
     36      );
     37 
     38      return promise;
     39    }
     40  );
     41 }
     42 
     43 add_task(async function test_paste_button_position_touch() {
     44  // Ensure there's text on the clipboard.
     45  await promiseWritingRandomTextToClipboard();
     46 
     47  await BrowserTestUtils.withNewTab(kContentFileUrl, async function (browser) {
     48    const pasteButtonIsShown = promisePasteButtonIsShown();
     49    const coordsOfClickInContentRelativeToScreenInDevicePixels =
     50      await promiseTouchTapContent(browser, "invokeReadTextOnceId");
     51    info(
     52      "coordsOfClickInContentRelativeToScreenInDevicePixels: " +
     53        coordsOfClickInContentRelativeToScreenInDevicePixels.x +
     54        ", " +
     55        coordsOfClickInContentRelativeToScreenInDevicePixels.y
     56    );
     57 
     58    const pasteButtonCoordsRelativeToScreenInDevicePixels =
     59      await pasteButtonIsShown;
     60    info(
     61      "pasteButtonCoordsRelativeToScreenInDevicePixels: " +
     62        pasteButtonCoordsRelativeToScreenInDevicePixels.x +
     63        ", " +
     64        pasteButtonCoordsRelativeToScreenInDevicePixels.y
     65    );
     66 
     67    const mouseCoordsRelativeToScreenInDevicePixels =
     68      getMouseCoordsRelativeToScreenInDevicePixels();
     69    info(
     70      "mouseCoordsRelativeToScreenInDevicePixels: " +
     71        mouseCoordsRelativeToScreenInDevicePixels.x +
     72        ", " +
     73        mouseCoordsRelativeToScreenInDevicePixels.y
     74    );
     75 
     76    // Asserting not overlapping is important; otherwise, when the
     77    // "Paste" button is shown via a `mousedown` event, the following
     78    // `mouseup` event could accept the "Paste" button unnoticed by the
     79    // user.
     80    ok(
     81      isCloselyLeftOnTopOf(
     82        mouseCoordsRelativeToScreenInDevicePixels,
     83        pasteButtonCoordsRelativeToScreenInDevicePixels
     84      ),
     85      "'Paste' button is closely left on top of the mouse pointer."
     86    );
     87    ok(
     88      isCloselyLeftOnTopOf(
     89        coordsOfClickInContentRelativeToScreenInDevicePixels,
     90        pasteButtonCoordsRelativeToScreenInDevicePixels
     91      ),
     92      "Coords of click in content are closely left on top of the 'Paste' button."
     93    );
     94 
     95    // To avoid disturbing subsequent tests.
     96    const pasteButtonIsHidden = promisePasteButtonIsHidden();
     97    await promiseClickPasteButton();
     98    await pasteButtonIsHidden;
     99  });
    100 });