tor-browser

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

head.js (2969B)


      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 /* eslint no-unused-vars: [2, {"vars": "local"}] */
      5 
      6 "use strict";
      7 
      8 // Load the Rule view's test/head.js to make use of its helpers.
      9 // It loads inspector/test/head.js which itself loads inspector/test/shared-head.js
     10 Services.scriptloader.loadSubScript(
     11  "chrome://mochitests/content/browser/devtools/client/inspector/rules/test/head.js",
     12  this
     13 );
     14 
     15 /**
     16 * Get an array of objects with property/value pairs of the CSS declarations rendered
     17 * in the Changes panel.
     18 *
     19 * @param  {Document} panelDoc
     20 *         Host document of the Changes panel.
     21 * @param  {string} selector
     22 *         Optional selector to filter rendered declaration DOM elements.
     23 *         One of ".diff-remove" or ".diff-add".
     24 *         If omitted, all declarations will be returned.
     25 * @param  {DOMNode} containerNode
     26 *         Optional element to restrict results to declaration DOM elements which are
     27 *         descendants of this container node.
     28 *         If omitted, all declarations will be returned
     29 * @return {Array}
     30 */
     31 function getDeclarations(panelDoc, selector = "", containerNode = null) {
     32  const els = panelDoc.querySelectorAll(`.changes__declaration${selector}`);
     33 
     34  return [...els]
     35    .filter(el => {
     36      return containerNode ? containerNode.contains(el) : true;
     37    })
     38    .map(el => {
     39      return {
     40        property: el.querySelector(".changes__declaration-name").textContent,
     41        value: el.querySelector(".changes__declaration-value").textContent,
     42        element: el,
     43      };
     44    });
     45 }
     46 
     47 function getAddedDeclarations(panelDoc, containerNode) {
     48  return getDeclarations(panelDoc, ".diff-add", containerNode);
     49 }
     50 
     51 function getRemovedDeclarations(panelDoc, containerNode) {
     52  return getDeclarations(panelDoc, ".diff-remove", containerNode);
     53 }
     54 
     55 /**
     56 * Get an array of DOM elements for the CSS selectors rendered in the Changes panel.
     57 *
     58 * @param  {Document} panelDoc
     59 *         Host document of the Changes panel.
     60 * @param  {string} selector
     61 *         Optional selector to filter rendered selector DOM elements.
     62 *         One of ".diff-remove" or ".diff-add".
     63 *         If omitted, all selectors will be returned.
     64 * @return {Array}
     65 */
     66 function getSelectors(panelDoc, selector = "") {
     67  return panelDoc.querySelectorAll(`.changes__selector${selector}`);
     68 }
     69 
     70 function getAddedSelectors(panelDoc) {
     71  return getSelectors(panelDoc, ".diff-add");
     72 }
     73 
     74 function getRemovedSelectors(panelDoc) {
     75  return getSelectors(panelDoc, ".diff-remove");
     76 }
     77 
     78 async function getChangesContextMenu(changesView, element) {
     79  const onContextMenu = changesView.contextMenu.once("open");
     80  info(`Trigger context menu for element: ${element}`);
     81  synthesizeContextMenuEvent(element);
     82  info(`Wait for context menu to show`);
     83  await onContextMenu;
     84 
     85  return changesView.contextMenu;
     86 }