Index: third_party/WebKit/LayoutTests/http/tests/resources/run-after-layout-and-paint.js |
diff --git a/third_party/WebKit/LayoutTests/http/tests/resources/run-after-layout-and-paint.js b/third_party/WebKit/LayoutTests/http/tests/resources/run-after-layout-and-paint.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e3173417aef5084f6c544b271507c86295c9b011 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/resources/run-after-layout-and-paint.js |
@@ -0,0 +1,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(); |
+ }); |
+} |