| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * @fileoverview Library providing basic test framework functionality. | 6 * @fileoverview Library providing basic test framework functionality. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Namespace for |Test|. | 10 * Namespace for |Test|. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 * the currentTestCase. | 214 * the currentTestCase. |
| 215 */ | 215 */ |
| 216 deferRunTest: function(whenTestDone) { | 216 deferRunTest: function(whenTestDone) { |
| 217 if (whenTestDone === WhenTestDone.DEFAULT) | 217 if (whenTestDone === WhenTestDone.DEFAULT) |
| 218 whenTestDone = WhenTestDone.ALWAYS; | 218 whenTestDone = WhenTestDone.ALWAYS; |
| 219 | 219 |
| 220 return currentTestCase.deferRunTest.apply( | 220 return currentTestCase.deferRunTest.apply( |
| 221 currentTestCase, [whenTestDone].concat( | 221 currentTestCase, [whenTestDone].concat( |
| 222 Array.prototype.slice.call(arguments, 1))); | 222 Array.prototype.slice.call(arguments, 1))); |
| 223 }, | 223 }, |
| 224 |
| 225 /** |
| 226 * Run an accessibility audit on the current page state. |
| 227 * @type {Function} |
| 228 */ |
| 229 runAccessibilityAudit: function() { |
| 230 for (var auditRuleName in axs.AuditRule.specs) { |
| 231 var auditRule = axs.AuditRules.getRule(auditRuleName); |
| 232 if (!auditRule) |
| 233 continue; // Shouldn't happen, but fail silently if it does. |
| 234 if (!auditRule.disabled && !auditRule.requiresConsoleAPI) { |
| 235 var result = auditRule.run(); |
| 236 expectTrue(result.result == axs.constants.AuditResult.PASS || |
| 237 result.result == axs.constants.AuditResult.NA, |
| 238 "Accessibility audit rule " + auditRule.name + " failed"); |
| 239 } |
| 240 } |
| 241 testDone(); |
| 242 } |
| 224 }; | 243 }; |
| 225 | 244 |
| 226 /** | 245 /** |
| 227 * This class is not exported and is available to hold the state of the | 246 * This class is not exported and is available to hold the state of the |
| 228 * |currentTestCase| throughout preload and test run. | 247 * |currentTestCase| throughout preload and test run. |
| 229 * @param {string} name The name of the test case. | 248 * @param {string} name The name of the test case. |
| 230 * @param {Test} fixture The fixture object for this test case. | 249 * @param {Test} fixture The fixture object for this test case. |
| 231 * @param {Function} body The code to run for the test. | 250 * @param {Function} body The code to run for the test. |
| 232 * @constructor | 251 * @constructor |
| 233 */ | 252 */ |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 } catch (e) { | 631 } catch (e) { |
| 613 // Caught an exception in tearDown; Register the error and recreate | 632 // Caught an exception in tearDown; Register the error and recreate |
| 614 // the result if it is passed in. | 633 // the result if it is passed in. |
| 615 errors.push(e); | 634 errors.push(e); |
| 616 if (result) | 635 if (result) |
| 617 result = [false, errorsToMessage([e], result[1])]; | 636 result = [false, errorsToMessage([e], result[1])]; |
| 618 } | 637 } |
| 619 currentTestCase = null; | 638 currentTestCase = null; |
| 620 } | 639 } |
| 621 chrome.send('testResult', result ? result : testResult()); | 640 chrome.send('testResult', result ? result : testResult()); |
| 622 errors.splice(0, errors.length); | 641 // errors.splice(0, errors.length); |
| 642 resetTestState(); |
| 623 } else { | 643 } else { |
| 624 console.warn('testIsDone already'); | 644 console.warn('testIsDone already'); |
| 625 } | 645 } |
| 626 } | 646 } |
| 627 | 647 |
| 628 /** | 648 /** |
| 629 * Converts each Error in |errors| to a suitable message, adding them to | 649 * Converts each Error in |errors| to a suitable message, adding them to |
| 630 * |message|, and returns the message string. | 650 * |message|, and returns the message string. |
| 631 * @param {Array.<Error>} errors Array of errors to add to |message|. | 651 * @param {Array.<Error>} errors Array of errors to add to |message|. |
| 632 * @param {string?} message When supplied, error messages are appended to it. | 652 * @param {string?} message When supplied, error messages are appended to it. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 * the |testFixture|'s prototype, if needed, and the |testCaseBodies| into its | 997 * the |testFixture|'s prototype, if needed, and the |testCaseBodies| into its |
| 978 * constructor. | 998 * constructor. |
| 979 * @param {string} testFixture The name of the test fixture class. | 999 * @param {string} testFixture The name of the test fixture class. |
| 980 * @param {string} testName The name of the test function. | 1000 * @param {string} testName The name of the test function. |
| 981 * @param {Function} testBody The body to execute when running this test. | 1001 * @param {Function} testBody The body to execute when running this test. |
| 982 */ | 1002 */ |
| 983 function TEST_F(testFixture, testName, testBody) { | 1003 function TEST_F(testFixture, testName, testBody) { |
| 984 var fixtureConstructor = this[testFixture]; | 1004 var fixtureConstructor = this[testFixture]; |
| 985 if (!fixtureConstructor.prototype.name) | 1005 if (!fixtureConstructor.prototype.name) |
| 986 fixtureConstructor.prototype.name = testFixture; | 1006 fixtureConstructor.prototype.name = testFixture; |
| 987 if (fixtureConstructor['testCaseBodies'] === undefined) | 1007 if (fixtureConstructor['testCaseBodies'] === undefined) { |
| 988 fixtureConstructor.testCaseBodies = {}; | 1008 fixtureConstructor.testCaseBodies = {}; |
| 1009 fixtureConstructor.testCaseBodies["accessibilityAudit"] = |
| 1010 Test.prototype.runAccessibilityAudit; |
| 1011 } |
| 989 fixtureConstructor.testCaseBodies[testName] = testBody; | 1012 fixtureConstructor.testCaseBodies[testName] = testBody; |
| 990 } | 1013 } |
| 991 | 1014 |
| 992 /** | 1015 /** |
| 993 * RunJavascriptTestF uses this as the |testFunction| when invoking | 1016 * RunJavascriptTestF uses this as the |testFunction| when invoking |
| 994 * runTest. If |currentTestCase| is non-null at this point, verify that | 1017 * runTest. If |currentTestCase| is non-null at this point, verify that |
| 995 * |testFixture| and |testName| agree with the preloaded values. Create | 1018 * |testFixture| and |testName| agree with the preloaded values. Create |
| 996 * |currentTestCase|, if needed, run it, and clear the |currentTestCase|. | 1019 * |currentTestCase|, if needed, run it, and clear the |currentTestCase|. |
| 997 * @param {string} testFixture The name of the test fixture class. | 1020 * @param {string} testFixture The name of the test fixture class. |
| 998 * @param {string} testName The name of the test function. | 1021 * @param {string} testName The name of the test function. |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 exports.DUMMY_URL = DUMMY_URL; | 1425 exports.DUMMY_URL = DUMMY_URL; |
| 1403 exports.TEST = TEST; | 1426 exports.TEST = TEST; |
| 1404 exports.TEST_F = TEST_F; | 1427 exports.TEST_F = TEST_F; |
| 1405 exports.GEN = GEN; | 1428 exports.GEN = GEN; |
| 1406 exports.GEN_INCLUDE = GEN_INCLUDE; | 1429 exports.GEN_INCLUDE = GEN_INCLUDE; |
| 1407 exports.WhenTestDone = WhenTestDone; | 1430 exports.WhenTestDone = WhenTestDone; |
| 1408 | 1431 |
| 1409 // Import the Mock4JS helpers. | 1432 // Import the Mock4JS helpers. |
| 1410 Mock4JS.addMockSupport(exports); | 1433 Mock4JS.addMockSupport(exports); |
| 1411 })(this); | 1434 })(this); |
| OLD | NEW |