Bug 1218560 - Part 2: Add an integration test for allocation stack breakdowns; r=jsantell
authorNick Fitzgerald <fitzgen@gmail.com>
Wed, 28 Oct 2015 22:46:25 -0700
changeset 305225 3e62a45284becec92ac5d6c3e4b7cd611cee75f2
parent 305224 ae06ef1f37db155b18520a2287c453de37ffbd73
child 305226 f3754dcad86e2ddacb1ad2b003cafb91f299ecf8
child 306158 31b456bf9b498f616358ad1932404ff7df062269
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjsantell
bugs1218560
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1218560 - Part 2: Add an integration test for allocation stack breakdowns; r=jsantell
devtools/client/memory/initializer.js
devtools/client/memory/test/browser/browser.ini
devtools/client/memory/test/browser/browser_memory_allocationStackBreakdown_01.js
--- a/devtools/client/memory/initializer.js
+++ b/devtools/client/memory/initializer.js
@@ -4,55 +4,60 @@
 
 "use strict";
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 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.
  */
 var gToolbox, gTarget, gFront, gHeapAnalysesClient;
 
 /**
  * Variables set by `initialize()`
  */
 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
  * the highlighting of the tool when recording allocations.
  */
 function onStateChange () {
   let isRecording = gStore.getState().allocations.recording;
+  if (isRecording === isHighlighted) {
+    return;
+  }
 
-  if (isRecording !== isHighlighted) {
-    isRecording ?
-      gToolbox.highlightTool("memory") :
-      gToolbox.unhighlightTool("memory");
-    isHighlighted = isRecording;
+  if (isRecording) {
+    gToolbox.highlightTool("memory");
+  } else {
+    gToolbox.unhighlightTool("memory");
   }
+
+  isHighlighted = isRecording;
 }
--- a/devtools/client/memory/test/browser/browser.ini
+++ b/devtools/client/memory/test/browser/browser.ini
@@ -1,9 +1,13 @@
 [DEFAULT]
 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]
new file mode 100644
--- /dev/null
+++ b/devtools/client/memory/test/browser/browser_memory_allocationStackBreakdown_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");
+});