test_profiler_activation-01.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 module and actor have the correct state on
  6. * initialization, activation, and when a clients' connection closes.
  7. */
  8. const Profiler = Cc["@mozilla.org/tools/profiler;1"].getService(Ci.nsIProfiler);
  9. const MAX_PROFILER_ENTRIES = 10000000;
  10. function run_test()
  11. {
  12. // Ensure the profiler is not running when the test starts (it could
  13. // happen if the MOZ_PROFILER_STARTUP environment variable is set).
  14. Profiler.StopProfiler();
  15. get_chrome_actors((client1, form1) => {
  16. let actor1 = form1.profilerActor;
  17. get_chrome_actors((client2, form2) => {
  18. let actor2 = form2.profilerActor;
  19. test_activate(client1, actor1, client2, actor2, () => {
  20. do_test_finished();
  21. });
  22. });
  23. });
  24. do_test_pending();
  25. }
  26. function test_activate(client1, actor1, client2, actor2, callback) {
  27. // Profiler should be inactive at this point.
  28. client1.request({ to: actor1, type: "isActive" }, response => {
  29. do_check_false(Profiler.IsActive());
  30. do_check_false(response.isActive);
  31. do_check_eq(response.currentTime, undefined);
  32. do_check_true(typeof response.position === "number");
  33. do_check_true(typeof response.totalSize === "number");
  34. do_check_true(typeof response.generation === "number");
  35. // Start the profiler on the first connection....
  36. client1.request({ to: actor1, type: "startProfiler", entries: MAX_PROFILER_ENTRIES }, response => {
  37. do_check_true(Profiler.IsActive());
  38. do_check_true(response.started);
  39. do_check_true(typeof response.position === "number");
  40. do_check_true(typeof response.totalSize === "number");
  41. do_check_true(typeof response.generation === "number");
  42. do_check_true(response.position >= 0 && response.position < response.totalSize);
  43. do_check_true(response.totalSize === MAX_PROFILER_ENTRIES);
  44. // On the next connection just make sure the actor has been instantiated.
  45. client2.request({ to: actor2, type: "isActive" }, response => {
  46. do_check_true(Profiler.IsActive());
  47. do_check_true(response.isActive);
  48. do_check_true(response.currentTime > 0);
  49. do_check_true(typeof response.position === "number");
  50. do_check_true(typeof response.totalSize === "number");
  51. do_check_true(typeof response.generation === "number");
  52. do_check_true(response.position >= 0 && response.position < response.totalSize);
  53. do_check_true(response.totalSize === MAX_PROFILER_ENTRIES);
  54. let origConnectionClosed = DebuggerServer._connectionClosed;
  55. DebuggerServer._connectionClosed = function (conn) {
  56. origConnectionClosed.call(this, conn);
  57. // The first client is the only actor that started the profiler,
  58. // however the second client can request the accumulated profile data
  59. // at any moment, so the profiler module shouldn't have deactivated.
  60. do_check_true(Profiler.IsActive());
  61. DebuggerServer._connectionClosed = function (conn) {
  62. origConnectionClosed.call(this, conn);
  63. // Now there are no open clients at all, it should *definitely*
  64. // be deactivated by now.
  65. do_check_false(Profiler.IsActive());
  66. callback();
  67. };
  68. client2.close();
  69. };
  70. client1.close();
  71. });
  72. });
  73. });
  74. }