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

Side by Side Diff: LayoutTests/resources/check-layout.js

Issue 22918026: Porting WebKit 114900 to blink: checkLayout() should error out if no data-expected* attributes were… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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
« no previous file with comments | « LayoutTests/fast/check-layout-error-no-attributes-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 if (window.testRunner) 1 if (window.testRunner)
2 testRunner.dumpAsText(); 2 testRunner.dumpAsText();
3 3
4 (function() { 4 (function() {
5 5
6 function insertAfter(nodeToAdd, referenceNode) 6 function insertAfter(nodeToAdd, referenceNode)
7 { 7 {
8 if (referenceNode == document.body) { 8 if (referenceNode == document.body) {
9 document.body.appendChild(nodeToAdd); 9 document.body.appendChild(nodeToAdd);
10 return; 10 return;
11 } 11 }
12 12
13 if (referenceNode.nextSibling) 13 if (referenceNode.nextSibling)
14 referenceNode.parentNode.insertBefore(nodeToAdd, referenceNode.nextSibli ng); 14 referenceNode.parentNode.insertBefore(nodeToAdd, referenceNode.nextSibli ng);
15 else 15 else
16 referenceNode.parentNode.appendChild(nodeToAdd); 16 referenceNode.parentNode.appendChild(nodeToAdd);
17 } 17 }
18 18
19 function checkSubtreeExpectedValues(parent, failures) 19 function checkSubtreeExpectedValues(parent, failures)
20 { 20 {
21 checkExpectedValues(parent, failures); 21 var checkedLayout = checkExpectedValues(parent, failures);
22 Array.prototype.forEach.call(parent.childNodes, function(node) { 22 Array.prototype.forEach.call(parent.childNodes, function(node) {
23 checkSubtreeExpectedValues(node, failures); 23 checkedLayout |= checkSubtreeExpectedValues(node, failures);
24 }); 24 });
25 return checkedLayout;
26 }
27
28 function checkAttribute(output, node, attribute)
29 {
30 var result = node.getAttribute && node.getAttribute(attribute);
31 output.checked |= !!result;
32 return result;
25 } 33 }
26 34
27 function checkExpectedValues(node, failures) 35 function checkExpectedValues(node, failures)
28 { 36 {
29 var expectedWidth = node.getAttribute && node.getAttribute("data-expected-wi dth"); 37 var output = { checked: false };
38 var expectedWidth = checkAttribute(output, node, "data-expected-width");
30 if (expectedWidth) { 39 if (expectedWidth) {
31 if (node.offsetWidth != parseInt(expectedWidth)) 40 if (node.offsetWidth != parseInt(expectedWidth))
32 failures.push("Expected " + expectedWidth + " for width, but got " + node.offsetWidth + ". "); 41 failures.push("Expected " + expectedWidth + " for width, but got " + node.offsetWidth + ". ");
33 } 42 }
34 43
35 var expectedHeight = node.getAttribute && node.getAttribute("data-expected-h eight"); 44 var expectedHeight = checkAttribute(output, node, "data-expected-height");
36 if (expectedHeight) { 45 if (expectedHeight) {
37 if (node.offsetHeight != parseInt(expectedHeight)) 46 if (node.offsetHeight != parseInt(expectedHeight))
38 failures.push("Expected " + expectedHeight + " for height, but got " + node.offsetHeight + ". "); 47 failures.push("Expected " + expectedHeight + " for height, but got " + node.offsetHeight + ". ");
39 } 48 }
40 49
41 var expectedOffset = node.getAttribute && node.getAttribute("data-offset-x") ; 50 var expectedOffset = checkAttribute(output, node, "data-offset-x");
42 if (expectedOffset) { 51 if (expectedOffset) {
43 if (node.offsetLeft != parseInt(expectedOffset)) 52 if (node.offsetLeft != parseInt(expectedOffset))
44 failures.push("Expected " + expectedOffset + " for offsetLeft, but g ot " + node.offsetLeft + ". "); 53 failures.push("Expected " + expectedOffset + " for offsetLeft, but g ot " + node.offsetLeft + ". ");
45 } 54 }
46 55
47 var expectedOffset = node.getAttribute && node.getAttribute("data-offset-y") ; 56 var expectedOffset = checkAttribute(output, node, "data-offset-y");
48 if (expectedOffset) { 57 if (expectedOffset) {
49 if (node.offsetTop != parseInt(expectedOffset)) 58 if (node.offsetTop != parseInt(expectedOffset))
50 failures.push("Expected " + expectedOffset + " for offsetTop, but go t " + node.offsetTop + ". "); 59 failures.push("Expected " + expectedOffset + " for offsetTop, but go t " + node.offsetTop + ". ");
51 } 60 }
52 61
53 var expectedWidth = node.getAttribute && node.getAttribute("data-expected-cl ient-width"); 62 var expectedWidth = checkAttribute(output, node, "data-expected-client-width ");
54 if (expectedWidth) { 63 if (expectedWidth) {
55 if (node.clientWidth != parseInt(expectedWidth)) 64 if (node.clientWidth != parseInt(expectedWidth))
56 failures.push("Expected " + expectedWidth + " for clientWidth, but g ot " + node.clientWidth + ". "); 65 failures.push("Expected " + expectedWidth + " for clientWidth, but g ot " + node.clientWidth + ". ");
57 } 66 }
58 67
59 var expectedHeight = node.getAttribute && node.getAttribute("data-expected-c lient-height"); 68 var expectedHeight = checkAttribute(output, node, "data-expected-client-heig ht");
60 if (expectedHeight) { 69 if (expectedHeight) {
61 if (node.clientHeight != parseInt(expectedHeight)) 70 if (node.clientHeight != parseInt(expectedHeight))
62 failures.push("Expected " + expectedHeight + " for clientHeight, but got " + node.clientHeight + ". "); 71 failures.push("Expected " + expectedHeight + " for clientHeight, but got " + node.clientHeight + ". ");
63 } 72 }
64 73
65 var expectedWidth = node.getAttribute && node.getAttribute("data-expected-sc roll-width"); 74 var expectedWidth = checkAttribute(output, node, "data-expected-scroll-width ");
66 if (expectedWidth) { 75 if (expectedWidth) {
67 if (node.scrollWidth != parseInt(expectedWidth)) 76 if (node.scrollWidth != parseInt(expectedWidth))
68 failures.push("Expected " + expectedWidth + " for scrollWidth, but g ot " + node.scrollWidth + ". "); 77 failures.push("Expected " + expectedWidth + " for scrollWidth, but g ot " + node.scrollWidth + ". ");
69 } 78 }
70 79
71 var expectedHeight = node.getAttribute && node.getAttribute("data-expected-s croll-height"); 80 var expectedHeight = checkAttribute(output, node, "data-expected-scroll-heig ht");
72 if (expectedHeight) { 81 if (expectedHeight) {
73 if (node.scrollHeight != parseInt(expectedHeight)) 82 if (node.scrollHeight != parseInt(expectedHeight))
74 failures.push("Expected " + expectedHeight + " for scrollHeight, but got " + node.scrollHeight + ". "); 83 failures.push("Expected " + expectedHeight + " for scrollHeight, but got " + node.scrollHeight + ". ");
75 } 84 }
76 85
77 var expectedOffset = node.getAttribute && node.getAttribute("data-total-x"); 86 var expectedOffset = checkAttribute(output, node, "data-total-x");
78 if (expectedOffset) { 87 if (expectedOffset) {
79 var totalLeft = node.clientLeft + node.offsetLeft; 88 var totalLeft = node.clientLeft + node.offsetLeft;
80 if (totalLeft != parseInt(expectedOffset)) 89 if (totalLeft != parseInt(expectedOffset))
81 failures.push("Expected " + expectedOffset + " for clientLeft+offset Left, but got " + totalLeft + ", clientLeft: " + node.clientLeft + ", offsetLeft : " + node.offsetLeft + ". "); 90 failures.push("Expected " + expectedOffset + " for clientLeft+offset Left, but got " + totalLeft + ", clientLeft: " + node.clientLeft + ", offsetLeft : " + node.offsetLeft + ". ");
82 } 91 }
83 92
84 var expectedOffset = node.getAttribute && node.getAttribute("data-total-y"); 93 var expectedOffset = checkAttribute(output, node, "data-total-y");
85 if (expectedOffset) { 94 if (expectedOffset) {
86 var totalTop = node.clientTop + node.offsetTop; 95 var totalTop = node.clientTop + node.offsetTop;
87 if (totalTop != parseInt(expectedOffset)) 96 if (totalTop != parseInt(expectedOffset))
88 failures.push("Expected " + expectedOffset + " for clientTop+offsetT op, but got " + totalTop + ", clientTop: " + node.clientTop + ", + offsetTop: " + node.offsetTop + ". "); 97 failures.push("Expected " + expectedOffset + " for clientTop+offsetT op, but got " + totalTop + ", clientTop: " + node.clientTop + ", + offsetTop: " + node.offsetTop + ". ");
89 } 98 }
90 99
91 var expectedDisplay = node.getAttribute && node.getAttribute("data-expected- display"); 100 var expectedDisplay = checkAttribute(output, node, "data-expected-display");
92 if (expectedDisplay) { 101 if (expectedDisplay) {
93 var actualDisplay = getComputedStyle(node).display; 102 var actualDisplay = getComputedStyle(node).display;
94 if (actualDisplay != expectedDisplay) 103 if (actualDisplay != expectedDisplay)
95 failures.push("Expected " + expectedDisplay + " for display, but got " + actualDisplay + ". "); 104 failures.push("Expected " + expectedDisplay + " for display, but got " + actualDisplay + ". ");
96 } 105 }
97 106
98 var expectedPaddingTop = node.getAttribute && node.getAttribute("data-expect ed-padding-top"); 107 var expectedPaddingTop = checkAttribute(output, node, "data-expected-padding -top");
99 if (expectedPaddingTop) { 108 if (expectedPaddingTop) {
100 var actualPaddingTop = getComputedStyle(node).paddingTop; 109 var actualPaddingTop = getComputedStyle(node).paddingTop;
101 // Trim the unit "px" from the output. 110 // Trim the unit "px" from the output.
102 actualPaddingTop = actualPaddingTop.substring(0, actualPaddingTop.length - 2); 111 actualPaddingTop = actualPaddingTop.substring(0, actualPaddingTop.length - 2);
103 if (actualPaddingTop != expectedPaddingTop) 112 if (actualPaddingTop != expectedPaddingTop)
104 failures.push("Expected " + expectedPaddingTop + " for padding-top, but got " + actualPaddingTop + ". "); 113 failures.push("Expected " + expectedPaddingTop + " for padding-top, but got " + actualPaddingTop + ". ");
105 } 114 }
106 115
107 var expectedPaddingBottom = node.getAttribute && node.getAttribute("data-exp ected-padding-bottom"); 116 var expectedPaddingBottom = checkAttribute(output, node, "data-expected-padd ing-bottom");
108 if (expectedPaddingBottom) { 117 if (expectedPaddingBottom) {
109 var actualPaddingBottom = getComputedStyle(node).paddingBottom; 118 var actualPaddingBottom = getComputedStyle(node).paddingBottom;
110 // Trim the unit "px" from the output. 119 // Trim the unit "px" from the output.
111 actualPaddingBottom = actualPaddingBottom.substring(0, actualPaddingBott om.length - 2); 120 actualPaddingBottom = actualPaddingBottom.substring(0, actualPaddingBott om.length - 2);
112 if (actualPaddingBottom != expectedPaddingBottom) 121 if (actualPaddingBottom != expectedPaddingBottom)
113 failures.push("Expected " + expectedPaddingBottom + " for padding-bo ttom, but got " + actualPaddingBottom + ". "); 122 failures.push("Expected " + expectedPaddingBottom + " for padding-bo ttom, but got " + actualPaddingBottom + ". ");
114 } 123 }
115 124
116 var expectedPaddingLeft = node.getAttribute && node.getAttribute("data-expec ted-padding-left"); 125 var expectedPaddingLeft = checkAttribute(output, node, "data-expected-paddin g-left");
117 if (expectedPaddingLeft) { 126 if (expectedPaddingLeft) {
118 var actualPaddingLeft = getComputedStyle(node).paddingLeft; 127 var actualPaddingLeft = getComputedStyle(node).paddingLeft;
119 // Trim the unit "px" from the output. 128 // Trim the unit "px" from the output.
120 actualPaddingLeft = actualPaddingLeft.substring(0, actualPaddingLeft.len gth - 2); 129 actualPaddingLeft = actualPaddingLeft.substring(0, actualPaddingLeft.len gth - 2);
121 if (actualPaddingLeft != expectedPaddingLeft) 130 if (actualPaddingLeft != expectedPaddingLeft)
122 failures.push("Expected " + expectedPaddingLeft + " for padding-left , but got " + actualPaddingLeft + ". "); 131 failures.push("Expected " + expectedPaddingLeft + " for padding-left , but got " + actualPaddingLeft + ". ");
123 } 132 }
124 133
125 var expectedPaddingRight = node.getAttribute && node.getAttribute("data-expe cted-padding-right"); 134 var expectedPaddingRight = checkAttribute(output, node, "data-expected-paddi ng-right");
126 if (expectedPaddingRight) { 135 if (expectedPaddingRight) {
127 var actualPaddingRight = getComputedStyle(node).paddingRight; 136 var actualPaddingRight = getComputedStyle(node).paddingRight;
128 // Trim the unit "px" from the output. 137 // Trim the unit "px" from the output.
129 actualPaddingRight = actualPaddingRight.substring(0, actualPaddingRight. length - 2); 138 actualPaddingRight = actualPaddingRight.substring(0, actualPaddingRight. length - 2);
130 if (actualPaddingRight != expectedPaddingRight) 139 if (actualPaddingRight != expectedPaddingRight)
131 failures.push("Expected " + expectedPaddingRight + " for padding-rig ht, but got " + actualPaddingRight + ". "); 140 failures.push("Expected " + expectedPaddingRight + " for padding-rig ht, but got " + actualPaddingRight + ". ");
132 } 141 }
133 142
134 var expectedMarginTop = node.getAttribute && node.getAttribute("data-expecte d-margin-top"); 143 var expectedMarginTop = checkAttribute(output, node, "data-expected-margin-t op");
135 if (expectedMarginTop) { 144 if (expectedMarginTop) {
136 var actualMarginTop = getComputedStyle(node).marginTop; 145 var actualMarginTop = getComputedStyle(node).marginTop;
137 // Trim the unit "px" from the output. 146 // Trim the unit "px" from the output.
138 actualMarginTop = actualMarginTop.substring(0, actualMarginTop.length - 2); 147 actualMarginTop = actualMarginTop.substring(0, actualMarginTop.length - 2);
139 if (actualMarginTop != expectedMarginTop) 148 if (actualMarginTop != expectedMarginTop)
140 failures.push("Expected " + expectedMarginTop + " for margin-top, bu t got " + actualMarginTop + ". "); 149 failures.push("Expected " + expectedMarginTop + " for margin-top, bu t got " + actualMarginTop + ". ");
141 } 150 }
142 151
143 var expectedMarginBottom = node.getAttribute && node.getAttribute("data-expe cted-margin-bottom"); 152 var expectedMarginBottom = checkAttribute(output, node, "data-expected-margi n-bottom");
144 if (expectedMarginBottom) { 153 if (expectedMarginBottom) {
145 var actualMarginBottom = getComputedStyle(node).marginBottom; 154 var actualMarginBottom = getComputedStyle(node).marginBottom;
146 // Trim the unit "px" from the output. 155 // Trim the unit "px" from the output.
147 actualMarginBottom = actualMarginBottom.substring(0, actualMarginBottom. length - 2); 156 actualMarginBottom = actualMarginBottom.substring(0, actualMarginBottom. length - 2);
148 if (actualMarginBottom != expectedMarginBottom) 157 if (actualMarginBottom != expectedMarginBottom)
149 failures.push("Expected " + expectedMarginBottom + " for margin-bott om, but got " + actualMarginBottom + ". "); 158 failures.push("Expected " + expectedMarginBottom + " for margin-bott om, but got " + actualMarginBottom + ". ");
150 } 159 }
151 160
152 var expectedMarginLeft = node.getAttribute && node.getAttribute("data-expect ed-margin-left"); 161 var expectedMarginLeft = checkAttribute(output, node, "data-expected-margin- left");
153 if (expectedMarginLeft) { 162 if (expectedMarginLeft) {
154 var actualMarginLeft = getComputedStyle(node).marginLeft; 163 var actualMarginLeft = getComputedStyle(node).marginLeft;
155 // Trim the unit "px" from the output. 164 // Trim the unit "px" from the output.
156 actualMarginLeft = actualMarginLeft.substring(0, actualMarginLeft.length - 2); 165 actualMarginLeft = actualMarginLeft.substring(0, actualMarginLeft.length - 2);
157 if (actualMarginLeft != expectedMarginLeft) 166 if (actualMarginLeft != expectedMarginLeft)
158 failures.push("Expected " + expectedMarginLeft + " for margin-left, but got " + actualMarginLeft + ". "); 167 failures.push("Expected " + expectedMarginLeft + " for margin-left, but got " + actualMarginLeft + ". ");
159 } 168 }
160 169
161 var expectedMarginRight = node.getAttribute && node.getAttribute("data-expec ted-margin-right"); 170 var expectedMarginRight = checkAttribute(output, node, "data-expected-margin -right");
162 if (expectedMarginRight) { 171 if (expectedMarginRight) {
163 var actualMarginRight = getComputedStyle(node).marginRight; 172 var actualMarginRight = getComputedStyle(node).marginRight;
164 // Trim the unit "px" from the output. 173 // Trim the unit "px" from the output.
165 actualMarginRight = actualMarginRight.substring(0, actualMarginRight.len gth - 2); 174 actualMarginRight = actualMarginRight.substring(0, actualMarginRight.len gth - 2);
166 if (actualMarginRight != expectedMarginRight) 175 if (actualMarginRight != expectedMarginRight)
167 failures.push("Expected " + expectedMarginRight + " for margin-right , but got " + actualMarginRight + ". "); 176 failures.push("Expected " + expectedMarginRight + " for margin-right , but got " + actualMarginRight + ". ");
168 } 177 }
178
179 return output.checked;
169 } 180 }
170 181
171 window.checkLayout = function(selectorList) 182 window.checkLayout = function(selectorList)
172 { 183 {
173 if (!selectorList) { 184 if (!selectorList) {
174 console.error("You must provide a CSS selector of nodes to check."); 185 console.error("You must provide a CSS selector of nodes to check.");
175 return; 186 return;
176 } 187 }
177 var nodes = document.querySelectorAll(selectorList); 188 var nodes = document.querySelectorAll(selectorList);
178 nodes = Array.prototype.slice.call(nodes); 189 nodes = Array.prototype.slice.call(nodes);
179 nodes.reverse(); 190 nodes.reverse();
191 var checkedLayout = false;
180 Array.prototype.forEach.call(nodes, function(node) { 192 Array.prototype.forEach.call(nodes, function(node) {
181 var failures = []; 193 var failures = [];
182 checkExpectedValues(node.parentNode, failures); 194 checkedLayout |= checkExpectedValues(node.parentNode, failures);
183 checkSubtreeExpectedValues(node, failures); 195 checkedLayout |= checkSubtreeExpectedValues(node, failures);
184 196
185 var container = node.parentNode.className == 'container' ? node.parentNo de : node; 197 var container = node.parentNode.className == 'container' ? node.parentNo de : node;
186 198
187 var pre = document.createElement('pre'); 199 var pre = document.createElement('pre');
188 if (failures.length) 200 if (failures.length)
189 pre.className = 'FAIL'; 201 pre.className = 'FAIL';
190 pre.appendChild(document.createTextNode(failures.length ? "FAIL:\n" + fa ilures.join('\n') + '\n\n' + container.outerHTML : "PASS")); 202 pre.appendChild(document.createTextNode(failures.length ? "FAIL:\n" + fa ilures.join('\n') + '\n\n' + container.outerHTML : "PASS"));
191 insertAfter(pre, container); 203 insertAfter(pre, container);
192 }); 204 });
205
206 if (!checkedLayout) {
207 document.body.innerHTML = "FAIL: No valid data-* attributes found in sel ector list : " + selectorList;
208 return;
209 }
210
193 var pre = document.querySelector('.FAIL'); 211 var pre = document.querySelector('.FAIL');
194 if (pre) 212 if (pre)
195 setTimeout(function() { pre.previousSibling.scrollIntoView(); }, 0); 213 setTimeout(function() { pre.previousSibling.scrollIntoView(); }, 0);
196 } 214 }
197 215
198 })(); 216 })();
OLDNEW
« no previous file with comments | « LayoutTests/fast/check-layout-error-no-attributes-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698