Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/repaint/resources/text-based-repaint.js

Issue 1972273002: Let repaint tests test pixels by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Asynchronous tests should manually call finishRepaintTest at the appropriate
2 // time.
3 window.testIsAsync = false;
4 window.outputRepaintRects = true;
5 window.generateMinimumRepaint = false; // See comments about 'Minimum repaint' b elow.
6
7 // All repaint tests are asynchronous.
8 if (window.testRunner)
9 testRunner.waitUntilDone();
10
11 function runRepaintTest()
12 {
13 if (!window.testRunner || !window.internals) {
14 setTimeout(repaintTest, 500);
15 return;
16 }
17
18 // TODO(enne): this is a workaround for multiple svg onload events.
19 // See: http://crbug.com/372946
20 if (window.hasRunRepaintTest)
21 return;
22 window.hasRunRepaintTest = true;
23
24 if (window.enablePixelTesting)
25 testRunner.dumpAsTextWithPixelResults();
26 else
27 testRunner.dumpAsText();
28
29 function continueRepaintTest()
30 {
31 window.internals.startTrackingRepaints(document);
32 repaintTest();
33 if (!window.testIsAsync)
34 finishRepaintTest();
35 }
36
37 if (window.generateMinimumRepaint) {
38 testRunner.capturePixelsAsyncThen(function(width, height, snapshot) {
39 window.widthBeforeRepaint = width;
40 window.heightBeforeRepaint = height;
41 window.snapshotBeforeRepaint = snapshot;
42 continueRepaintTest();
43 });
44 } else {
45 testRunner.layoutAndPaintAsyncThen(continueRepaintTest);
46 };
47 }
48
49 function runRepaintAndPixelTest()
50 {
51 window.enablePixelTesting = true;
52 runRepaintTest();
53 }
54
55 function forceStyleRecalc()
56 {
57 if (document.body)
58 document.body.clientTop;
59 else if (document.documentElement)
60 document.documentElement.clientTop;
61 }
62
63 function finishRepaintTest()
64 {
65 if (!window.testRunner || !window.internals)
66 return;
67
68 // Force a style recalc.
69 forceStyleRecalc();
70
71 var flags = window.internals.LAYER_TREE_INCLUDES_PAINT_INVALIDATIONS;
72
73 if (window.layerTreeAsTextAdditionalFlags)
74 flags |= window.layerTreeAsTextAdditionalFlags;
75
76 var repaintRects = window.internals.layerTreeAsText(document, flags);
77
78 internals.stopTrackingRepaints(document);
79
80 function repaintTestDone()
81 {
82 // Play nice with JS tests which may want to print out assert results.
83 if (window.isJsTest)
84 window.outputRepaintRects = false;
85
86 if (window.outputRepaintRects)
87 testRunner.setCustomTextOutput(repaintRects);
88
89 if (window.afterTest)
90 window.afterTest();
91
92 // Play nice with async JS tests which want to notifyDone themselves.
93 if (!window.jsTestIsAsync)
94 testRunner.notifyDone();
95 }
96
97 if (window.generateMinimumRepaint) {
98 internals.forceFullRepaint(document);
99 testRunner.capturePixelsAsyncThen(function(width, height, snapshot) {
100 if (window.outputRepaintRects) {
101 var minimumRepaint = computeMinimumRepaint(width, height, snapsh ot);
102 if (minimumRepaint.length)
103 repaintRects += '\nMinimum repaint:\n' + JSON.stringify(mini mumRepaint, null, 2);
104 }
105 repaintTestDone();
106 });
107 } else {
108 repaintTestDone();
109 }
110 }
111
112 // Minimum repaint
113 //
114 // Definitions
115 // - minimum-repaint = region(diff(snapshot-before-repaintTest,
116 // snapshot-after-repaintTest-and-full-repaint))
117 // It includes all pixels that should be changed after repaintTest.
118 // - actual-repaint = repaint rects recorded during repaintTest() and
119 // forceStyleRecalc().
120 // - potential-under-repaint = subtract(minimum-repaint, actual-repaint)
121 // Potential-under-repaint will be shown in layout test overlay in black if
122 // any minimum-repaint region is not covered by actual-repaint.
123 //
124 // Potential-under-repaints don't always mean bug:
125 // - Some know visualization issues (crbug.com/381221) may cause false
126 // under-repaint;
127 // - Screen updates caused by composited layer re-compositing may not need
128 // repaint.
129 //
130 // How to use
131 // 1. Set window.generateMinimumRepaint to true in some repaint test or change
132 // this script to force window.generateMinimumRepaint to true.
133 // 2. Run layout tests. Repaint tests will result text diffs, which is because
134 // of the minimum repaint output in the actual results and doesn't mean the
135 // tests failed.
136 // 3. In layout test result page, click 'overlay' link or expand the test to
137 // see the 'overlay' pane.
138 // 4. Click 'Highlight under-repaint' button. You'll see black region if there
139 // is any under-repaint.
140 //
141 // Known issues
142 // crbug.com/381221
143
144 function computeMinimumRepaint(width, height, snapshot)
145 {
146 var result = [];
147 if (width > widthBeforeRepaint) {
148 result.push([widthBeforeRepaint, 0, width - widthBeforeRepaint, Math.max (height, heightBeforeRepaint)]);
149 width = widthBeforeRepaint;
150 }
151 if (height > heightBeforeRepaint) {
152 result.push([0, heightBeforeRepaint, width, height - heightBeforeRepaint ]);
153 height = heightBeforeRepaint;
154 }
155
156 var dataBefore = new Uint32Array(snapshotBeforeRepaint);
157 var dataAfter = new Uint32Array(snapshot);
158 var rectsMayContinue = [];
159 var index = 0;
160 for (var y = 0; y < height; ++y) {
161 var x = 0;
162 var rectsMayContinueIndex = 0;
163 var nextRectsMayContinue = [];
164 while (true) {
165 while (x < width && dataBefore[index] == dataAfter[index]) {
166 ++x;
167 ++index;
168 }
169 xBegin = x;
170 while (x < width && dataBefore[index] != dataAfter[index]) {
171 ++x;
172 ++index;
173 }
174 xEnd = x;
175
176 var xWidth = xEnd - xBegin;
177 if (!xWidth)
178 break;
179
180 var rectMayContinue = rectsMayContinue[rectsMayContinueIndex];
181 while (rectMayContinue && rectMayContinue[0] < xBegin)
182 rectMayContinue = rectsMayContinue[++rectsMayContinueIndex];
183
184 if (rectMayContinue && rectMayContinue[0] == xBegin && rectMayContin ue[2] == xWidth) {
185 ++rectMayContinue[3];
186 nextRectsMayContinue.push(rectMayContinue);
187 } else {
188 var newRect = [xBegin, y, xWidth, 1];
189 nextRectsMayContinue.push(newRect);
190 result.push(newRect);
191 }
192 }
193 rectsMayContinue = nextRectsMayContinue;
194 }
195 return result;
196 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698