Bug 1494162 - Part 19: Directly import getCssPath, getXpath and findCssSelector. r=pbro

This commit is contained in:
Gabriel Luong 2018-09-29 15:25:34 -04:00
Родитель ebcf4a73ee
Коммит f387d9fbfd
5 изменённых файлов: 17 добавлений и 44 удалений

Просмотреть файл

@ -12,9 +12,9 @@ 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);

Просмотреть файл

@ -18,7 +18,7 @@ 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);

Просмотреть файл

@ -46,9 +46,6 @@ const MAX_DATA_URL_LENGTH = 40;
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);
@ -362,28 +359,6 @@ function prettifyCSS(text, ruleCount) {
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

Просмотреть файл

@ -11,8 +11,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1323700
<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) {
@ -35,21 +34,21 @@ window.onload = function() {
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;
@ -64,7 +63,7 @@ addTest(function cssPathHasOneStepForEachAncestor() {
runNextTest();
});
addTest(function getCssPath() {
addTest(function testGetCssPath() {
let data = [{
selector: "#id",
path: "html body div div div.class div#id"
@ -84,7 +83,7 @@ addTest(function getCssPath() {
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();

Просмотреть файл

@ -12,8 +12,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=987877
<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) {
@ -36,19 +35,19 @@ window.onload = function () {
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",
@ -70,7 +69,7 @@ addTest(function getXPath() {
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();