forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun-after-layout-and-paint.js
43 lines (39 loc) · 1.44 KB
/
run-after-layout-and-paint.js
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
// Run a callback after layout and paint of all pending document changes.
//
// It has two modes:
// - traditional mode, for existing tests, and tests needing customized notifyDone timing:
// Usage:
// if (window.testRunner)
// testRunner.waitUntilDone();
// runAfterLayoutAndPaint(function() {
// ... // some code which modifies style/layout
// if (window.testRunner)
// testRunner.notifyDone();
// // Or to ensure the next paint is executed before the test finishes:
// // if (window.testRunner)
// // runAfterAfterLayoutAndPaint(function() { testRunner.notifyDone() });
// // Or notifyDone any time later if needed.
// });
//
// - autoNotifyDone mode, for new tests which just need to change style/layout and finish:
// Usage:
// runAfterLayoutAndPaint(function() {
// ... // some code which modifies style/layout
// }, true);
if (window.internals)
internals.runtimeFlags.paintUnderInvalidationCheckingEnabled = true;
function runAfterLayoutAndPaint(callback, autoNotifyDone) {
if (!window.testRunner) {
// For manual test. Delay 500ms to allow us to see the visual change
// caused by the callback.
setTimeout(callback, 500);
return;
}
if (autoNotifyDone)
testRunner.waitUntilDone();
testRunner.layoutAndPaintAsyncThen(function() {
callback();
if (autoNotifyDone)
testRunner.notifyDone();
});
}