tor-browser

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

browser_947914_button_paste.js (1803B)


      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      CustomizableUI.addWidgetToArea(
     21        "edit-controls",
     22        CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
     23      );
     24      info("Check paste button existence and functionality");
     25 
     26      let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(
     27        Ci.nsIClipboardHelper
     28      );
     29      globalClipboard = Services.clipboard.kGlobalClipboard;
     30 
     31      await waitForOverflowButtonShown();
     32 
     33      await document.getElementById("nav-bar").overflowable.show();
     34      info("Menu panel was opened");
     35 
     36      let pasteButton = document.getElementById("paste-button");
     37      ok(pasteButton, "Paste button exists in Panel Menu");
     38 
     39      // add text to clipboard
     40      let text = "Sample text for testing";
     41      clipboard.copyString(text);
     42 
     43      // test paste button by pasting text to URL bar
     44      gURLBar.focus();
     45      await gCUITestUtils.openMainMenu();
     46      info("Menu panel was opened");
     47 
     48      ok(!pasteButton.hasAttribute("disabled"), "Paste button is enabled");
     49      pasteButton.click();
     50 
     51      is(gURLBar.value, text, "Text pasted successfully");
     52 
     53      await gCUITestUtils.hideMainMenu();
     54    }
     55  );
     56 });
     57 
     58 registerCleanupFunction(function cleanup() {
     59  CustomizableUI.reset();
     60  Services.clipboard.emptyClipboard(globalClipboard);
     61 });