Bug 1428076 - Add a mochitest r=mstange
MozReview-Commit-ID: EhNoJuMhrAS
--- a/tools/profiler/moz.build
+++ b/tools/profiler/moz.build
@@ -129,16 +129,17 @@ if CONFIG['MOZ_TASK_TRACER']:
'tasktracer/TracedTaskCommon.h',
]
UNIFIED_SOURCES += [
'tasktracer/GeckoTaskTracer.cpp',
'tasktracer/TracedTaskCommon.cpp',
]
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell.ini']
+MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
CXXFLAGS += [
'-Wno-error=shadow',
'-Wno-ignored-qualifiers', # due to use of breakpad headers
]
with Files('**'):
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/.eslintrc.js
@@ -0,0 +1,6 @@
+"use strict";
+
+module.exports = {
+ // Extend from the shared list of defined globals for mochitests.
+ "extends": "plugin:mozilla/chrome-test"
+};
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/chrome.ini
@@ -0,0 +1,1 @@
+[test_profile_worker_bug_1428076.html]
new file mode 100644
--- /dev/null
+++ b/tools/profiler/tests/chrome/test_profile_worker_bug_1428076.html
@@ -0,0 +1,108 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1428076
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1428076</title>
+ <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1428076">Mozilla Bug 1428076</a>
+
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script type="application/javascript">
+
+/** Test for Bug 1428076 **/
+"use strict";
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+function startProfiler() {
+ const settings = {
+ entries: 1000000, // 9MB
+ interval: 1, // ms
+ features: ["js", "threads", "leaf", "stackwalk"],
+ threads: ["GeckoMain", "Compositor", "Worker"] // most common combination
+ };
+
+ Services.profiler.StartProfiler(
+ settings.entries,
+ settings.interval,
+ settings.features,
+ settings.features.length,
+ settings.threads,
+ settings.threads.length
+ );
+
+ info("Profiler has started");
+}
+
+function getProfile() {
+ const profile = Services.profiler.getProfileData();
+ info("We got a profile");
+
+ // Run the mochitest with `--keep-open true` to see the logged profile in the
+ // Web console.
+ console.log(profile);
+
+ return profile;
+}
+
+function stopProfiler() {
+ Services.profiler.StopProfiler();
+ info("Profiler has stopped");
+}
+
+function end(error) {
+ if (error) {
+ ok(false, `We got an error: ${error}`);
+ } else {
+ ok(true, "We ran the whole process");
+ }
+ SimpleTest.finish();
+}
+
+function workload() {
+ // We use a Blob for the worker content to avoid an external JS file, and data
+ // URLs seem to be blocked in a chrome environment.
+ const workerContent = new Blob(
+ [ "console.log('hello world!')" ],
+ { type: "application/javascript" }
+ );
+ const blobURL = URL.createObjectURL(workerContent);
+
+ // We start a worker and then terminate it right away to trigger our bug.
+ info("Starting the worker, and terminate it right away.");
+ const myWorker = new Worker(blobURL);
+ myWorker.terminate();
+
+ URL.revokeObjectURL(blobURL);
+
+ // We're deferring some little time so that the worker has the time to be
+ // properly cleaned up and the profiler actually saves the worker data.
+ return new Promise(resolve => {
+ setTimeout(resolve, 50);
+ });
+}
+
+SimpleTest.waitForExplicitFinish();
+(async function() {
+ try {
+ await startProfiler();
+ await workload();
+ await getProfile();
+ await stopProfiler();
+ await end();
+ } catch (e) {
+ // By catching and handling the error, we're being nice to mochitest
+ // runners: instead of waiting for the timeout, we fail right away.
+ await end(e);
+ }
+})();
+
+
+</script>
+</body>
+</html>