Bug 1520782 - Convert memory tests using chrome documents and using server references directly to browser mochitests. r=julienw
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 23 Jan 2019 08:53:01 +0000
changeset 514958 552b8ad866be42f5e1ca2376026c6539d2bd28d3
parent 514957 0b8dbea063541103c759b29e9de24ca9bf0aaa5b
child 514959 9bbfd13f52fad97736df6cba9d7ab32785452643
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjulienw
bugs1520782
milestone66.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 1520782 - Convert memory tests using chrome documents and using server references directly to browser mochitests. r=julienw This test was using chrome mochitest which forces the test page to be running in chrome and in parent process. This doesn't reflect typical setup where the page runs unprivileged in content process. Also, with the current bug, the pages running in system principal will be debugged with a special setup. Actors will be run with modules loaded in a distinct loader in order to be executed in a distinct compartment, distinct from the shared system principal compartment. That a prerequisite for the Debugger API. It has to run in a distinct compartment than its debuggee. Depends on D16824 Differential Revision: https://phabricator.services.mozilla.com/D16825
devtools/server/tests/browser/browser.ini
devtools/server/tests/browser/browser_memory_allocations_01.js
devtools/server/tests/mochitest/chrome.ini
devtools/server/tests/mochitest/test_memory_allocations_01.html
--- a/devtools/server/tests/browser/browser.ini
+++ b/devtools/server/tests/browser/browser.ini
@@ -71,16 +71,17 @@ skip-if = e10s # Bug 1183605 - devtools/
 [browser_layout_getGrids.js]
 [browser_layout_simple.js]
 [browser_markers-cycle-collection.js]
 [browser_markers-gc.js]
 [browser_markers-minor-gc.js]
 [browser_markers-parse-html.js]
 [browser_markers-styles.js]
 [browser_markers-timestamp.js]
+[browser_memory_allocations_01.js]
 [browser_navigateEvents.js]
 [browser_perf-01.js]
 [browser_perf-02.js]
 [browser_perf-03.js]
 [browser_perf-04.js]
 [browser_perf-allocation-data.js]
 [browser_perf-profiler-01.js]
 [browser_perf-profiler-02.js]
