Bug 1403871 - rename getAllGrids to getGrids;r=gl
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 21 Nov 2017 17:31:50 +0100
changeset 701828 fb858a306b2fdc693898184e9d4b328fa1c2772a
parent 701827 c9a12455c869b6c6774098f10431ec51d96dc932
child 701829 0fd137f9b3fe1d8f9ed23cee79dfd7b6a4f2f02d
push id90298
push userbmo:bpostelnicu@mozilla.com
push dateWed, 22 Nov 2017 10:54:01 +0000
reviewersgl
bugs1403871
milestone59.0a1
Bug 1403871 - rename getAllGrids to getGrids;r=gl MozReview-Commit-ID: I9MZ2mrVMiT
devtools/client/inspector/grids/grid-inspector.js
devtools/server/actors/layout.js
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_layout_getAllGrids.js
devtools/server/tests/browser/browser_layout_getGrids.js
devtools/server/tests/browser/browser_layout_simple.js
devtools/shared/specs/layout.js
--- a/devtools/client/inspector/grids/grid-inspector.js
+++ b/devtools/client/inspector/grids/grid-inspector.js
@@ -287,17 +287,17 @@ class GridInspector {
     // Stop refreshing if the inspector or store is already destroyed.
     if (!this.inspector || !this.store) {
       return;
     }
 
     // Get all the GridFront from the server if no gridFronts were provided.
     let gridFronts;
     try {
-      gridFronts = await this.layoutInspector.getAllGrids(this.walker.rootNode);
+      gridFronts = await this.layoutInspector.getGrids(this.walker.rootNode);
     } catch (e) {
       // This call might fail if called asynchrously after the toolbox is finished
       // closing.
       return;
     }
 
     // Log how many CSS Grid elements DevTools sees.
     if (gridFronts.length > 0 &&
@@ -403,17 +403,17 @@ class GridInspector {
     }
 
     // The list of grids currently displayed.
     const { grids } = this.store.getState();
 
     // The new list of grids from the server.
     let newGridFronts;
     try {
-      newGridFronts = await this.layoutInspector.getAllGrids(this.walker.rootNode);
+      newGridFronts = await this.layoutInspector.getGrids(this.walker.rootNode);
     } catch (e) {
       // This call might fail if called asynchrously after the toolbox is finished
       // closing.
       return;
     }
 
     // Get the node front(s) from the current grid(s) so we can compare them to them to
     // node(s) of the new grids.
--- a/devtools/server/actors/layout.js
+++ b/devtools/server/actors/layout.js
@@ -196,54 +196,42 @@ const LayoutActor = ActorClassWithSpec(l
 
     return flexboxes;
   },
 
   /**
    * Returns an array of GridActor objects for all the grid elements contained in the
    * given root node.
    *
-   * @param  {Node} node
+   * @param  {Node|NodeActor} node
    *         The root node for grid elements
    * @return {Array} An array of GridActor objects.
    */
   getGrids(node) {
     if (!node) {
       return [];
     }
 
+    // Root node can either be a Node or a NodeActor.
+    if (node.rawNode) {
+      node = node.rawNode;
+    }
+
     // Root node can be a #document object, which does not support getElementsWithGrid.
     if (node.nodeType === nodeConstants.DOCUMENT_NODE) {
       node = node.documentElement;
     }
 
     let gridElements = node.getElementsWithGrid();
     let gridActors = gridElements.map(n => new GridActor(this, n));
 
     let frames = node.querySelectorAll("iframe, frame");
     for (let frame of frames) {
       gridActors = gridActors.concat(this.getGrids(frame.contentDocument));
     }
 
     return gridActors;
   },
-
-  /**
-   * Returns an array of GridActor objects for all existing grid containers found by
-   * iterating below the given rootNode and including nested frames.
-   *
-   * @param  {NodeActor} rootNode
-   * @return {Array} An array of GridActor objects.
-   */
-  getAllGrids(rootNode) {
-    let grids = [];
-
-    if (!rootNode) {
-      return grids;
-    }
-
-    return this.getGrids(rootNode.rawNode);
-  },
 });
 
 exports.FlexboxActor = FlexboxActor;
 exports.GridActor = GridActor;
 exports.LayoutActor = LayoutActor;
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -54,17 +54,17 @@ skip-if = e10s # Bug 1183605 - devtools/
 [browser_canvasframe_helper_03.js]
 skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
 [browser_canvasframe_helper_04.js]
 skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
 [browser_canvasframe_helper_05.js]
 skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
 [browser_canvasframe_helper_06.js]
 skip-if = e10s # Bug 1183605 - devtools/server/tests/browser/ tests are still disabled in E10S
