summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/unit/test_profiler_events-02.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/server/tests/unit/test_profiler_events-02.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/tests/unit/test_profiler_events-02.js')
-rw-r--r--devtools/server/tests/unit/test_profiler_events-02.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/devtools/server/tests/unit/test_profiler_events-02.js b/devtools/server/tests/unit/test_profiler_events-02.js
new file mode 100644
index 000000000..fed702043
--- /dev/null
+++ b/devtools/server/tests/unit/test_profiler_events-02.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Tests the event notification service for the profiler actor.
+ */
+
+const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
+const MAX_PROFILER_ENTRIES = 10000000;
+const { ProfilerFront } = require("devtools/shared/fronts/profiler");
+const { waitForTime } = DevToolsUtils;
+
+function run_test() {
+ run_next_test();
+}
+
+add_task(function* () {
+ let [client, form] = yield getChromeActors();
+ let front = new ProfilerFront(client, form);
+
+ // Ensure the profiler is not running when the test starts (it could
+ // happen if the MOZ_PROFILER_STARTUP environment variable is set).
+ Profiler.StopProfiler();
+ let eventsCalled = 0;
+ let handledThreeTimes = promise.defer();
+
+ front.on("profiler-status", (response) => {
+ dump("'profiler-status' fired\n");
+ do_check_true(typeof response.position === "number");
+ do_check_true(typeof response.totalSize === "number");
+ do_check_true(typeof response.generation === "number");
+ do_check_true(response.position > 0 && response.position < response.totalSize);
+ do_check_true(response.totalSize === MAX_PROFILER_ENTRIES);
+ // There's no way we'll fill the buffer in this test.
+ do_check_true(response.generation === 0);
+
+ eventsCalled++;
+ if (eventsCalled > 2) {
+ handledThreeTimes.resolve();
+ }
+ });
+
+ yield front.setProfilerStatusInterval(1);
+ dump("Set the profiler-status event interval to 1\n");
+ yield front.startProfiler();
+ yield waitForTime(500);
+ yield front.stopProfiler();
+
+ do_check_true(eventsCalled === 0, "No 'profiler-status' events should be fired before registering.");
+
+ let ret = yield front.registerEventNotifications({ events: ["profiler-status"] });
+ do_check_true(ret.registered.length === 1);
+
+ yield front.startProfiler();
+ yield handledThreeTimes.promise;
+ yield front.stopProfiler();
+ do_check_true(eventsCalled >= 3, "profiler-status fired atleast three times while recording");
+
+ let totalEvents = eventsCalled;
+ yield waitForTime(50);
+ do_check_true(totalEvents === eventsCalled, "No more profiler-status events after recording.");
+});
+
+function getChromeActors() {
+ let deferred = promise.defer();
+ get_chrome_actors((client, form) => deferred.resolve([client, form]));
+ return deferred.promise;
+}