Bug 1253803 - Ensure that we maintain the focused node state when changing labels in the dominators view; r=jsantell, a=ritu

This commit is contained in:
Nick Fitzgerald 2016-04-11 10:49:00 +02:00
parent 9356dbffa2
commit 89d201a2f5
3 changed files with 97 additions and 0 deletions

View File

@ -221,10 +221,32 @@ handlers[actions.FETCH_DOMINATOR_TREE_END] = function (snapshots, { id, root })
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: new Set(),
focused,
});
return immutableUpdate(snapshot, { dominatorTree });

View File

@ -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,
labelDisplays,
viewState,
} = require("devtools/client/memory/constants");
let {
takeSnapshotAndCensus,
focusDominatorTreeNode,
} = require("devtools/client/memory/actions/snapshot");
const {
changeView,
} = require("devtools/client/memory/actions/view");
const {
setLabelDisplayAndRefresh,
} = require("devtools/client/memory/actions/label-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().labelDisplay, labelDisplays.coarseType,
"Using labelDisplays.coarseType by default");
dispatch(setLabelDisplayAndRefresh(heapWorker,
labelDisplays.allocationStack));
equal(getState().labelDisplay, labelDisplays.allocationStack,
"Using labelDisplays.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();
});

View File

@ -40,5 +40,6 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
[test_dominator_trees_07.js]
[test_dominator_trees_08.js]
[test_dominator_trees_09.js]
[test_dominator_trees_10.js]
[test_utils.js]
[test_utils-get-snapshot-totals.js]