tor-browser

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

browser_inspector_menu-03-paste-items-svg.js (1740B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 // Test that HTML can be pasted in SVG elements.
      6 
      7 const TEST_URL = URL_ROOT + "doc_inspector_svg.svg";
      8 const PASTE_AS_FIRST_CHILD =
      9  '<circle xmlns="http://www.w3.org/2000/svg" cx="42" cy="42" r="5"/>';
     10 const PASTE_AS_LAST_CHILD =
     11  '<circle xmlns="http://www.w3.org/2000/svg" cx="42" cy="42" r="15"/>';
     12 
     13 add_task(async function () {
     14  const clipboard = require("resource://devtools/shared/platform/clipboard.js");
     15 
     16  const { inspector } = await openInspectorForURL(TEST_URL);
     17 
     18  const refSelector = "svg";
     19  const oldHTML = await getContentPageElementProperty(refSelector, "innerHTML");
     20  await selectNode(refSelector, inspector);
     21  const markupTagLine = getContainerForSelector(refSelector, inspector).tagLine;
     22 
     23  await pasteContent("node-menu-pastefirstchild", PASTE_AS_FIRST_CHILD);
     24  await pasteContent("node-menu-pastelastchild", PASTE_AS_LAST_CHILD);
     25 
     26  const html = await getContentPageElementProperty(refSelector, "innerHTML");
     27  const expectedHtml = PASTE_AS_FIRST_CHILD + oldHTML + PASTE_AS_LAST_CHILD;
     28  is(html, expectedHtml, "The innerHTML of the SVG node is correct");
     29 
     30  // Helpers
     31  async function pasteContent(menuId, clipboardData) {
     32    const allMenuItems = openContextMenuAndGetAllItems(inspector, {
     33      target: markupTagLine,
     34    });
     35    info(`Testing ${menuId} for ${clipboardData}`);
     36 
     37    await SimpleTest.promiseClipboardChange(clipboardData, () => {
     38      clipboard.copyString(clipboardData);
     39    });
     40 
     41    const onMutation = inspector.once("markupmutation");
     42    allMenuItems.find(item => item.id === menuId).click();
     43    info("Waiting for mutation to occur");
     44    await onMutation;
     45  }
     46 });