tor-browser

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

browser_inspector_highlighter-eyedropper-clipboard.js (2149B)


      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 "use strict";
      5 
      6 // Test that the eyedropper can copy colors to the clipboard
      7 
      8 const { TYPES } = ChromeUtils.importESModule(
      9  "resource://devtools/shared/highlighters.mjs"
     10 );
     11 const HIGHLIGHTER_TYPE = TYPES.EYEDROPPER;
     12 const ID = "eye-dropper-";
     13 const TEST_URI =
     14  "data:text/html;charset=utf-8,<style>html{background:red}</style>";
     15 
     16 add_task(async function () {
     17  const helper = await openInspectorForURL(TEST_URI).then(
     18    getHighlighterHelperFor(HIGHLIGHTER_TYPE)
     19  );
     20  helper.prefix = ID;
     21 
     22  const {
     23    show,
     24    finalize,
     25    waitForElementAttributeSet,
     26    waitForElementAttributeRemoved,
     27  } = helper;
     28 
     29  info("Show the eyedropper with the copyOnSelect option");
     30  await show("html", { copyOnSelect: true });
     31 
     32  info(
     33    "Make sure to wait until the eyedropper is done taking a screenshot of the page"
     34  );
     35  await waitForElementAttributeSet("root", "drawn", helper);
     36 
     37  await waitForClipboardPromise(() => {
     38    info("Activate the eyedropper so the background color is copied");
     39    EventUtils.synthesizeKey("KEY_Enter");
     40  }, "#ff0000");
     41 
     42  ok(true, "The clipboard contains the right value");
     43 
     44  await waitForElementAttributeRemoved("root", "drawn", helper);
     45  await waitForElementAttributeSet("root", "hidden", helper);
     46  ok(true, "The eyedropper is now hidden");
     47 
     48  info("Check that the clipboard still contains the copied color");
     49  is(SpecialPowers.getClipboardData("text/plain"), "#ff0000");
     50 
     51  info("Replace the clipboard content with another text");
     52  SpecialPowers.clipboardCopyString("not-a-color");
     53  is(SpecialPowers.getClipboardData("text/plain"), "not-a-color");
     54 
     55  info("Click on the page again, check the clipboard was not updated");
     56  await BrowserTestUtils.synthesizeMouseAtCenter(
     57    "body",
     58    {},
     59    gBrowser.selectedBrowser
     60  );
     61  // Wait 500ms because nothing is observable when the test is successful.
     62  await wait(500);
     63  is(SpecialPowers.getClipboardData("text/plain"), "not-a-color");
     64 
     65  finalize();
     66 });