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

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

Powered by Google App Engine
This is Rietveld 408576698