Bug 1494162 - Part 19: Directly import getCssPath, getXpath and findCssSelector. r=pbro
☠☠ backed out by be070bf5d08a ☠ ☠
authorGabriel Luong <gabriel.luong@gmail.com>
Sat, 29 Sep 2018 15:25:34 -0400
changeset 494649 d3fd96af0ca264b2637b88107420070ea9400700
parent 494648 f1dcdcc1674b19b6384f7354c4ac8a0f6896a1e5
child 494650 3039bfc0e2707fa57523756d29de73703baccd59
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1494162
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1494162 - Part 19: Directly import getCssPath, getXpath and findCssSelector. r=pbro
devtools/server/actors/inspector/node.js
devtools/server/actors/thread.js
devtools/shared/inspector/css-logic.js
devtools/shared/tests/mochitest/test_css-logic-getCssPath.html
devtools/shared/tests/mochitest/test_css-logic-getXPath.html
--- a/devtools/server/actors/inspector/node.js
+++ b/devtools/server/actors/inspector/node.js
@@ -7,19 +7,19 @@
 const { Cu } = require("chrome");
 const Services = require("Services");
 const InspectorUtils = require("InspectorUtils");
 const protocol = require("devtools/shared/protocol");
 const { nodeSpec, nodeListSpec } = require("devtools/shared/specs/node");
 
 loader.lazyRequireGetter(this, "colorUtils", "devtools/shared/css/color", true);
 
