Bug 1218560 - Part 2: Add an integration test for allocation stack breakdowns; r=jsantell

This commit is contained in:
Nick Fitzgerald 2015-10-28 22:46:25 -07:00
parent 5697eb4257
commit d531dd8d95
3 changed files with 71 additions and 23 deletions

View File

@ -9,10 +9,11 @@ const BrowserLoaderModule = {};
Cu.import("resource://devtools/client/shared/browser-loader.js", BrowserLoaderModule);
const { require } = BrowserLoaderModule.BrowserLoader("resource://devtools/client/memory/", this);
const { Task } = require("resource://gre/modules/Task.jsm");
const { createFactory, createElement, render } = require("devtools/client/shared/vendor/react");
const { createFactory, createElement, render, unmountComponentAtNode } = require("devtools/client/shared/vendor/react");
const { Provider } = require("devtools/client/shared/vendor/react-redux");
const App = createFactory(require("devtools/client/memory/app"));
const Store = require("devtools/client/memory/store");
const { assert } = require("devtools/shared/DevToolsUtils");
/**
* The current target, toolbox, MemoryFront, and HeapAnalysesClient, set by this tool's host.
@ -24,23 +25,23 @@ var gToolbox, gTarget, gFront, gHeapAnalysesClient;
*/
var gStore, gRoot, gApp, gProvider, unsubscribe, isHighlighted;
function initialize () {
return Task.spawn(function*() {
gRoot = document.querySelector("#app");
gStore = Store();
gApp = createElement(App, { toolbox: gToolbox, front: gFront, heapWorker: gHeapAnalysesClient });
gProvider = createElement(Provider, { store: gStore }, gApp);
render(gProvider, gRoot);
unsubscribe = gStore.subscribe(onStateChange);
});
}
var initialize = Task.async(function*() {
gRoot = document.querySelector("#app");
gStore = Store();
gApp = createElement(App, { toolbox: gToolbox, front: gFront, heapWorker: gHeapAnalysesClient });
gProvider = createElement(Provider, { store: gStore }, gApp);
render(gProvider, gRoot);
unsubscribe = gStore.subscribe(onStateChange);
});
function destroy () {
return Task.spawn(function*(){
unsubscribe();
gStore, gRoot, gApp, gProvider, unsubscribe, isHighlighted = null;
});
}
var destroy = Task.async(function*() {
const ok = unmountComponentAtNode(gRoot);
assert(ok, "Should successfully unmount the memory tool's top level React component");
unsubscribe();
gStore, gRoot, gApp, gProvider, unsubscribe, isHighlighted = null;
});
/**
* Fired on any state change, currently only handles toggling
@ -48,11 +49,15 @@ function destroy () {
*/
function onStateChange () {
let isRecording = gStore.getState().allocations.recording;
if (isRecording !== isHighlighted) {
isRecording ?
gToolbox.highlightTool("memory") :
gToolbox.unhighlightTool("memory");
isHighlighted = isRecording;
if (isRecording === isHighlighted) {
return;
}
if (isRecording) {
gToolbox.highlightTool("memory");
} else {
gToolbox.unhighlightTool("memory");
}
isHighlighted = isRecording;
}

View File

@ -3,7 +3,11 @@ tags = devtools
subsuite = devtools
support-files =
head.js
doc_steady_allocation.html
[browser_memory_allocationStackBreakdown_01.js]
[browser_memory-breakdowns-01.js]
skip-if = debug # bug 1219554
[browser_memory-simple-01.js]
skip-if = debug # bug 1219554
[browser_memory_transferHeapSnapshot_e10s_01.js]

View File

@ -0,0 +1,39 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Sanity test that we can show allocation stack breakdowns in the tree.
"use strict";
const { waitForTime } = require("devtools/shared/DevToolsUtils");
const { breakdowns } = require("devtools/client/memory/constants");
const { toggleRecordingAllocationStacks } = require("devtools/client/memory/actions/allocations");
const { takeSnapshotAndCensus } = require("devtools/client/memory/actions/snapshot");
const breakdownActions = require("devtools/client/memory/actions/breakdown");
const { toggleInverted } = require("devtools/client/memory/actions/inverted");
const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
this.test = makeMemoryTest(TEST_URL, function* ({ tab, panel }) {
const heapWorker = panel.panelWin.gHeapAnalysesClient;
const front = panel.panelWin.gFront;
const { getState, dispatch } = panel.panelWin.gStore;
dispatch(toggleInverted());
ok(getState().inverted, true);
dispatch(breakdownActions.setBreakdown(breakdowns.allocationStack.breakdown));
is(getState().breakdown.by, "allocationStack");
yield dispatch(toggleRecordingAllocationStacks(front));
ok(getState().allocations.recording);
// Let some allocations build up.
yield waitForTime(500);
yield dispatch(takeSnapshotAndCensus(front, heapWorker));
const doc = panel.panelWin.document;
ok(doc.querySelector(".frame-link-function-display-name"),
"Should have rendered some allocation stack tree items");
});