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

Side by Side Diff: ui/webui/resources/js/webui_resource_test.js

Issue 2597013002: Run clang-format on ui/webui/resources (Closed)
Patch Set: remove cr_shared_menu.js Created 3 years, 12 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Tests that an observation matches the expected value. 6 * Tests that an observation matches the expected value.
7 * @param {Object} expected The expected value. 7 * @param {Object} expected The expected value.
8 * @param {Object} observed The actual value. 8 * @param {Object} observed The actual value.
9 * @param {string=} opt_message Optional message to include with a test 9 * @param {string=} opt_message Optional message to include with a test
10 * failure. 10 * failure.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 58
59 /** 59 /**
60 * Verifies that a test evaluation results in an exception. 60 * Verifies that a test evaluation results in an exception.
61 * @param {!Function} f The test function. 61 * @param {!Function} f The test function.
62 */ 62 */
63 function assertThrows(f) { 63 function assertThrows(f) {
64 var triggeredError = false; 64 var triggeredError = false;
65 try { 65 try {
66 f(); 66 f();
67 } catch(err) { 67 } catch (err) {
68 triggeredError = true; 68 triggeredError = true;
69 } 69 }
70 if (!triggeredError) 70 if (!triggeredError)
71 throw new Error('Assertion Failed: throw expected.'); 71 throw new Error('Assertion Failed: throw expected.');
72 } 72 }
73 73
74 /** 74 /**
75 * Verifies that the contents of the expected and observed arrays match. 75 * Verifies that the contents of the expected and observed arrays match.
76 * @param {!Array} expected The expected result. 76 * @param {!Array} expected The expected result.
77 * @param {!Array} observed The actual result. 77 * @param {!Array} observed The actual result.
78 */ 78 */
79 function assertArrayEquals(expected, observed) { 79 function assertArrayEquals(expected, observed) {
80 var v1 = Array.prototype.slice.call(expected); 80 var v1 = Array.prototype.slice.call(expected);
81 var v2 = Array.prototype.slice.call(observed); 81 var v2 = Array.prototype.slice.call(observed);
82 var equal = v1.length == v2.length; 82 var equal = v1.length == v2.length;
83 if (equal) { 83 if (equal) {
84 for (var i = 0; i < v1.length; i++) { 84 for (var i = 0; i < v1.length; i++) {
85 if (v1[i] !== v2[i]) { 85 if (v1[i] !== v2[i]) {
86 equal = false; 86 equal = false;
87 break; 87 break;
88 } 88 }
89 } 89 }
90 } 90 }
91 if (!equal) { 91 if (!equal) {
92 var message = 92 var message =
93 ['Assertion Failed', 'Observed: ' + v2, 'Expected: ' + v1].join('\n '); 93 ['Assertion Failed', 'Observed: ' + v2, 'Expected: ' + v1].join('\n ');
94 throw new Error(message); 94 throw new Error(message);
95 } 95 }
96 } 96 }
97 97
98 /** 98 /**
99 * Verifies that the expected and observed result have the same content. 99 * Verifies that the expected and observed result have the same content.
100 * @param {*} expected The expected result. 100 * @param {*} expected The expected result.
101 * @param {*} observed The actual result. 101 * @param {*} observed The actual result.
102 */ 102 */
103 function assertDeepEquals(expected, observed, opt_message) { 103 function assertDeepEquals(expected, observed, opt_message) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (/^test/.test(name) && typeof window[name] == 'function') 147 if (/^test/.test(name) && typeof window[name] == 'function')
148 testCases.push(name); 148 testCases.push(name);
149 } 149 }
150 if (!testCases.length) { 150 if (!testCases.length) {
151 console.error('Failed to find test cases.'); 151 console.error('Failed to find test cases.');
152 cleanTestRun = false; 152 cleanTestRun = false;
153 } 153 }
154 try { 154 try {
155 if (window.setUpPage) 155 if (window.setUpPage)
156 window.setUpPage(); 156 window.setUpPage();
157 } catch(err) { 157 } catch (err) {
158 cleanTestRun = false; 158 cleanTestRun = false;
159 } 159 }
160 continueTesting(); 160 continueTesting();
161 } 161 }
162 162
163 /** 163 /**
164 * Runs the next test in the queue. Reports the test results if the queue is 164 * Runs the next test in the queue. Reports the test results if the queue is
165 * empty. 165 * empty.
166 * @param {boolean=} opt_asyncTestFailure Optional parameter indicated if the 166 * @param {boolean=} opt_asyncTestFailure Optional parameter indicated if the
167 * last asynchronous test failed. 167 * last asynchronous test failed.
168 */ 168 */
169 function continueTesting(opt_asyncTestFailure) { 169 function continueTesting(opt_asyncTestFailure) {
170 if (opt_asyncTestFailure) 170 if (opt_asyncTestFailure)
171 cleanTestRun = false; 171 cleanTestRun = false;
172 var done = false; 172 var done = false;
173 if (pendingTearDown) { 173 if (pendingTearDown) {
174 pendingTearDown(); 174 pendingTearDown();
175 pendingTearDown = null; 175 pendingTearDown = null;
176 } 176 }
177 if (testCases.length > 0) { 177 if (testCases.length > 0) {
178 var fn = testCases.pop(); 178 var fn = testCases.pop();
179 var isAsyncTest = window[fn].length; 179 var isAsyncTest = window[fn].length;
180 try { 180 try {
181 if (window.setUp) 181 if (window.setUp)
182 window.setUp(); 182 window.setUp();
183 pendingTearDown = window.tearDown; 183 pendingTearDown = window.tearDown;
184 window[fn](continueTesting); 184 window[fn](continueTesting);
185 } catch(err) { 185 } catch (err) {
186 console.error('Failure in test ' + fn + '\n' + err); 186 console.error('Failure in test ' + fn + '\n' + err);
187 console.log(err.stack); 187 console.log(err.stack);
188 cleanTestRun = false; 188 cleanTestRun = false;
189 } 189 }
190 // Asynchronous tests must manually call continueTesting when complete. 190 // Asynchronous tests must manually call continueTesting when complete.
191 if (!isAsyncTest) 191 if (!isAsyncTest)
192 continueTesting(); 192 continueTesting();
193 } else { 193 } else {
194 done = true; 194 done = true;
195 endTests(cleanTestRun); 195 endTests(cleanTestRun);
(...skipping 12 matching lines...) Expand all
208 * @param {boolean} success Indicates if the test completed successfully. 208 * @param {boolean} success Indicates if the test completed successfully.
209 */ 209 */
210 function endTests(success) { 210 function endTests(success) {
211 domAutomationController.setAutomationId(1); 211 domAutomationController.setAutomationId(1);
212 domAutomationController.send(success ? 'SUCCESS' : 'FAILURE'); 212 domAutomationController.send(success ? 'SUCCESS' : 'FAILURE');
213 } 213 }
214 214
215 window.onerror = function() { 215 window.onerror = function() {
216 endTests(false); 216 endTests(false);
217 }; 217 };
OLDNEW
« ui/webui/resources/js/cr/ui/bubble.js ('K') | « ui/webui/resources/js/util.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698