new file mode 100644
--- /dev/null
+++ b/devtools/server/tests/browser/browser_memory_allocations_01.js
@@ -0,0 +1,95 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function() {
+  const target = await addTabTarget("data:text/html;charset=utf-8,test-doc");
+  const memory = await target.getFront("memory");
+
+  await memory.attach();
+
+  await memory.startRecordingAllocations();
+  ok(true, "Can start recording allocations");
+
+  // Allocate some objects.
+  const [line1, line2, line3] =
+    await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+      // Use eval to ensure allocating the object in the page's compartment
+      return content.eval("(" + function() {
+        let alloc1, alloc2, alloc3;
+
+        /* eslint-disable max-nested-callbacks */
+        (function outer() {
+          (function middle() {
+            (function inner() {
+              alloc1 = {}; alloc1.line = Error().lineNumber;
+              alloc2 = []; alloc2.line = Error().lineNumber;
+              // eslint-disable-next-line new-parens
+              alloc3 = new function() {}; alloc3.line = Error().lineNumber;
+            }());
+          }());
+        }());
+        /* eslint-enable max-nested-callbacks */
+
+        return [ alloc1.line, alloc2.line, alloc3.line ];
+      } + ")()");
+    });
+
+  const response = await memory.getAllocations();
+
+  await memory.stopRecordingAllocations();
+  ok(true, "Can stop recording allocations");
+
+  // Filter out allocations by library and test code, and get only the
+  // allocations that occurred in our test case above.
+
+  function isTestAllocation(alloc) {
+    const frame = response.frames[alloc];
+    return frame
+      && frame.functionDisplayName === "inner"
+      && (frame.line === line1
+          || frame.line === line2
+          || frame.line === line3);
+  }
+
+  const testAllocations = response.allocations.filter(isTestAllocation);
+  ok(testAllocations.length >= 3,
+     "Should find our 3 test allocations (plus some allocations for the error "
+     + "objects used to get line numbers)");
+
+  // For each of the test case's allocations, ensure that the parent frame
+  // indices are correct. Also test that we did get an allocation at each
+  // line we expected (rather than a bunch on the first line and none on the
+  // others, etc).
+
+  const expectedLines = new Set([line1, line2, line3]);
+  is(expectedLines.size, 3, "We are expecting 3 allocations");
+
+  for (const alloc of testAllocations) {
+    const innerFrame = response.frames[alloc];
+    ok(innerFrame, "Should get the inner frame");
+    is(innerFrame.functionDisplayName, "inner");
+    expectedLines.delete(innerFrame.line);
+
+    const middleFrame = response.frames[innerFrame.parent];
+    ok(middleFrame, "Should get the middle frame");
+    is(middleFrame.functionDisplayName, "middle");
+
+    const outerFrame = response.frames[middleFrame.parent];
+    ok(outerFrame, "Should get the outer frame");
+    is(outerFrame.functionDisplayName, "outer");
+
+    // Not going to test the rest of the frames because they are Task.jsm
+    // and promise frames and it gets gross. Plus, I wouldn't want this test
+    // to start failing if they changed their implementations in a way that
+    // added or removed stack frames here.
+  }
+
+  is(expectedLines.size, 0,
+     "Should have found all the expected lines");
+
+  await memory.detach();
+
+  await target.destroy();
+});
--- a/devtools/server/tests/mochitest/chrome.ini
+++ b/devtools/server/tests/mochitest/chrome.ini
@@ -86,17 +86,16 @@ skip-if = (verify && debug && (os == 'wi
 [test_inspector-retain.html]
 [test_inspector-search.html]
 [test_inspector-search-front.html]
 [test_inspector-scroll-into-view.html]
 [test_inspector-template.html]
 [test_inspector-traversal.html]
 [test_makeGlobalObjectReference.html]
 [test_memory.html]
-[test_memory_allocations_01.html]
 [test_memory_allocations_02.html]
 [test_memory_allocations_03.html]
 [test_memory_allocations_04.html]
 [test_memory_allocations_05.html]
 [test_memory_allocations_06.html]
 [test_memory_allocations_07.html]
 [test_memory_attach_01.html]
 [test_memory_attach_02.html]
deleted file mode 100644
--- a/devtools/server/tests/mochitest/test_memory_allocations_01.html
+++ /dev/null
@@ -1,104 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-Bug 1067491 - Test recording allocations.
--->
-<head>
-  <meta charset="utf-8">
-  <title>Memory monitoring actor test</title>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
-</head>
-<body>
-<pre id="test">
-<script src="memory-helpers.js" type="application/javascript"></script>
-<script>
-"use strict";
-
-window.onload = function() {
-  SimpleTest.waitForExplicitFinish();
-
-  (async function() {
-    const { memory, target } = await startServerAndGetSelectedTabMemory();
-    await memory.attach();
-
-    await memory.startRecordingAllocations();
-    ok(true, "Can start recording allocations");
-
-    // Allocate some objects.
-
-    let alloc1, alloc2, alloc3;
-
-    /* eslint-disable max-nested-callbacks */
-    (function outer() {
-      (function middle() {
-        (function inner() {
-          alloc1 = {}; alloc1.line = Error().lineNumber;
-          alloc2 = []; alloc2.line = Error().lineNumber;
-          // eslint-disable-next-line new-parens
-          alloc3 = new function() {}; alloc3.line = Error().lineNumber;
-        }());
-      }());
-    }());
-    /* eslint-enable max-nested-callbacks */
-
-    const response = await memory.getAllocations();
-
-    await memory.stopRecordingAllocations();
-    ok(true, "Can stop recording allocations");
-
-    // Filter out allocations by library and test code, and get only the
-    // allocations that occurred in our test case above.
-
-    function isTestAllocation(alloc) {
-      const frame = response.frames[alloc];
-      return frame
-        && frame.functionDisplayName === "inner"
-        && (frame.line === alloc1.line
-            || frame.line === alloc2.line
-            || frame.line === alloc3.line);
-    }
-
-    const testAllocations = response.allocations.filter(isTestAllocation);
-    ok(testAllocations.length >= 3,
-       "Should find our 3 test allocations (plus some allocations for the error "
-       + "objects used to get line numbers)");
-
-    // For each of the test case's allocations, ensure that the parent frame
-    // indices are correct. Also test that we did get an allocation at each
-    // line we expected (rather than a bunch on the first line and none on the
-    // others, etc).
-
-    const expectedLines = new Set([alloc1.line, alloc2.line, alloc3.line]);
-
-    for (const alloc of testAllocations) {
-      const innerFrame = response.frames[alloc];
-      ok(innerFrame, "Should get the inner frame");
-      is(innerFrame.functionDisplayName, "inner");
-      expectedLines.delete(innerFrame.line);
-
-      const middleFrame = response.frames[innerFrame.parent];
-      ok(middleFrame, "Should get the middle frame");
-      is(middleFrame.functionDisplayName, "middle");
-
-      const outerFrame = response.frames[middleFrame.parent];
-      ok(outerFrame, "Should get the outer frame");
-      is(outerFrame.functionDisplayName, "outer");
-
-      // Not going to test the rest of the frames because they are Task.jsm
-      // and promise frames and it gets gross. Plus, I wouldn't want this test
-      // to start failing if they changed their implementations in a way that
-      // added or removed stack frames here.
-    }
-
-    is(expectedLines.size, 0,
-       "Should have found all the expected lines");
-
-    await memory.detach();
-    destroyServerAndFinish(target);
-  })();
-};
-</script>
-</pre>
-</body>
-</html>