test_profiler_activation-02.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests whether the profiler actor correctly handles the case where the
  6. * built-in module was already started.
  7. */
  8. const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
  9. const WAIT_TIME = 1000; // ms
  10. function run_test()
  11. {
  12. // Ensure the profiler is already running when the test starts.
  13. Profiler.StartProfiler(1000000, 1, ["js"], 1);
  14. DevToolsUtils.waitForTime(WAIT_TIME).then(() => {
  15. get_chrome_actors((client, form) => {
  16. let actor = form.profilerActor;
  17. test_start_time(client, actor, () => {
  18. client.close().then(do_test_finished);
  19. });
  20. });
  21. });
  22. do_test_pending();
  23. }
  24. function test_start_time(client, actor, callback) {
  25. // Profiler should already be active at this point.
  26. client.request({ to: actor, type: "isActive" }, firstResponse => {
  27. do_check_true(Profiler.IsActive());
  28. do_check_true(firstResponse.isActive);
  29. do_check_true(firstResponse.currentTime > 0);
  30. client.request({ to: actor, type: "getProfile" }, secondResponse => {
  31. do_check_true("profile" in secondResponse);
  32. do_check_true(secondResponse.currentTime > firstResponse.currentTime);
  33. callback();
  34. });
  35. });
  36. }