forked from WebKit/Speedometer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-invoker.mjs
More file actions
55 lines (51 loc) · 1.62 KB
/
Copy pathtest-invoker.mjs
File metadata and controls
55 lines (51 loc) · 1.62 KB
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
class TestInvoker {
constructor(syncCallback, asyncCallback, reportCallback, params) {
this._syncCallback = syncCallback;
this._asyncCallback = asyncCallback;
this._reportCallback = reportCallback;
this._params = params;
}
}
export class TimerTestInvoker extends TestInvoker {
start() {
return new Promise((resolve) => {
setTimeout(() => {
this._syncCallback();
setTimeout(() => {
this._asyncCallback();
requestAnimationFrame(async () => {
const result = await this._reportCallback();
resolve(result);
});
}, 0);
}, this._params.waitBeforeSync);
});
}
}
export class RAFTestInvoker extends TestInvoker {
start() {
return new Promise((resolve) => {
if (this._params.waitBeforeSync)
setTimeout(() => this._scheduleCallbacks(resolve), this._params.waitBeforeSync);
else
this._scheduleCallbacks(resolve);
});
}
_scheduleCallbacks(resolve) {
requestAnimationFrame(() => this._syncCallback());
requestAnimationFrame(() => {
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
const result = await this._reportCallback();
resolve(result);
}, 0);
}, 0);
});
}
}
export const TEST_INVOKER_LOOKUP = {
__proto__: null,
timer: TimerTestInvoker,
raf: RAFTestInvoker,
};