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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
/* Any copyright is dedicated to the Public Domain.
yield new Promise(function(){});
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* global window, document, SimpleTest, requestAnimationFrame, is, ok */
/* exported Cc, Ci, Cu, Cr, Assert, Task, TargetFactory, Toolbox, browserRequire,
forceRender, setProps, dumpn, checkOptimizationHeader, checkOptimizationTree */
let { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
let { require } = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {});
let { Assert } = require("resource://testing-common/Assert.jsm");
let { BrowserLoader } = Cu.import("resource://devtools/client/shared/browser-loader.js", {});
let defer = require("devtools/shared/defer");
let flags = require("devtools/shared/flags");
let { Task } = require("devtools/shared/task");
let { TargetFactory } = require("devtools/client/framework/target");
let { Toolbox } = require("devtools/client/framework/toolbox");
flags.testing = true;
let { require: browserRequire } = BrowserLoader({
baseURI: "resource://devtools/client/performance/",
window
});
let $ = (selector, scope = document) => scope.querySelector(selector);
let $$ = (selector, scope = document) => scope.querySelectorAll(selector);
function forceRender(comp) {
return setState(comp, {})
.then(() => setState(comp, {}));
}
// All tests are asynchronous.
SimpleTest.waitForExplicitFinish();
function onNextAnimationFrame(fn) {
return () =>
requestAnimationFrame(() =>
requestAnimationFrame(fn));
}
function setState(component, newState) {
let deferred = defer();
component.setState(newState, onNextAnimationFrame(deferred.resolve));
return deferred.promise;
}
function setProps(component, newState) {
let deferred = defer();
component.setProps(newState, onNextAnimationFrame(deferred.resolve));
return deferred.promise;
}
function dumpn(msg) {
dump(`PERFORMANCE-COMPONENT-TEST: ${msg}\n`);
}
/**
* Default opts data for testing. First site has a simple IonType,
* and an IonType with an ObservedType, and a successful outcome.
* Second site does not have a successful outcome.
*/
let OPTS_DATA_GENERAL = [{
id: 1,
propertyName: "my property name",
line: 100,
column: 200,
samples: 90,
data: {
attempts: [
{ id: 1, strategy: "GetElem_TypedObject", outcome: "AccessNotTypedObject" },
{ id: 1, strategy: "GetElem_Dense", outcome: "AccessNotDense" },
{ id: 1, strategy: "GetElem_TypedStatic", outcome: "Disabled" },
{ id: 1, strategy: "GetElem_TypedArray", outcome: "GenericSuccess" },
],
types: [{
id: 1,
site: "Receiver",
mirType: "Object",
typeset: [{
id: 1,
keyedBy: "constructor",
name: "MyView",
location: "http://internet.com/file.js",
line: "123",
}]
}, {
id: 1,
typeset: void 0,
site: "Index",
mirType: "Int32",
}]
}
}, {
id: 2,
propertyName: void 0,
line: 50,
column: 51,
samples: 100,
data: {
attempts: [
{ id: 2, strategy: "Call_Inline", outcome: "CantInlineBigData" }
],
types: [{
id: 2,
site: "Call_Target",
mirType: "Object",
typeset: [
{ id: 2, keyedBy: "primitive" },
{ id: 2, keyedBy: "constructor", name: "B", location: "http://mypage.com/file.js", line: "2" },
{ id: 2, keyedBy: "constructor", name: "C", location: "http://mypage.com/file.js", line: "3" },
{ id: 2, keyedBy: "constructor", name: "D", location: "http://mypage.com/file.js", line: "4" },
],
}]
}
}];
OPTS_DATA_GENERAL.forEach(site => {
site.data.types.forEach(type => {
if (type.typeset) {
type.typeset.id = site.id;
}
});
site.data.attempts.id = site.id;
site.data.types.id = site.id;
});
function checkOptimizationHeader(name, file, line) {
is($(".optimization-header .header-function-name").textContent, name,
"correct optimization header function name");
is($(".optimization-header .frame-link-filename").textContent, file,
"correct optimization header file name");
is($(".optimization-header .frame-link-line").textContent, `:${line}`,
"correct optimization header line");
}
function checkOptimizationTree(rowData) {
let rows = $$(".tree .tree-node");
for (let i = 0; i < rowData.length; i++) {
let row = rows[i];
let expected = rowData[i];
switch (expected.type) {
case "site":
is($(".optimization-site-title", row).textContent,
`${expected.strategy} – (${expected.samples} samples)`,
`row ${i}th: correct optimization site row`);
is(!!$(".opt-icon.warning", row), !!expected.failureIcon,
`row ${i}th: expected visibility of failure icon for unsuccessful outcomes`);
break;
case "types":
is($(".optimization-types", row).textContent,
`Types (${expected.count})`,
`row ${i}th: correct types row`);
break;
case "attempts":
is($(".optimization-attempts", row).textContent,
`Attempts (${expected.count})`,
`row ${i}th: correct attempts row`);
break;
case "type":
is($(".optimization-ion-type", row).textContent,
`${expected.site}:${expected.mirType}`,
`row ${i}th: correct ion type row`);
break;
case "observedtype":
is($(".optimization-observed-type-keyed", row).textContent,
expected.name ?
`${expected.keyedBy} → ${expected.name}` :
expected.keyedBy,
`row ${i}th: correct observed type row`);
break;
case "attempt":
is($(".optimization-strategy", row).textContent, expected.strategy,
`row ${i}th: correct attempt row, attempt item`);
is($(".optimization-outcome", row).textContent, expected.outcome,
`row ${i}th: correct attempt row, outcome item`);
ok($(".optimization-outcome", row)
.classList.contains(expected.success ? "success" : "failure"),
`row ${i}th: correct attempt row, failure/success status`);
break;
}
}
}
|