text-based-repaint.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Asynchronous tests should manually call finishRepaintTest at the appropriate
  2. // time.
  3. window.testIsAsync = false;
  4. window.outputRepaintRects = true;
  5. // All repaint tests are asynchronous.
  6. if (window.testRunner)
  7. testRunner.waitUntilDone();
  8. if (window.internals)
  9. internals.runtimeFlags.paintUnderInvalidationCheckingEnabled = true;
  10. // Add string names of objects that should be invalidated here. If you use this feature,
  11. // you must also include testharness.js.
  12. window.expectedObjectInvalidations = [];
  13. // Objects which must *not* be invalidated.
  14. window.expectedObjectNonInvalidations = [];
  15. function runRepaintTest()
  16. {
  17. if (!window.testRunner || !window.internals) {
  18. setTimeout(repaintTest, 500);
  19. return;
  20. }
  21. if (window.enablePixelTesting)
  22. testRunner.dumpAsTextWithPixelResults();
  23. else
  24. testRunner.dumpAsText();
  25. // This is equivalent to runAfterLayoutAndPaint() in
  26. // ../../resources/run-after-layout-and-paint.js. Duplicate it here so that
  27. // the callers don't need to include that file.
  28. requestAnimationFrame(() => {
  29. setTimeout(() => {
  30. internals.startTrackingRepaints(top.document);
  31. repaintTest();
  32. if (!window.testIsAsync)
  33. finishRepaintTest();
  34. }, 0);
  35. });
  36. }
  37. function runRepaintAndPixelTest()
  38. {
  39. window.enablePixelTesting = true;
  40. runRepaintTest();
  41. }
  42. function finishRepaintTest()
  43. {
  44. if (!window.testRunner || !window.internals)
  45. return;
  46. var flags = internals.LAYER_TREE_INCLUDES_INVALIDATIONS;
  47. if (window.layerTreeAsTextAdditionalFlags)
  48. flags |= layerTreeAsTextAdditionalFlags;
  49. var layersWithInvalidationsText = internals.layerTreeAsText(top.document, flags);
  50. internals.stopTrackingRepaints(top.document);
  51. // Play nice with JS tests which may want to print out assert results.
  52. if (window.isJsTest)
  53. window.outputRepaintRects = false;
  54. if (window.outputRepaintRects)
  55. testRunner.setCustomTextOutput(layersWithInvalidationsText);
  56. if (window.afterTest)
  57. window.afterTest();
  58. // Play nice with async JS tests which want to notifyDone themselves.
  59. if (!window.jsTestIsAsync)
  60. testRunner.notifyDone();
  61. }