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

Side by Side Diff: sky/tests/resources/check-layout.sky

Issue 699113002: Add the check layout framework for tests. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 | « sky/tests/layout/margins-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 <script>
2 (function() {
abarth-chromium 2014/11/04 03:42:11 No need for this. All script tags do this automat
ojan 2014/11/04 04:02:46 Done.
3
4 function identifier(node) {
5 var attributes = node.getAttributes().map(function(attr) {
6 return attr.name + '="' + attr.value + '"';
7 }).join(' ');
8 return '<' + node.tagName + ' ' + attributes + '>';
9 }
10
11 function checkSubtreeExpectedValues(parent, failures) {
12 var checkedLayout = checkExpectedValues(parent, failures);
13 for (var child = parent.firstChild; child; child = child.nextSibling) {
14 checkedLayout |= checkSubtreeExpectedValues(child, failures);
15 };
16 return checkedLayout;
17 }
18
19 function checkAttribute(output, node, attribute) {
20 var result = node.getAttribute && node.getAttribute(attribute);
21 output.checked |= !!result;
22 return result;
23 }
24
25 function checkExpectedValues(node, failuresOut) {
26 var output = { checked: false };
27 var failures = [];
28 var expectedWidth = checkAttribute(output, node, "data-expected-width");
29 if (expectedWidth) {
30 if (Math.abs(node.offsetWidth - expectedWidth) >= 1)
31 failures.push("Expected " + expectedWidth + " for width, but got " + node. offsetWidth + ".");
32 }
33
34 var expectedHeight = checkAttribute(output, node, "data-expected-height");
35 if (expectedHeight) {
36 if (Math.abs(node.offsetHeight - expectedHeight) >= 1)
37 failures.push("Expected " + expectedHeight + " for height, but got " + nod e.offsetHeight + ".");
38 }
39
40 var expectedOffset = checkAttribute(output, node, "data-offset-x");
41 if (expectedOffset) {
42 if (Math.abs(node.offsetLeft - expectedOffset) >= 1)
43 failures.push("Expected " + expectedOffset + " for offsetLeft, but got " + node.offsetLeft + ".");
44 }
45
46 var expectedOffset = checkAttribute(output, node, "data-offset-y");
47 if (expectedOffset) {
48 if (Math.abs(node.offsetTop - expectedOffset) >= 1)
49 failures.push("Expected " + expectedOffset + " for offsetTop, but got " + node.offsetTop + ".");
50 }
51
52 var expectedWidth = checkAttribute(output, node, "data-expected-client-width") ;
53 if (expectedWidth) {
54 if (Math.abs(node.clientWidth - expectedWidth) >= 1)
55 failures.push("Expected " + expectedWidth + " for clientWidth, but got " + node.clientWidth + ".");
56 }
57
58 var expectedHeight = checkAttribute(output, node, "data-expected-client-height ");
59 if (expectedHeight) {
60 if (Math.abs(node.clientHeight - expectedHeight) >= 1)
61 failures.push("Expected " + expectedHeight + " for clientHeight, but got " + node.clientHeight + ".");
62 }
63
64 var expectedWidth = checkAttribute(output, node, "data-expected-scroll-width") ;
65 if (expectedWidth) {
66 if (Math.abs(node.scrollWidth - expectedWidth) >= 1)
67 failures.push("Expected " + expectedWidth + " for scrollWidth, but got " + node.scrollWidth + ".");
68 }
69
70 var expectedHeight = checkAttribute(output, node, "data-expected-scroll-height ");
71 if (expectedHeight) {
72 if (Math.abs(node.scrollHeight - expectedHeight) >= 1)
73 failures.push("Expected " + expectedHeight + " for scrollHeight, but got " + node.scrollHeight + ".");
74 }
75
76 var expectedOffset = checkAttribute(output, node, "data-total-x");
77 if (expectedOffset) {
78 var totalLeft = node.clientLeft + node.offsetLeft;
79 if (Math.abs(totalLeft - expectedOffset) >= 1)
80 failures.push("Expected " + expectedOffset + " for clientLeft+offsetLeft, but got " + totalLeft + ", clientLeft: " + node.clientLeft + ", offsetLeft: " + node.offsetLeft + ".");
81 }
82
83 var expectedOffset = checkAttribute(output, node, "data-total-y");
84 if (expectedOffset) {
85 var totalTop = node.clientTop + node.offsetTop;
86 if (Math.abs(totalTop - expectedOffset) >= 1)
87 failures.push("Expected " + expectedOffset + " for clientTop+offsetTop, bu t got " + totalTop + ", clientTop: " + node.clientTop + ", + offsetTop: " + node .offsetTop + ".");
88 }
89
90 var expectedDisplay = checkAttribute(output, node, "data-expected-display");
91 if (expectedDisplay) {
92 var actualDisplay = getComputedStyle(node).display;
93 if (actualDisplay != expectedDisplay)
94 failures.push("Expected " + expectedDisplay + " for display, but got " + a ctualDisplay + ".");
95 }
96
97 var expectedPaddingTop = checkAttribute(output, node, "data-expected-padding-t op");
98 if (expectedPaddingTop) {
99 var actualPaddingTop = getComputedStyle(node).paddingTop;
100 // Trim the unit "px" from the output.
101 actualPaddingTop = actualPaddingTop.substring(0, actualPaddingTop.length - 2 );
102 if (actualPaddingTop != expectedPaddingTop)
103 failures.push("Expected " + expectedPaddingTop + " for padding-top, but go t " + actualPaddingTop + ".");
104 }
105
106 var expectedPaddingBottom = checkAttribute(output, node, "data-expected-paddin g-bottom");
107 if (expectedPaddingBottom) {
108 var actualPaddingBottom = getComputedStyle(node).paddingBottom;
109 // Trim the unit "px" from the output.
110 actualPaddingBottom = actualPaddingBottom.substring(0, actualPaddingBottom.l ength - 2);
111 if (actualPaddingBottom != expectedPaddingBottom)
112 failures.push("Expected " + expectedPaddingBottom + " for padding-bottom, but got " + actualPaddingBottom + ".");
113 }
114
115 var expectedPaddingLeft = checkAttribute(output, node, "data-expected-padding- left");
116 if (expectedPaddingLeft) {
117 var actualPaddingLeft = getComputedStyle(node).paddingLeft;
118 // Trim the unit "px" from the output.
119 actualPaddingLeft = actualPaddingLeft.substring(0, actualPaddingLeft.length - 2);
120 if (actualPaddingLeft != expectedPaddingLeft)
121 failures.push("Expected " + expectedPaddingLeft + " for padding-left, but got " + actualPaddingLeft + ".");
122 }
123
124 var expectedPaddingRight = checkAttribute(output, node, "data-expected-padding -right");
125 if (expectedPaddingRight) {
126 var actualPaddingRight = getComputedStyle(node).paddingRight;
127 // Trim the unit "px" from the output.
128 actualPaddingRight = actualPaddingRight.substring(0, actualPaddingRight.leng th - 2);
129 if (actualPaddingRight != expectedPaddingRight)
130 failures.push("Expected " + expectedPaddingRight + " for padding-right, bu t got " + actualPaddingRight + ".");
131 }
132
133 var expectedMarginTop = checkAttribute(output, node, "data-expected-margin-top ");
134 if (expectedMarginTop) {
135 var actualMarginTop = getComputedStyle(node).marginTop;
136 // Trim the unit "px" from the output.
137 actualMarginTop = actualMarginTop.substring(0, actualMarginTop.length - 2);
138 if (actualMarginTop != expectedMarginTop)
139 failures.push("Expected " + expectedMarginTop + " for margin-top, but got " + actualMarginTop + ".");
140 }
141
142 var expectedMarginBottom = checkAttribute(output, node, "data-expected-margin- bottom");
143 if (expectedMarginBottom) {
144 var actualMarginBottom = getComputedStyle(node).marginBottom;
145 // Trim the unit "px" from the output.
146 actualMarginBottom = actualMarginBottom.substring(0, actualMarginBottom.leng th - 2);
147 if (actualMarginBottom != expectedMarginBottom)
148 failures.push("Expected " + expectedMarginBottom + " for margin-bottom, bu t got " + actualMarginBottom + ".");
149 }
150
151 var expectedMarginLeft = checkAttribute(output, node, "data-expected-margin-le ft");
152 if (expectedMarginLeft) {
153 var actualMarginLeft = getComputedStyle(node).marginLeft;
154 // Trim the unit "px" from the output.
155 actualMarginLeft = actualMarginLeft.substring(0, actualMarginLeft.length - 2 );
156 if (actualMarginLeft != expectedMarginLeft)
157 failures.push("Expected " + expectedMarginLeft + " for margin-left, but go t " + actualMarginLeft + ".");
158 }
159
160 var expectedMarginRight = checkAttribute(output, node, "data-expected-margin-r ight");
161 if (expectedMarginRight) {
162 var actualMarginRight = getComputedStyle(node).marginRight;
163 // Trim the unit "px" from the output.
164 actualMarginRight = actualMarginRight.substring(0, actualMarginRight.length - 2);
165 if (actualMarginRight != expectedMarginRight)
166 failures.push("Expected " + expectedMarginRight + " for margin-right, but got " + actualMarginRight + ".");
167 }
168
169 if (failures.length) {
170 failuresOut.push(identifier(node));
171 failures.forEach(function(failure) {
172 failuresOut.push(failure);
173 });
174 }
175
176 return output.checked;
177 }
178
179 window.checkLayout = function(selectorList, outputContainer) {
180 if (!selectorList) {
181 console.error("You must provide a CSS selector of nodes to check.");
182 return;
183 }
184
185 var nodes = document.querySelectorAll(selectorList);
186 var checkedLayout = false;
187 var output = [];
188 Array.prototype.forEach.call(nodes, function(node) {
189 var failures = [];
190 checkedLayout |= checkSubtreeExpectedValues(node, failures);
191 output.push(failures.length ? "FAIL:\n" + failures.join('\n') : "PASS");
192 });
193
194 if (!checkedLayout)
195 internals.notifyTestComplete("FAIL: No valid data-* attributes found in sele ctor list : " + selectorList);
196 internals.notifyTestComplete(output.join('\n\n'));
197 }
198
199 })();
200 </script>
OLDNEW
« no previous file with comments | « sky/tests/layout/margins-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698