Bug 1596728 - fix an error when opening a color picker for an element with a pseudo child. r=rcaliman a=pascalc
authorYura Zenevich <yura.zenevich@gmail.com>
Tue, 19 Nov 2019 11:36:47 +0000
changeset 563449 f4fc0e2524f47fe66062758f9e5ce90737486d56
parent 563448 f979fad36ca3122de7cd9fd350e88d03188108fc
child 563450 3191228990dac5ecc15b3a4f98cec3fcf50a3f05
push id2195
push userffxbld-merge
push dateMon, 25 Nov 2019 12:02:33 +0000
treeherdermozilla-release@19adee6f7bb3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcaliman, pascalc
bugs1596728
milestone71.0
Bug 1596728 - fix an error when opening a color picker for an element with a pseudo child. r=rcaliman a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D53673
devtools/server/actors/inspector/utils.js
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_inspector-utils.js
--- a/devtools/server/actors/inspector/utils.js
+++ b/devtools/server/actors/inspector/utils.js
@@ -461,17 +461,21 @@ function findGridParentContainerForNode(
  *         RGBA array for the max luminance color in a multi-colored background.
  *         Null for single-colored backgrounds.
  */
 async function getBackgroundColor({ rawNode: node, walker }) {
   // Fall back to calculating contrast against closest bg if:
   // - not element node
   // - more than one child
   // Avoid calculating bounds and creating doc walker by returning early.
-  if (node.nodeType != Node.ELEMENT_NODE || node.children.length > 0) {
+  if (
+    node.nodeType != Node.ELEMENT_NODE ||
+    node.childNodes.length > 1 ||
+    !node.firstChild
+  ) {
     return {
       value: colorUtils.colorToRGBA(
         getClosestBackgroundColor(node),
         true,
         true
       ),
     };
   }
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -111,16 +111,17 @@ skip-if = e10s # Bug 1183605 - devtools/
 [browser_inspector-mutations-childlist.js]
 [browser_inspector-mutations-frameload.js]
 [browser_inspector-release.js]
 [browser_inspector-remove.js]
 [browser_inspector-retain.js]
 [browser_inspector-search.js]
 [browser_inspector-shadow.js]
 [browser_inspector-traversal.js]
+[browser_inspector-utils.js]
 [browser_layout_getGrids.js]
 [browser_layout_simple.js]
 [browser_markers-cycle-collection.js]
 [browser_markers-gc.js]
 [browser_markers-minor-gc.js]
 [browser_markers-parse-html.js]
 [browser_markers-styles.js]
 [browser_markers-timestamp.js]
new file mode 100644
--- /dev/null
+++ b/devtools/server/tests/browser/browser_inspector-utils.js
@@ -0,0 +1,26 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from inspector-helpers.js */
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/devtools/server/tests/browser/inspector-helpers.js",
+  this
+);
+
+const COLOR_WHITE = [255, 255, 255, 1];
+
+add_task(async function loadNewChild() {
+  const { walker } = await initInspectorFront(
+    `data:text/html,<style>body{color:red;background-color:white;}body::before{content:"test";}</style>`
+  );
+
+  const body = await walker.querySelector(walker.rootNode, "body");
+  const color = await body.getBackgroundColor();
+  Assert.deepEqual(
+    color.value,
+    COLOR_WHITE,
+    "Background color is calculated correctly for an element with a pseudo child."
+  );
+});