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

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

Issue 1458553005: Add variant of check-layout.js that uses testharness.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better error output, remove dead code Created 5 years, 1 month 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 | « third_party/WebKit/LayoutTests/css3/flexbox/stretched-child-shrink-on-relayout-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
(Empty)
1 (function() {
2 // Test is initiated from body.onload, so explicit done() call is required.
3 setup({ explicit_done: true });
4
5 function checkSubtreeExpectedValues(t, parent, prefix)
6 {
7 var checkedLayout = checkExpectedValues(t, parent, prefix);
8 Array.prototype.forEach.call(parent.childNodes, function(node) {
9 checkedLayout |= checkSubtreeExpectedValues(t, node, prefix);
10 });
11 return checkedLayout;
12 }
13
14 function checkAttribute(output, node, attribute)
15 {
16 var result = node.getAttribute && node.getAttribute(attribute);
17 output.checked |= !!result;
18 return result;
19 }
20
21 function assert_tolerance(actual, expected, message)
22 {
23 if (isNaN(expected) || Math.abs(actual - expected) >= 1) {
24 assert_equals(actual, Number(expected), message);
25 }
26 }
27
28 function checkExpectedValues(t, node, prefix)
29 {
30 var output = { checked: false };
31
32 var expectedWidth = checkAttribute(output, node, "data-expected-width");
33 if (expectedWidth) {
34 assert_tolerance(node.offsetWidth, expectedWidth, prefix + "width");
35 }
36
37 var expectedHeight = checkAttribute(output, node, "data-expected-height");
38 if (expectedHeight) {
39 assert_tolerance(node.offsetHeight, expectedHeight, prefix + "height");
40 }
41
42 var expectedOffset = checkAttribute(output, node, "data-offset-x");
43 if (expectedOffset) {
44 assert_tolerance(node.offsetLeft, expectedOffset, prefix + "offsetLeft") ;
45 }
46
47 var expectedOffset = checkAttribute(output, node, "data-offset-y");
48 if (expectedOffset) {
49 assert_tolerance(node.offsetTop, expectedOffset, prefix + "offsetTop");
50 }
51
52 var expectedWidth = checkAttribute(output, node, "data-expected-client-width ");
53 if (expectedWidth) {
54 assert_tolerance(node.clientWidth, expectedWidth, prefix + "clientWidth" );
55 }
56
57 var expectedHeight = checkAttribute(output, node, "data-expected-client-heig ht");
58 if (expectedHeight) {
59 assert_tolerance(node.clientHeight, expectedHeight, prefix + "clientHeig ht");
60 }
61
62 var expectedWidth = checkAttribute(output, node, "data-expected-scroll-width ");
63 if (expectedWidth) {
64 assert_tolerance(node.scrollWidth, expectedWidth, prefix + "scrollWidth" );
65 }
66
67 var expectedHeight = checkAttribute(output, node, "data-expected-scroll-heig ht");
68 if (expectedHeight) {
69 assert_tolerance(node.scrollHeight, expectedHeight, prefix + "scrollHeig ht");
70 }
71
72 var expectedOffset = checkAttribute(output, node, "data-total-x");
73 if (expectedOffset) {
74 var totalLeft = node.clientLeft + node.offsetLeft;
75 assert_tolerance(totalLeft, expectedOffset, prefix +
76 "clientLeft+offsetLeft (" + node.clientLeft + " + " + n ode.offsetLeft + ")");
77 }
78
79 var expectedOffset = checkAttribute(output, node, "data-total-y");
80 if (expectedOffset) {
81 var totalTop = node.clientTop + node.offsetTop;
82 assert_tolerance(totalTop, expectedOffset, prefix +
83 "clientTop+offsetTop (" + node.clientTop + " + " + node .offsetTop + ")");
84 }
85
86 var expectedDisplay = checkAttribute(output, node, "data-expected-display");
87 if (expectedDisplay) {
88 var actualDisplay = getComputedStyle(node).display;
89 assert_equals(actualDisplay, expectedDisplay, prefix + "display");
90 }
91
92 var expectedPaddingTop = checkAttribute(output, node, "data-expected-padding -top");
93 if (expectedPaddingTop) {
94 var actualPaddingTop = getComputedStyle(node).paddingTop;
95 // Trim the unit "px" from the output.
96 actualPaddingTop = actualPaddingTop.slice(0, -2);
97 assert_equals(actualPaddingTop, expectedPaddingTop, prefix + "padding-to p");
98 }
99
100 var expectedPaddingBottom = checkAttribute(output, node, "data-expected-padd ing-bottom");
101 if (expectedPaddingBottom) {
102 var actualPaddingBottom = getComputedStyle(node).paddingBottom;
103 // Trim the unit "px" from the output.
104 actualPaddingBottom = actualPaddingBottom.slice(0, -2);
105 assert_equals(actualPaddingBottom, expectedPaddingBottom, prefix + "padd ing-bottom");
106 }
107
108 var expectedPaddingLeft = checkAttribute(output, node, "data-expected-paddin g-left");
109 if (expectedPaddingLeft) {
110 var actualPaddingLeft = getComputedStyle(node).paddingLeft;
111 // Trim the unit "px" from the output.
112 actualPaddingLeft = actualPaddingLeft.slice(0, -2);
113 assert_equals(actualPaddingLeft, expectedPaddingLeft, prefix + "padding- left");
114 }
115
116 var expectedPaddingRight = checkAttribute(output, node, "data-expected-paddi ng-right");
117 if (expectedPaddingRight) {
118 var actualPaddingRight = getComputedStyle(node).paddingRight;
119 // Trim the unit "px" from the output.
120 actualPaddingRight = actualPaddingRight.slice(0, -2);
121 assert_equals(actualPaddingRight, expectedPaddingRight, prefix + "paddin g-right");
122 }
123
124 var expectedMarginTop = checkAttribute(output, node, "data-expected-margin-t op");
125 if (expectedMarginTop) {
126 var actualMarginTop = getComputedStyle(node).marginTop;
127 // Trim the unit "px" from the output.
128 actualMarginTop = actualMarginTop.slice(0, -2);
129 assert_equals(actualMarginTop, expectedMarginTop, prefix + "margin-top") ;
130 }
131
132 var expectedMarginBottom = checkAttribute(output, node, "data-expected-margi n-bottom");
133 if (expectedMarginBottom) {
134 var actualMarginBottom = getComputedStyle(node).marginBottom;
135 // Trim the unit "px" from the output.
136 actualMarginBottom = actualMarginBottom.slice(0, -2);
137 assert_equals(actualMarginBottom, expectedMarginBottom, prefix + "margin -bottom");
138 }
139
140 var expectedMarginLeft = checkAttribute(output, node, "data-expected-margin- left");
141 if (expectedMarginLeft) {
142 var actualMarginLeft = getComputedStyle(node).marginLeft;
143 // Trim the unit "px" from the output.
144 actualMarginLeft = actualMarginLeft.slice(0, -2);
145 assert_equals(actualMarginLeft, expectedMarginLeft, prefix + "margin-lef t");
146 }
147
148 var expectedMarginRight = checkAttribute(output, node, "data-expected-margin -right");
149 if (expectedMarginRight) {
150 var actualMarginRight = getComputedStyle(node).marginRight;
151 // Trim the unit "px" from the output.
152 actualMarginRight = actualMarginRight.slice(0, -2);
153 assert_equals(actualMarginRight, expectedMarginRight, prefix + "margin-r ight");
154 }
155
156 return output.checked;
157 }
158
159 window.checkLayout = function(selectorList, outputContainer)
160 {
161 if (!selectorList) {
162 console.error("You must provide a CSS selector of nodes to check.");
163 return;
164 }
165 var nodes = document.querySelectorAll(selectorList);
166 var testNumber = 0;
167 nodes = Array.prototype.slice.call(nodes);
168 nodes.reverse();
169 var checkedLayout = false;
170 Array.prototype.forEach.call(nodes, function(node) {
171 test(function(t) {
172 var container = node.parentNode.className == 'container' ? node.pare ntNode : node;
173 var prefix = "\n" + container.outerHTML + "\n";
174 var passed = false;
175 try {
176 checkedLayout |= checkExpectedValues(t, node.parentNode, prefix) ;
177 checkedLayout |= checkSubtreeExpectedValues(t, node, prefix);
178 passed = true;
179 } finally {
180 checkedLayout |= !passed;
181 }
182 }, selectorList + ' ' + String(++testNumber));
183 });
184 if (!checkedLayout) {
185 console.error("No valid data-* attributes found in selector list : " + s electorList);
186 }
187 done();
188 };
189
190 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/css3/flexbox/stretched-child-shrink-on-relayout-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698