-loader.lazyRequireGetter(this, "getCssPath", "devtools/shared/inspector/css-logic", true);
-loader.lazyRequireGetter(this, "getXPath", "devtools/shared/inspector/css-logic", true);
-loader.lazyRequireGetter(this, "findCssSelector", "devtools/shared/inspector/css-logic", true);
+loader.lazyRequireGetter(this, "getCssPath", "resource://gre/modules/css-selector", true);
+loader.lazyRequireGetter(this, "getXPath", "resource://gre/modules/css-selector", true);
+loader.lazyRequireGetter(this, "findCssSelector", "resource://gre/modules/css-selector", true);
 
 loader.lazyRequireGetter(this, "isAfterPseudoElement", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isAnonymous", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isBeforePseudoElement", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isDirectShadowHostChild", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isNativeAnonymous", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isShadowAnonymous", "devtools/shared/layout/utils", true);
 loader.lazyRequireGetter(this, "isShadowHost", "devtools/shared/layout/utils", true);
--- a/devtools/server/actors/thread.js
+++ b/devtools/server/actors/thread.js
@@ -13,17 +13,17 @@ const { createValueGrip } = require("dev
 const { longStringGrip } = require("devtools/server/actors/object/long-string");
 const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const flags = require("devtools/shared/flags");
 const { assert, dumpn } = DevToolsUtils;
 const { DevToolsWorker } = require("devtools/shared/worker/worker");
 const { threadSpec } = require("devtools/shared/specs/script");
 
-loader.lazyRequireGetter(this, "findCssSelector", "devtools/shared/inspector/css-logic", true);
+loader.lazyRequireGetter(this, "findCssSelector", "resource://gre/modules/css-selector", true);
 loader.lazyRequireGetter(this, "BreakpointActor", "devtools/server/actors/breakpoint", true);
 loader.lazyRequireGetter(this, "setBreakpointAtEntryPoints", "devtools/server/actors/breakpoint", true);
 loader.lazyRequireGetter(this, "EnvironmentActor", "devtools/server/actors/environment", true);
 loader.lazyRequireGetter(this, "SourceActorStore", "devtools/server/actors/utils/source-actor-store", true);
 loader.lazyRequireGetter(this, "BreakpointActorMap", "devtools/server/actors/utils/breakpoint-actor-map", true);
 loader.lazyRequireGetter(this, "PauseScopedObjectActor", "devtools/server/actors/pause-scoped", true);
 loader.lazyRequireGetter(this, "EventLoopStack", "devtools/server/actors/utils/event-loop", true);
 loader.lazyRequireGetter(this, "FrameActor", "devtools/server/actors/frame", true);
--- a/devtools/shared/inspector/css-logic.js
+++ b/devtools/shared/inspector/css-logic.js
@@ -41,19 +41,16 @@ const MAX_DATA_URL_LENGTH = 40;
  * that helps them understand:
  * - why their expectations may not have been fulfilled
  * - how browsers process CSS
  * @constructor
  */
 
 const Services = require("Services");
 
-loader.lazyImporter(this, "findCssSelector", "resource://gre/modules/css-selector.js");
-loader.lazyImporter(this, "getCssPath", "resource://gre/modules/css-selector.js");
-loader.lazyImporter(this, "getXPath", "resource://gre/modules/css-selector.js");
 loader.lazyRequireGetter(this, "getCSSLexer", "devtools/shared/css/lexer", true);
 loader.lazyRequireGetter(this, "getTabPrefs", "devtools/shared/indentation", true);
 
 const {LocalizationHelper} = require("devtools/shared/l10n");
 const styleInspectorL10N =
   new LocalizationHelper("devtools/shared/locales/styleinspector.properties");
 
 /**
@@ -358,38 +355,16 @@ function prettifyCSS(text, ruleCount) {
   }
 
   return result;
 }
 
 exports.prettifyCSS = prettifyCSS;
 
 /**
- * Find a unique CSS selector for a given element
- * @returns a string such that ele.ownerDocument.querySelector(reply) === ele
- * and ele.ownerDocument.querySelectorAll(reply).length === 1
- */
-exports.findCssSelector = findCssSelector;
-
-/**
- * Get the full CSS path for a given element.
- * @returns a string that can be used as a CSS selector for the element. It might not
- * match the element uniquely. It does however, represent the full path from the root
- * node to the element.
- */
-exports.getCssPath = getCssPath;
-
-/**
- * Get the xpath for a given element.
- * @param {DomNode} ele
- * @returns a string that can be used as an XPath to find the element uniquely.
- */
-exports.getXPath = getXPath;
-
-/**
  * Given a node, check to see if it is a ::before or ::after element.
  * If so, return the node that is accessible from within the document
  * (the parent of the anonymous node), along with which pseudo element
  * it was.  Otherwise, return the node itself.
  *
  * @returns {Object}
  *            - {DOMNode} node The non-anonymous node
  *            - {string} pseudo One of ':before', ':after', or null.
--- a/devtools/shared/tests/mochitest/test_css-logic-getCssPath.html
+++ b/devtools/shared/tests/mochitest/test_css-logic-getCssPath.html
@@ -6,18 +6,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1323700</title>
 
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript">
 
-let { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
-const CssLogic = require("devtools/shared/inspector/css-logic");
+ChromeUtils.import("resource://gre/modules/css-selector.js", this);
 
 var _tests = [];
 function addTest(test) {
   _tests.push(test);
 }
 
 function runNextTest() {
   if (_tests.length == 0) {
@@ -30,46 +29,46 @@ function runNextTest() {
 window.onload = function() {
   SimpleTest.waitForExplicitFinish();
   runNextTest();
 }
 
 addTest(function getCssPathForUnattachedElement() {
   var unattached = document.createElement("div");
   unattached.id = "unattached";
-  is(CssLogic.getCssPath(unattached), "", "Unattached node returns empty string");
+  is(getCssPath(unattached), "", "Unattached node returns empty string");
 
   var unattachedChild = document.createElement("div");
   unattached.appendChild(unattachedChild);
-  is(CssLogic.getCssPath(unattachedChild), "", "Unattached child returns empty string");
+  is(getCssPath(unattachedChild), "", "Unattached child returns empty string");
 
   var unattachedBody = document.createElement("body");
-  is(CssLogic.getCssPath(unattachedBody), "", "Unattached body returns empty string");
+  is(getCssPath(unattachedBody), "", "Unattached body returns empty string");
 
   runNextTest();
 });
 
 addTest(function cssPathHasOneStepForEachAncestor() {
   for (let el of [...document.querySelectorAll('*')]) {
-    let splitPath = CssLogic.getCssPath(el).split(" ");
+    let splitPath = getCssPath(el).split(" ");
 
     let expectedNbOfParts = 0;
     var parent = el.parentNode;
     while (parent) {
       expectedNbOfParts ++;
       parent = parent.parentNode;
     }
 
     is(splitPath.length, expectedNbOfParts, "There are enough parts in the full path");
   }
 
   runNextTest();
 });
 
-addTest(function getCssPath() {
+addTest(function testGetCssPath() {
   let data = [{
     selector: "#id",
     path: "html body div div div.class div#id"
   }, {
     selector: "html",
     path: "html"
   }, {
     selector: "body",
@@ -79,17 +78,17 @@ addTest(function getCssPath() {
     path: "html body span.c1.c2.c3"
   }, {
     selector: "#i",
     path: "html body span#i.c1.c2"
   }];
 
   for (let {selector, path} of data) {
     let node = document.querySelector(selector);
-    is (CssLogic.getCssPath(node), path, `Full css path is correct for ${selector}`);
+    is (getCssPath(node), path, `Full css path is correct for ${selector}`);
   }
 
   runNextTest();
 });
   </script>
 </head>
 <body>
   <div>
--- a/devtools/shared/tests/mochitest/test_css-logic-getXPath.html
+++ b/devtools/shared/tests/mochitest/test_css-logic-getXPath.html
@@ -7,18 +7,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <meta charset="utf-8">
   <title>Test for Bug 987877</title>
 
   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
   <script type="application/javascript">
 "use strict";
 
-const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
-const CssLogic = require("devtools/shared/inspector/css-logic");
+ChromeUtils.import("resource://gre/modules/css-selector.js", this);
 
 const _tests = [];
 function addTest(test) {
   _tests.push(test);
 }
 
 function runNextTest() {
   if (_tests.length == 0) {
@@ -31,29 +30,29 @@ function runNextTest() {
 window.onload = function () {
   SimpleTest.waitForExplicitFinish();
   runNextTest();
 };
 
 addTest(function getXPathForUnattachedElement() {
   let unattached = document.createElement("div");
   unattached.id = "unattached";
-  is(CssLogic.getXPath(unattached), "", "Unattached node returns empty string");
+  is(getXPath(unattached), "", "Unattached node returns empty string");
 
   let unattachedChild = document.createElement("div");
   unattached.appendChild(unattachedChild);
-  is(CssLogic.getXPath(unattachedChild), "", "Unattached child returns empty string");
+  is(getXPath(unattachedChild), "", "Unattached child returns empty string");
 
   let unattachedBody = document.createElement("body");
-  is(CssLogic.getXPath(unattachedBody), "", "Unattached body returns empty string");
+  is(getXPath(unattachedBody), "", "Unattached body returns empty string");
 
   runNextTest();
 });
 
-addTest(function getXPath() {
+addTest(function testGetXPath() {
   let data = [{
     // Target elements that have an ID get a short XPath.
     selector: "#i-have-an-id",
     path: "//*[@id=\"i-have-an-id\"]"
   }, {
     selector: "html",
     path: "/html"
   }, {
@@ -65,17 +64,17 @@ addTest(function getXPath() {
   }, {
     // XPath should support namespace.
     selector: "namespace\\:body",
     path: "/html/body/namespace:test/namespace:body"
   }];
 
   for (let {selector, path} of data) {
     let node = document.querySelector(selector);
-    is(CssLogic.getXPath(node), path, `Full css path is correct for ${selector}`);
+    is(getXPath(node), path, `Full css path is correct for ${selector}`);
   }
 
   runNextTest();
 });
   </script>
 </head>
 <body>
   <div id="i-have-an-id">find me</div>