Bug 1253803 - Ensure that we maintain the focused node state when changing labels in the dominators view; r=jsantell
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 04 Apr 2016 17:36:00 +0200
changeset 291642 75bef7c5fd91e42e5cfa5337f02f48942b568996
parent 291641 4209cc859abcb5986b7b0e1406e9a00b5fff17a7
child 291643 7bd6cea0b0a3ec4d0faaedd642e9c9747c098cde
child 291861 68c0b7d6f16ce5bb023e08050102b5f2fe4aacd8
push id18551
push usercbook@mozilla.com
push dateWed, 06 Apr 2016 03:56:47 +0000
treeherderfx-team@75bef7c5fd91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs1253803
milestone48.0a1
Bug 1253803 - Ensure that we maintain the focused node state when changing labels in the dominators view; r=jsantell
devtools/client/memory/reducers/snapshots.js
devtools/client/memory/test/unit/test_dominator_trees_10.js
devtools/client/memory/test/unit/xpcshell.ini
--- a/devtools/client/memory/reducers/snapshots.js
+++ b/devtools/client/memory/reducers/snapshots.js
@@ -277,20 +277,42 @@ handlers[actions.FETCH_DOMINATOR_TREE_EN
     if (snapshot.id !== id) {
       return snapshot;
     }
 
     assert(snapshot.dominatorTree, "Should have a dominator tree model");
     assert(snapshot.dominatorTree.state == dominatorTreeState.FETCHING,
            "Should be in the FETCHING state");
 
+    let focused;
+    if (snapshot.dominatorTree.focused) {
+      focused = (function findFocused(node) {
+        if (node.nodeId === snapshot.dominatorTree.focused.nodeId) {
+          return node;
+        }
+
+        if (node.children) {
+          const length = node.children.length;
+          for (let i = 0; i < length; i++) {
+            const result = findFocused(node.children[i]);
+            if (result) {
+              return result;
+            }
+          }
+        }
+
+        return undefined;
+      }(root));
+    }
+
     const dominatorTree = immutableUpdate(snapshot.dominatorTree, {
       state: dominatorTreeState.LOADED,
       root,
       expanded: Immutable.Set(),
+      focused,
     });
 
     return immutableUpdate(snapshot, { dominatorTree });
   });
 };
 
 handlers[actions.EXPAND_DOMINATOR_TREE_NODE] = function (snapshots, { id, node }) {
   return snapshots.map(snapshot => {
new file mode 100644
--- /dev/null
+++ b/devtools/client/memory/test/unit/test_dominator_trees_10.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test that we maintain focus of the selected dominator tree node across
+// changing breakdowns for labeling them.
+
+let {
+  snapshotState: states,
+  dominatorTreeState,
+  dominatorTreeDisplays,
+  viewState,
+} = require("devtools/client/memory/constants");
+let {
+  takeSnapshotAndCensus,
+  focusDominatorTreeNode,
+} = require("devtools/client/memory/actions/snapshot");
+const {
+  changeView,
+} = require("devtools/client/memory/actions/view");
+const {
+  setDominatorTreeDisplayAndRefresh,
+} = require("devtools/client/memory/actions/dominator-tree-display");
+
+function run_test() {
+  run_next_test();
+}
+
+add_task(function *() {
+  let front = new StubbedMemoryFront();
+  let heapWorker = new HeapAnalysesClient();
+  yield front.attach();
+  let store = Store();
+  let { getState, dispatch } = store;
+
+  dispatch(changeView(viewState.DOMINATOR_TREE));
+  dispatch(takeSnapshotAndCensus(front, heapWorker));
+
+  // Wait for the dominator tree to finish being fetched.
+  yield waitUntilState(store, state =>
+    state.snapshots[0] &&
+    state.snapshots[0].dominatorTree &&
+    state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED);
+  ok(true, "The dominator tree was fetched");
+
+  const root = getState().snapshots[0].dominatorTree.root;
+  ok(root, "When the dominator tree is loaded, we should have its root");
+
+  dispatch(focusDominatorTreeNode(getState().snapshots[0].id, root));
+  equal(root, getState().snapshots[0].dominatorTree.focused,
+        "The root should be focused.");
+
+  equal(getState().dominatorTreeDisplay, dominatorTreeDisplays.coarseType,
+        "Using dominatorTreeDisplays.coarseType by default");
+  dispatch(setDominatorTreeDisplayAndRefresh(heapWorker,
+                                             dominatorTreeDisplays.allocationStack));
+  equal(getState().dominatorTreeDisplay, dominatorTreeDisplays.allocationStack,
+        "Using dominatorTreeDisplays.allocationStack now");
+
+  yield waitUntilState(store, state =>
+    state.snapshots[0].dominatorTree.state === dominatorTreeState.FETCHING);
+  ok(true, "We started re-fetching the dominator tree");
+
+  yield waitUntilState(store, state =>
+    state.snapshots[0].dominatorTree.state === dominatorTreeState.LOADED);
+  ok(true, "The dominator tree was loaded again");
+
+  ok(getState().snapshots[0].dominatorTree.focused,
+     "Still have a focused node");
+  equal(getState().snapshots[0].dominatorTree.focused.nodeId, root.nodeId,
+        "Focused node is the same as before");
+
+  heapWorker.destroy();
+  yield front.detach();
+});
--- a/devtools/client/memory/test/unit/xpcshell.ini
+++ b/devtools/client/memory/test/unit/xpcshell.ini
@@ -37,12 +37,13 @@ skip-if = toolkit == 'android' || toolki
 [test_dominator_trees_02.js]
 [test_dominator_trees_03.js]
 [test_dominator_trees_04.js]
 [test_dominator_trees_05.js]
 [test_dominator_trees_06.js]
 [test_dominator_trees_07.js]
 [test_dominator_trees_08.js]
 [test_dominator_trees_09.js]
+[test_dominator_trees_10.js]
 [test_tree-map-01.js]
 [test_tree-map-02.js]
 [test_utils.js]
 [test_utils-get-snapshot-totals.js]