head.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. const { require, loader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  5. /* exported loader, either, click, dblclick, mousedown, rightMousedown, key */
  6. // All tests are asynchronous.
  7. waitForExplicitFinish();
  8. // Performance tests are much heavier because of their reliance on the
  9. // profiler module, memory measurements, frequent canvas operations etc. Many of
  10. // of them take longer than 30 seconds to finish on try server VMs, even though
  11. // they superficially do very little.
  12. requestLongerTimeout(3);
  13. // Same as `is`, but takes in two possible values.
  14. const either = (value, a, b, message) => {
  15. if (value == a) {
  16. is(value, a, message);
  17. } else if (value == b) {
  18. is(value, b, message);
  19. } else {
  20. ok(false, message);
  21. }
  22. };
  23. // Shortcut for simulating a click on an element.
  24. const click = (node, win = window) => {
  25. EventUtils.sendMouseEvent({ type: "click" }, node, win);
  26. };
  27. // Shortcut for simulating a double click on an element.
  28. const dblclick = (node, win = window) => {
  29. EventUtils.sendMouseEvent({ type: "dblclick" }, node, win);
  30. };
  31. // Shortcut for simulating a mousedown on an element.
  32. const mousedown = (node, win = window) => {
  33. EventUtils.sendMouseEvent({ type: "mousedown" }, node, win);
  34. };
  35. // Shortcut for simulating a mousedown using the right mouse button on an element.
  36. const rightMousedown = (node, win = window) => {
  37. EventUtils.sendMouseEvent({ type: "mousedown", button: 2 }, node, win);
  38. };
  39. // Shortcut for firing a key event, like "VK_UP", "VK_DOWN", etc.
  40. const key = (id, win = window) => {
  41. EventUtils.synthesizeKey(id, {}, win);
  42. };
  43. // Don't pollute global scope.
  44. (() => {
  45. const flags = require("devtools/shared/flags");
  46. const PrefUtils = require("devtools/client/performance/test/helpers/prefs");
  47. flags.testing = true;
  48. // Make sure all the prefs are reverted to their defaults once tests finish.
  49. let stopObservingPrefs = PrefUtils.whenUnknownPrefChanged("devtools.performance",
  50. pref => {
  51. ok(false, `Unknown pref changed: ${pref}. Please add it to test/helpers/prefs.js ` +
  52. "to make sure it's reverted to its default value when the tests finishes, " +
  53. "and avoid interfering with future tests.\n");
  54. });
  55. // By default, enable memory flame graphs for tests for now.
  56. // TODO: remove when we have flame charts via bug 1148663.
  57. Services.prefs.setBoolPref(PrefUtils.UI_ENABLE_MEMORY_FLAME_CHART, true);
  58. registerCleanupFunction(() => {
  59. info("finish() was called, cleaning up...");
  60. flags.testing = false;
  61. PrefUtils.rollbackPrefsToDefault();
  62. stopObservingPrefs();
  63. // Manually stop the profiler module at the end of all tests, to hopefully
  64. // avoid at least some leaks on OSX. Theoretically the module should never
  65. // be active at this point. We shouldn't have to do this, but rather
  66. // find and fix the leak in the module itself. Bug 1257439.
  67. let nsIProfilerModule = Cc["@mozilla.org/tools/profiler;1"]
  68. .getService(Ci.nsIProfiler);
  69. nsIProfilerModule.StopProfiler();
  70. // Forces GC, CC and shrinking GC to get rid of disconnected docshells
  71. // and windows.
  72. Cu.forceGC();
  73. Cu.forceCC();
  74. Cu.forceShrinkingGC();
  75. });
  76. })();