tor-browser

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

browser_navigator_clipboard_contextmenu_dismiss.js (4121B)


      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 = kBaseUrlForContent + "file_toplevel.html";
     10 
     11 async function readText(aBrowser) {
     12  return SpecialPowers.spawn(aBrowser, [], () => {
     13    content.document.notifyUserGestureActivation();
     14    content.eval(`navigator.clipboard.readText();`);
     15  });
     16 }
     17 
     18 add_task(async function test_context_menu_dimiss_tab_close() {
     19  let pasteButtonIsHidden;
     20  await BrowserTestUtils.withNewTab(kContentFileUrl, async aBrowser => {
     21    info(`Randomized text to avoid overlappings with other tests`);
     22    await promiseWritingRandomTextToClipboard();
     23 
     24    info(`Wait for paste context menu is shown`);
     25    let pasteButtonIsShown = promisePasteButtonIsShown();
     26    let readTextRequest = readText(aBrowser);
     27    await pasteButtonIsShown;
     28 
     29    pasteButtonIsHidden = promisePasteButtonIsHidden();
     30    info("Close tab");
     31  });
     32 
     33  info(`Wait for paste context menu is hidden`);
     34  await pasteButtonIsHidden;
     35 });
     36 
     37 add_task(async function test_context_menu_dimiss_tab_switch() {
     38  await BrowserTestUtils.withNewTab(kContentFileUrl, async aBrowser => {
     39    info(`Randomized text to avoid overlappings with other tests`);
     40    await promiseWritingRandomTextToClipboard();
     41 
     42    info(`Wait for paste context menu is shown`);
     43    let pasteButtonIsShown = promisePasteButtonIsShown();
     44    await readText(aBrowser);
     45    await pasteButtonIsShown;
     46 
     47    info("Switch tab");
     48    let pasteButtonIsHidden = promisePasteButtonIsHidden();
     49    let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
     50 
     51    info(`Wait for paste context menu is hidden`);
     52    await pasteButtonIsHidden;
     53 
     54    BrowserTestUtils.removeTab(tab);
     55  });
     56 });
     57 
     58 add_task(async function test_context_menu_dimiss_browser_window_switch() {
     59  await BrowserTestUtils.withNewTab(kContentFileUrl, async aBrowser => {
     60    info(`Randomized text to avoid overlappings with other tests`);
     61    await promiseWritingRandomTextToClipboard();
     62 
     63    info(`Wait for paste context menu is shown`);
     64    let pasteButtonIsShown = promisePasteButtonIsShown();
     65    await readText(aBrowser);
     66    await pasteButtonIsShown;
     67 
     68    info("Switch browser window");
     69    let pasteButtonIsHidden = promisePasteButtonIsHidden();
     70    let newWin = await BrowserTestUtils.openNewBrowserWindow();
     71 
     72    info(`Wait for paste context menu is hidden`);
     73    await pasteButtonIsHidden;
     74 
     75    await BrowserTestUtils.closeWindow(newWin);
     76  });
     77 });
     78 
     79 add_task(async function test_context_menu_dimiss_tab_navigate() {
     80  await BrowserTestUtils.withNewTab(kContentFileUrl, async aBrowser => {
     81    info(`Randomized text to avoid overlappings with other tests`);
     82    await promiseWritingRandomTextToClipboard();
     83 
     84    info(`Wait for paste context menu is shown`);
     85    let pasteButtonIsShown = promisePasteButtonIsShown();
     86    await readText(aBrowser);
     87    await pasteButtonIsShown;
     88 
     89    info("Navigate tab");
     90    let pasteButtonIsHidden = promisePasteButtonIsHidden();
     91    aBrowser.loadURI(Services.io.newURI("https://example.com/"), {
     92      triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
     93    });
     94 
     95    info(`Wait for paste context menu is hidden`);
     96    await pasteButtonIsHidden;
     97  });
     98 });
     99 
    100 add_task(async function test_context_menu_dimiss_tab_reload() {
    101  await BrowserTestUtils.withNewTab(kContentFileUrl, async aBrowser => {
    102    info(`Randomized text to avoid overlappings with other tests`);
    103    await promiseWritingRandomTextToClipboard();
    104 
    105    info(`Wait for paste context menu is shown`);
    106    let pasteButtonIsShown = promisePasteButtonIsShown();
    107    await readText(aBrowser);
    108    await pasteButtonIsShown;
    109 
    110    info("Reload tab");
    111    let pasteButtonIsHidden = promisePasteButtonIsHidden();
    112    await BrowserTestUtils.reloadTab(gBrowser.selectedTab);
    113 
    114    info(`Wait for paste context menu is hidden`);
    115    await pasteButtonIsHidden;
    116  });
    117 });