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

Side by Side Diff: chrome_test/chrome_test.js

Issue 1415743013: Run jshint over all JavaScript files (Closed) Base URL: https://chromium.googlesource.com/external/naclports.git@repo_conf
Patch Set: 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 | « build_tools/pipeserver.js ('k') | chrome_test/tcpapp/tcp.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 'use strict'; 7 'use strict';
8 8
9 // Utilities to allow googletest style tests of apps / extensions. 9 // Utilities to allow googletest style tests of apps / extensions.
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 */ 80 */
81 chrometest.resetExtension = function() { 81 chrometest.resetExtension = function() {
82 var port = chrometest.newTestPort(); 82 var port = chrometest.newTestPort();
83 var count = null; 83 var count = null;
84 port.postMessage({'name': 'reset'}); 84 port.postMessage({'name': 'reset'});
85 return port.wait().then(function(msg) { 85 return port.wait().then(function(msg) {
86 ASSERT_EQ('resetReply', msg.name); 86 ASSERT_EQ('resetReply', msg.name);
87 port.disconnect(); 87 port.disconnect();
88 return msg.count; 88 return msg.count;
89 }); 89 });
90 } 90 };
91 91
92 /** 92 /**
93 * Get a list of all loaded extensions. 93 * Get a list of all loaded extensions.
94 * 94 *
95 * This exposes the result of chrome.management.getAll for use by tests. 95 * This exposes the result of chrome.management.getAll for use by tests.
96 * @returns {Promise.Array.<ExtensionInfo>}. 96 * @returns {Promise.Array.<ExtensionInfo>}.
97 */ 97 */
98 chrometest.getAllExtensions = function() { 98 chrometest.getAllExtensions = function() {
99 var port = chrometest.newTestPort(); 99 var port = chrometest.newTestPort();
100 port.postMessage({'name': 'getAllExtensions'}); 100 port.postMessage({'name': 'getAllExtensions'});
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 var r = new XMLHttpRequest(); 225 var r = new XMLHttpRequest();
226 r.open('GET', url, false); 226 r.open('GET', url, false);
227 r.onload = function() { 227 r.onload = function() {
228 if (r.readyState == 4) { 228 if (r.readyState == 4) {
229 if (r.status == 200) { 229 if (r.status == 200) {
230 resolve(r.responseText); 230 resolve(r.responseText);
231 } else { 231 } else {
232 reject(r.status); 232 reject(r.status);
233 } 233 }
234 } 234 }
235 } 235 };
236 r.send(); 236 r.send();
237 }); 237 });
238 }; 238 };
239 239
240 /** 240 /**
241 * Sleep for a duration. 241 * Sleep for a duration.
242 * @param {float} ms Timeout in milliseconds. 242 * @param {float} ms Timeout in milliseconds.
243 * @return {Promise} A promise to wait. 243 * @return {Promise} A promise to wait.
244 */ 244 */
245 chrometest.sleep = function(ms) { 245 chrometest.sleep = function(ms) {
(...skipping 27 matching lines...) Expand all
273 return chrometest.httpGet('/_command?test_count=' + testCount); 273 return chrometest.httpGet('/_command?test_count=' + testCount);
274 }; 274 };
275 275
276 /** 276 /**
277 * Notify the test harness that a test has begun. 277 * Notify the test harness that a test has begun.
278 * @param {string} name The full name of the test. 278 * @param {string} name The full name of the test.
279 * @return {Promise} A promise to do it. 279 * @return {Promise} A promise to do it.
280 */ 280 */
281 chrometest.beginTest_ = function(name) { 281 chrometest.beginTest_ = function(name) {
282 return chrometest.resetExtension().then(function(count) { 282 return chrometest.resetExtension().then(function(count) {
283 if (count != 0) { 283 if (count !== 0) {
284 throw new Error( 284 throw new Error(
285 'Test extension connections from the last test remain active!'); 285 'Test extension connections from the last test remain active!');
286 } 286 }
287 console.log('[ RUN ] ' + name); 287 console.log('[ RUN ] ' + name);
288 chrometest.passed_ = true; 288 chrometest.passed_ = true;
289 chrometest.currentTestName_ = name; 289 chrometest.currentTestName_ = name;
290 return chrometest.httpGet( 290 return chrometest.httpGet(
291 '/_command?name=' + encodeURIComponent(name) + 291 '/_command?name=' + encodeURIComponent(name) +
292 '&start=1'); 292 '&start=1');
293 }).then(function(result) { 293 }).then(function(result) {
294 chrometest.startTime_ = new Date(); 294 chrometest.startTime_ = new Date();
295 }); 295 });
296 }; 296 };
297 297
298 /** 298 /**
299 * Notify the test harness that a test has ended. 299 * Notify the test harness that a test has ended.
300 * @return {Promise} A promise to do it. 300 * @return {Promise} A promise to do it.
301 */ 301 */
302 chrometest.endTest_ = function() { 302 chrometest.endTest_ = function() {
303 return chrometest.resetExtension().then(function(count) { 303 return chrometest.resetExtension().then(function(count) {
304 EXPECT_EQ(0, count, 304 EXPECT_EQ(0, count,
305 'all connection to the test extension should be closed'); 305 'all connection to the test extension should be closed');
306 var endTime = new Date(); 306 var endTime = new Date();
307 var duration = endTime.getTime() - chrometest.startTime_.getTime(); 307 var duration = endTime.getTime() - chrometest.startTime_.getTime();
308 duration = chrometest.formatDuration(duration); 308 duration = chrometest.formatDuration(duration);
309 var name = chrometest.currentTestName_; 309 var name = chrometest.currentTestName_;
310 var resultMsg;
311 var result;
310 if (chrometest.passed_) { 312 if (chrometest.passed_) {
311 var resultMsg = ' OK'; 313 resultMsg = ' OK';
312 var result = 1; 314 result = 1;
313 } else { 315 } else {
314 var resultMsg = ' FAILED '; 316 resultMsg = ' FAILED ';
315 var result = 0; 317 result = 0;
316 } 318 }
317 console.log('[ ' + resultMsg + ' ] ' + name + ' (' + duration + ')'); 319 console.log('[ ' + resultMsg + ' ] ' + name + ' (' + duration + ')');
318 chrometest.startTime_ = null; 320 chrometest.startTime_ = null;
319 chrometest.currentTest_ = null; 321 chrometest.currentTest_ = null;
320 chrometest.currentTestName_ = null; 322 chrometest.currentTestName_ = null;
321 return chrometest.httpGet( 323 return chrometest.httpGet(
322 '/_command?name=' + encodeURIComponent(name) + '&' + 324 '/_command?name=' + encodeURIComponent(name) + '&' +
323 'duration=' + encodeURIComponent(duration) + '&' + 325 'duration=' + encodeURIComponent(duration) + '&' +
324 'result=' + result); 326 'result=' + result);
325 }); 327 });
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 /** 431 /**
430 * Check if a string matches a googletest style filter. 432 * Check if a string matches a googletest style filter.
431 * A filter consists of zero or more ':' separated positive wildcard 433 * A filter consists of zero or more ':' separated positive wildcard
432 * strings, followed optionally by a '-' and zero or more ':' separated 434 * strings, followed optionally by a '-' and zero or more ':' separated
433 * negative wildcard strings. 435 * negative wildcard strings.
434 * @param string filter A googletest style filter string. 436 * @param string filter A googletest style filter string.
435 * @param string s A string to match. 437 * @param string s A string to match.
436 */ 438 */
437 chrometest.filterMatch = function(filter, s) { 439 chrometest.filterMatch = function(filter, s) {
438 var parts = filter.split('-'); 440 var parts = filter.split('-');
441 var positive;
442 var negative;
439 if (parts.length == 1) { 443 if (parts.length == 1) {
440 var positive = parts[0].split(':'); 444 positive = parts[0].split(':');
441 var negative = []; 445 negative = [];
442 } else if (parts.length == 2) { 446 } else if (parts.length == 2) {
443 var positive = parts[0].split(':'); 447 positive = parts[0].split(':');
444 var negative = parts[1].split(':'); 448 negative = parts[1].split(':');
445 } else { 449 } else {
446 // Treat ill-formated filters as non-matches. 450 // Treat ill-formated filters as non-matches.
447 return false; 451 return false;
448 } 452 }
449 if (positive.length == 1 && positive[0] == '') { 453 if (positive.length == 1 && positive[0] === '') {
450 positive = ['*']; 454 positive = ['*'];
451 } 455 }
452 if (negative.length == 1 && negative[0] == '') { 456 if (negative.length == 1 && negative[0] === '') {
453 negative = []; 457 negative = [];
454 } 458 }
455 for (var i = 0; i < positive.length; i++) { 459 for (var i = 0; i < positive.length; i++) {
456 if (!chrometest.wildcardMatch(positive[i], s)) { 460 if (!chrometest.wildcardMatch(positive[i], s)) {
457 return false; 461 return false;
458 } 462 }
459 } 463 }
460 for (var i = 0; i < negative.length; i++) { 464 for (var i = 0; i < negative.length; i++) {
461 if (chrometest.wildcardMatch(negative[i], s)) { 465 if (chrometest.wildcardMatch(negative[i], s)) {
462 return false; 466 return false;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 // - A global name makes use through multiple tests convenient. 710 // - A global name makes use through multiple tests convenient.
707 // - Using an existing naming convention makes use and intent clear. 711 // - Using an existing naming convention makes use and intent clear.
708 // - ALL CAPS highlights the testing constructs visually. 712 // - ALL CAPS highlights the testing constructs visually.
709 713
710 714
711 // TEST Types 715 // TEST Types
712 // ---------- 716 // ----------
713 717
714 /** 718 /**
715 * Register a test case using a fixture class. 719 * Register a test case using a fixture class.
716 * @param {string} fixtureClass The test fixture class object. 720 * @param {string} FixtureClass The test fixture class object.
717 * @param {string} testName The name of the test. 721 * @param {string} testName The name of the test.
718 * @param {function()} testFunc Called to run the test, may return 722 * @param {function()} testFunc Called to run the test, may return
719 * a Promise. 723 * a Promise.
720 * @param {string} opt_caseName Optional name for the case, otherwise the 724 * @param {string} opt_caseName Optional name for the case, otherwise the
721 * fixtureClass class name is used. 725 * FixtureClass class name is used.
722 */ 726 */
723 function TEST_F(fixtureClass, testName, testFunc, opt_caseName) { 727 function TEST_F(FixtureClass, testName, testFunc, opt_caseName) {
724 if (opt_caseName == undefined) { 728 if (opt_caseName === undefined) {
725 opt_caseName = fixtureClass.name; 729 opt_caseName = FixtureClass.name;
726 } 730 }
727 var fullName = opt_caseName + '.' + testName; 731 var fullName = opt_caseName + '.' + testName;
728 chrometest.tests_.push({ 732 chrometest.tests_.push({
729 'name': fullName, 733 'name': fullName,
730 'call': function() { 734 'call': function() {
731 return Promise.resolve().then(function() { 735 return Promise.resolve().then(function() {
732 return chrometest.beginTest_(fullName); 736 return chrometest.beginTest_(fullName);
733 }).then(function() { 737 }).then(function() {
734 chrometest.currentTest_ = new fixtureClass(); 738 chrometest.currentTest_ = new FixtureClass();
735 return Promise.resolve().then(function() { 739 return Promise.resolve().then(function() {
736 return chrometest.currentTest_.setUp(); 740 return chrometest.currentTest_.setUp();
737 }).then(function() { 741 }).then(function() {
738 return Promise.resolve().then(function() { 742 return Promise.resolve().then(function() {
739 return testFunc.call(chrometest.currentTest_); 743 return testFunc.call(chrometest.currentTest_);
740 }).catch(function(error) { 744 }).catch(function(error) {
741 chrometest.fail(); 745 chrometest.fail();
742 return chrometest.error(chrometest.formatError(error)); 746 return chrometest.error(chrometest.formatError(error));
743 }); 747 });
744 }).then(function() { 748 }).then(function() {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 chrometest.expect(a > b, 'Expected ' + a + ' > ' + b + ' when ' + context); 846 chrometest.expect(a > b, 'Expected ' + a + ' > ' + b + ' when ' + context);
843 } 847 }
844 848
845 function EXPECT_LE(a, b, context) { 849 function EXPECT_LE(a, b, context) {
846 chrometest.expect(a <= b, 'Expected ' + a + ' <= ' + b + ' when ' + context); 850 chrometest.expect(a <= b, 'Expected ' + a + ' <= ' + b + ' when ' + context);
847 } 851 }
848 852
849 function EXPECT_GE(a, b, context) { 853 function EXPECT_GE(a, b, context) {
850 chrometest.expect(a >= b, 'Expected ' + a + ' >= ' + b + ' when ' + context); 854 chrometest.expect(a >= b, 'Expected ' + a + ' >= ' + b + ' when ' + context);
851 } 855 }
OLDNEW
« no previous file with comments | « build_tools/pipeserver.js ('k') | chrome_test/tcpapp/tcp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698