tor-browser

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

browser_console_content_object_context_menu.js (2387B)


      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 // Test that "Copy Object" on a the content message works in the browser console.
      6 
      7 "use strict";
      8 
      9 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8>console API calls<script>
     10  console.log({
     11    contentObject: "YAY!",
     12    deep: ["hello", "world"]
     13  });
     14 </script>`;
     15 
     16 add_task(async function () {
     17  // Show the content messages
     18  await pushPref("devtools.browsertoolbox.scope", "everything");
     19 
     20  await addTab(TEST_URI);
     21 
     22  info("Open the Browser Console");
     23  const hud = await BrowserConsoleManager.toggleBrowserConsole();
     24 
     25  info("Wait until the content object is displayed");
     26  const objectMessage = await waitFor(() =>
     27    findConsoleAPIMessage(
     28      hud,
     29      `Object { contentObject: "YAY!", deep: (2) […] }`
     30    )
     31  );
     32  ok(true, "Content object is displayed in the Browser Console");
     33 
     34  info("Expand the object");
     35  const oi = objectMessage.querySelector(".tree");
     36  oi.querySelector(".theme-twisty").click();
     37  // The object inspector now looks like:
     38  // ▼ Object { contentObject: "YAY!", deep: (1) […] }
     39  // |  contentObject: "YAY!"
     40  // |  ▶︎ deep: Array [ "hello", "world" ]
     41  // |  ▶︎ <prototype>
     42 
     43  await waitFor(() => oi.querySelectorAll(".node").length === 4);
     44  ok(true, "The ObjectInspector was expanded");
     45  oi.scrollIntoView();
     46 
     47  info("Check that the object can be copied to clipboard");
     48  await testCopyObject(
     49    hud,
     50    oi.querySelector(".objectBox-object"),
     51    JSON.stringify({ contentObject: "YAY!", deep: ["hello", "world"] }, null, 2)
     52  );
     53 
     54  info("Check that inner object can be copied to clipboard");
     55  await testCopyObject(
     56    hud,
     57    oi.querySelectorAll(".node")[2].querySelector(".objectBox-array"),
     58    JSON.stringify(["hello", "world"], null, 2)
     59  );
     60 });
     61 
     62 async function testCopyObject(hud, element, expected) {
     63  info("Check `Copy object` is enabled");
     64  const menuPopup = await openContextMenu(hud, element);
     65  const copyObjectMenuItem = menuPopup.querySelector(
     66    "#console-menu-copy-object"
     67  );
     68  ok(!copyObjectMenuItem.disabled, "`Copy object` is enabled");
     69 
     70  info("Click on `Copy object`");
     71  await waitForClipboardPromise(() => copyObjectMenuItem.click(), expected);
     72  await hideContextMenu(hud);
     73 }