-[browser_layout_getAllGrids.js]
+[browser_layout_getGrids.js]
 [browser_layout_simple.js]
 [browser_markers-cycle-collection.js]
 [browser_markers-docloading-01.js]
 [browser_markers-docloading-02.js]
 [browser_markers-docloading-03.js]
 [browser_markers-gc.js]
 [browser_markers-minor-gc.js]
 [browser_markers-parse-html.js]
rename from devtools/server/tests/browser/browser_layout_getAllGrids.js
rename to devtools/server/tests/browser/browser_layout_getGrids.js
--- a/devtools/server/tests/browser/browser_layout_getAllGrids.js
+++ b/devtools/server/tests/browser/browser_layout_getGrids.js
@@ -1,15 +1,15 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-// Check the output of getAllGrids for the LayoutActor
+// Check the output of getGrids for the LayoutActor
 
 const GRID_FRAGMENT_DATA = {
   areas: [
     {
       columnEnd: 3,
       columnStart: 2,
       name: "header",
       rowEnd: 2,
@@ -104,17 +104,17 @@ const GRID_FRAGMENT_DATA = {
         type: "explicit"
       }
     ]
   }
 };
 
 add_task(function* () {
   let { client, walker, layout } = yield initLayoutFrontForUrl(MAIN_DOMAIN + "grid.html");
-  let grids = yield layout.getAllGrids(walker.rootNode);
+  let grids = yield layout.getGrids(walker.rootNode);
   let grid = grids[0];
   let { gridFragments } = grid;
 
   is(grids.length, 1, "One grid was returned.");
   is(gridFragments.length, 1, "One grid fragment was returned.");
   ok(Array.isArray(gridFragments), "An array of grid fragments was returned.");
   Assert.deepEqual(gridFragments[0], GRID_FRAGMENT_DATA,
     "Got the correct grid fragment data.");
--- a/devtools/server/tests/browser/browser_layout_simple.js
+++ b/devtools/server/tests/browser/browser_layout_simple.js
@@ -6,34 +6,26 @@
 
 // Simple checks for the LayoutActor and GridActor
 
 add_task(function* () {
   let {client, walker, layout} = yield initLayoutFrontForUrl(
     "data:text/html;charset=utf-8,<title>test</title><div></div>");
 
   ok(layout, "The LayoutFront was created");
-  ok(layout.getAllGrids, "The getAllGrids method exists");
+  ok(layout.getGrids, "The getGrids method exists");
 
   let didThrow = false;
   try {
     yield layout.getGrids(null);
   } catch (e) {
     didThrow = true;
   }
   ok(didThrow, "An exception was thrown for a missing NodeActor in getGrids");
 
-  didThrow = false;
-  try {
-    yield layout.getAllGrids(null);
-  } catch (e) {
-    didThrow = true;
-  }
-  ok(didThrow, "An exception was thrown for a missing NodeActor in getAllGrids");
-
   let invalidNode = yield walker.querySelector(walker.rootNode, "title");
-  let grids = yield layout.getAllGrids(invalidNode);
+  let grids = yield layout.getGrids(invalidNode);
   ok(Array.isArray(grids), "An array of grids was returned");
   is(grids.length, 0, "0 grids have been returned for the invalid node");
 
   yield client.close();
   gBrowser.removeCurrentTab();
 });
--- a/devtools/shared/specs/layout.js
+++ b/devtools/shared/specs/layout.js
@@ -27,17 +27,17 @@ const layoutSpec = generateActorSpec({
         rootNode: Arg(0, "domnode"),
         traverseFrames: Arg(1, "nullable:boolean")
       },
       response: {
         flexboxes: RetVal("array:flexbox")
       }
     },
 
-    getAllGrids: {
+    getGrids: {
       request: {
         rootNode: Arg(0, "domnode")
       },
       response: {
         grids: RetVal("array:grid")
       }
     },
   },