test_profiler_events-01.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests the event notification service for the profiler actor.
  6. */
  7. const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
  8. const { ProfilerFront } = require("devtools/shared/fronts/profiler");
  9. function run_test() {
  10. run_next_test();
  11. }
  12. add_task(function* () {
  13. let [client, form] = yield getChromeActors();
  14. let front = new ProfilerFront(client, form);
  15. let events = [0, 0, 0, 0];
  16. front.on("console-api-profiler", () => events[0]++);
  17. front.on("profiler-started", () => events[1]++);
  18. front.on("profiler-stopped", () => events[2]++);
  19. client.addListener("eventNotification", (type, response) => {
  20. do_check_true(type === "eventNotification");
  21. events[3]++;
  22. });
  23. yield front.startProfiler();
  24. yield front.stopProfiler();
  25. // All should be empty without binding events
  26. do_check_true(events[0] === 0);
  27. do_check_true(events[1] === 0);
  28. do_check_true(events[2] === 0);
  29. do_check_true(events[3] === 0);
  30. let ret = yield front.registerEventNotifications({ events: ["console-api-profiler", "profiler-started", "profiler-stopped"] });
  31. do_check_true(ret.registered.length === 3);
  32. yield front.startProfiler();
  33. do_check_true(events[0] === 0);
  34. do_check_true(events[1] === 1);
  35. do_check_true(events[2] === 0);
  36. do_check_true(events[3] === 1, "compatibility events supported for eventNotifications");
  37. yield front.stopProfiler();
  38. do_check_true(events[0] === 0);
  39. do_check_true(events[1] === 1);
  40. do_check_true(events[2] === 1);
  41. do_check_true(events[3] === 2, "compatibility events supported for eventNotifications");
  42. ret = yield front.unregisterEventNotifications({ events: ["console-api-profiler", "profiler-started", "profiler-stopped"] });
  43. do_check_true(ret.registered.length === 3);
  44. });
  45. function getChromeActors() {
  46. let deferred = promise.defer();
  47. get_chrome_actors((client, form) => deferred.resolve([client, form]));
  48. return deferred.promise;
  49. }