tor-browser

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

browser_947914_button_copy.js (1887B)


      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 var initialLocation = gBrowser.currentURI.spec;
      8 var globalClipboard;
      9 
     10 add_setup(async function () {
     11  await SpecialPowers.pushPrefEnv({
     12    set: [["test.wait300msAfterTabSwitch", true]],
     13  });
     14 });
     15 
     16 add_task(async function () {
     17  await BrowserTestUtils.withNewTab(
     18    { gBrowser, url: "about:blank" },
     19    async function () {
     20      info("Check copy button existence and functionality");
     21      CustomizableUI.addWidgetToArea(
     22        "edit-controls",
     23        CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     24      );
     25 
     26      await waitForOverflowButtonShown();
     27 
     28      let testText = "copy text test";
     29 
     30      gURLBar.focus();
     31      info("The URL bar was focused");
     32      await document.getElementById("nav-bar").overflowable.show();
     33      info("Menu panel was opened");
     34 
     35      let copyButton = document.getElementById("copy-button");
     36      ok(copyButton, "Copy button exists in Panel Menu");
     37      ok(
     38        copyButton.getAttribute("disabled"),
     39        "Copy button is initially disabled"
     40      );
     41 
     42      // copy text from URL bar
     43      gURLBar.value = testText;
     44      gURLBar.valueIsTyped = true;
     45      gURLBar.focus();
     46      gURLBar.select();
     47      await document.getElementById("nav-bar").overflowable.show();
     48      info("Menu panel was opened");
     49 
     50      ok(
     51        !copyButton.hasAttribute("disabled"),
     52        "Copy button is enabled when selecting"
     53      );
     54 
     55      await SimpleTest.promiseClipboardChange(testText, () => {
     56        copyButton.click();
     57      });
     58 
     59      is(
     60        gURLBar.value,
     61        testText,
     62        "Selected text is unaltered when clicking copy"
     63      );
     64    }
     65  );
     66 });
     67 
     68 registerCleanupFunction(function cleanup() {
     69  CustomizableUI.reset();
     70 });