blob: 8d18d26a0af694d76204e41124364cece7a0bd9d [file] [log] [blame]
Xianzhu Wangeca17772019-01-08 23:15:151// Run a callback after a frame update.
[email protected]a0f4d1dc2015-02-26 01:31:432//
Xianzhu Wangeca17772019-01-08 23:15:153// Note that this file has two copies:
4// resources/run-after-layout-and-paint.js
5// and
6// http/tests/resources/run-after-layout-and-paint.js.
7// They should be kept always the same.
8//
9// The function runAfterLayoutAndPaint() has two modes:
10// - traditional mode, for existing tests, and tests needing customized
11// notifyDone timing:
[email protected]a0f4d1dc2015-02-26 01:31:4312// if (window.testRunner)
13// testRunner.waitUntilDone();
[email protected]334039da2015-05-08 03:38:4714// runAfterLayoutAndPaint(function() {
[email protected]a0f4d1dc2015-02-26 01:31:4315// ... // some code which modifies style/layout
16// if (window.testRunner)
17// testRunner.notifyDone();
[email protected]a0f4d1dc2015-02-26 01:31:4318// // Or notifyDone any time later if needed.
19// });
20//
Xianzhu Wangeca17772019-01-08 23:15:1521// - autoNotifyDone mode, for new tests which just need to change style/layout
22// and finish:
[email protected]334039da2015-05-08 03:38:4723// runAfterLayoutAndPaint(function() {
[email protected]a0f4d1dc2015-02-26 01:31:4324// ... // some code which modifies style/layout
25// }, true);
Xianzhu Wangeca17772019-01-08 23:15:1526//
27// Note that because we always update a frame before finishing a test,
28// we don't need
29// runAfterLayoutAndPaint(function() { testRunner.notifyDone(); })
30// to ensure the test finish after a frame update.
31//
wangxianzhuecaad1e2016-07-18 16:54:5532if (window.internals)
wangxianzhu5d28b2b62016-09-07 00:41:3033 internals.runtimeFlags.paintUnderInvalidationCheckingEnabled = true;
wangxianzhu86f41e762016-06-30 23:56:5734
[email protected]334039da2015-05-08 03:38:4735function runAfterLayoutAndPaint(callback, autoNotifyDone) {
[email protected]a0f4d1dc2015-02-26 01:31:4336 if (!window.testRunner) {
37 // For manual test. Delay 500ms to allow us to see the visual change
38 // caused by the callback.
39 setTimeout(callback, 500);
40 return;
41 }
42
43 if (autoNotifyDone)
44 testRunner.waitUntilDone();
45
Xianzhu Wangeca17772019-01-08 23:15:1546 // We do requestAnimationFrame and setTimeout to ensure a frame has started
47 // and layout and paint have run. The requestAnimationFrame fires after the
48 // frame has started but before layout and paint. The setTimeout fires
49 // at the beginning of the next frame, meaning that the previous frame has
50 // completed layout and paint.
51 // See http://crrev.com/c/1395193/10/third_party/blink/web_tests/http/tests/resources/run-after-layout-and-paint.js
52 // for more discussions.
53 requestAnimationFrame(function() {
54 setTimeout(function() {
55 callback();
56 if (autoNotifyDone)
57 testRunner.notifyDone();
Wanming Lin79ddcf82020-12-18 05:51:0058 }, 1);
[email protected]8866d952014-02-28 01:14:1059 });
60}
Alice Boxhall2e842492019-02-27 19:48:4461
62function test_after_layout_and_paint(func, name, properties) {
63 var test = async_test(name, properties);
64 runAfterLayoutAndPaint(test.step_func(() => {
65 func.call(test, test);
66 test.done();
67 }, false));
68}
69
70function async_test_after_layout_and_paint(func, name, properties) {
71 var test = async_test(name, properties);
72 runAfterLayoutAndPaint(test.step_func(() => {
73 func.call(test, test);
74 }, false));
75}