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
Родитель 5baf1b0f6c
Коммит 3fbbe9a152
3 изменённых файлов: 71 добавлений и 23 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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");
});