1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from ../../shared/test/telemetry-test-helpers.js */
"use strict";
const { require, loader } = ChromeUtils.import(
"resource://devtools/shared/Loader.jsm"
);
try {
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/shared/test/telemetry-test-helpers.js",
this
);
} catch (e) {
ok(
false,
"MISSING DEPENDENCY ON telemetry-test-helpers.js\n" +
"Please add the following line in browser.ini:\n" +
" !/devtools/client/shared/test/telemetry-test-helpers.js\n"
);
throw e;
}
/* exported loader, either, click, dblclick, mousedown, rightMousedown, key */
// All tests are asynchronous.
waitForExplicitFinish();
// Performance tests are much heavier because of their reliance on the
// profiler module, memory measurements, frequent canvas operations etc. Many of
// of them take longer than 30 seconds to finish on try server VMs, even though
// they superficially do very little.
requestLongerTimeout(3);
// Same as `is`, but takes in two possible values.
const either = (value, a, b, message) => {
if (value == a) {
is(value, a, message);
} else if (value == b) {
is(value, b, message);
} else {
ok(false, message);
}
};
// Shortcut for simulating a click on an element.
const click = async (node, win = window) => {
await EventUtils.sendMouseEvent({ type: "click" }, node, win);
};
// Shortcut for simulating a double click on an element.
const dblclick = async (node, win = window) => {
await EventUtils.sendMouseEvent({ type: "dblclick" }, node, win);
};
// Shortcut for simulating a mousedown on an element.
const mousedown = async (node, win = window) => {
await EventUtils.sendMouseEvent({ type: "mousedown" }, node, win);
};
// Shortcut for simulating a mousedown using the right mouse button on an element.
const rightMousedown = async (node, win = window) => {
await EventUtils.sendMouseEvent({ type: "mousedown", button: 2 }, node, win);
};
// Shortcut for firing a key event, like "VK_UP", "VK_DOWN", etc.
const key = (id, win = window) => {
EventUtils.synthesizeKey(id, {}, win);
};
// Don't pollute global scope.
(() => {
const PrefUtils = require("devtools/client/performance/test/helpers/prefs");
// Make sure all the prefs are reverted to their defaults once tests finish.
const stopObservingPrefs = PrefUtils.whenUnknownPrefChanged(
"devtools.performance",
pref => {
ok(
false,
`Unknown pref changed: ${pref}. Please add it to test/helpers/prefs.js ` +
"to make sure it's reverted to its default value when the tests finishes, " +
"and avoid interfering with future tests.\n"
);
}
);
// By default, enable memory flame graphs for tests for now.
// TODO: remove when we have flame charts via bug 1148663.
Services.prefs.setBoolPref(PrefUtils.UI_ENABLE_MEMORY_FLAME_CHART, true);
// By default, reduce the default buffer size to reduce the overhead when
// transfering the profile data. Hopefully this should help to reduce our
// intermittents for the performance tests.
Services.prefs.setIntPref(PrefUtils.PROFILER_BUFFER_SIZE_PREF, 100000);
registerCleanupFunction(() => {
info("finish() was called, cleaning up...");
PrefUtils.rollbackPrefsToDefault();
stopObservingPrefs();
// Manually stop the profiler module at the end of all tests, to hopefully
// avoid at least some leaks on OSX. Theoretically the module should never
// be active at this point. We shouldn't have to do this, but rather
// find and fix the leak in the module itself. Bug 1257439.
Services.profiler.StopProfiler();
// Forces GC, CC and shrinking GC to get rid of disconnected docshells
// and windows.
Cu.forceGC();
Cu.forceCC();
Cu.forceShrinkingGC();
});
})();
|