| 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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 ok = createExpect(currentTestCase.tearDown.bind( | 823 ok = createExpect(currentTestCase.tearDown.bind( |
| 824 currentTestCase)).call(null) && ok; | 824 currentTestCase)).call(null) && ok; |
| 825 | 825 |
| 826 if (!ok && result) | 826 if (!ok && result) |
| 827 result = [false, errorsToMessage(errors, result[1])]; | 827 result = [false, errorsToMessage(errors, result[1])]; |
| 828 | 828 |
| 829 currentTestCase = null; | 829 currentTestCase = null; |
| 830 } | 830 } |
| 831 if (!result) | 831 if (!result) |
| 832 result = testResult(); | 832 result = testResult(); |
| 833 chrome.send('testResult', result); | 833 if (chrome.send) { |
| 834 // For WebUI tests. |
| 835 chrome.send('testResult', result); |
| 836 } else if (window.domAutomationController.send) { |
| 837 // For extension tests. |
| 838 valueResult = { 'result': result[0], message: result[1] }; |
| 839 window.domAutomationController.send(JSON.stringify(valueResult)); |
| 840 } |
| 834 errors.splice(0, errors.length); | 841 errors.splice(0, errors.length); |
| 835 } else { | 842 } else { |
| 836 console.warn('testIsDone already'); | 843 console.warn('testIsDone already'); |
| 837 } | 844 } |
| 838 } | 845 } |
| 839 | 846 |
| 840 /** | 847 /** |
| 841 * Converts each Error in |errors| to a suitable message, adding them to | 848 * Converts each Error in |errors| to a suitable message, adding them to |
| 842 * |message|, and returns the message string. | 849 * |message|, and returns the message string. |
| 843 * @param {Array.<Error>} errors Array of errors to add to |message|. | 850 * @param {Array.<Error>} errors Array of errors to add to |message|. |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 * @return {boolean} true always to signal successful execution (but not | 1101 * @return {boolean} true always to signal successful execution (but not |
| 1095 * necessarily successful results) of this test. | 1102 * necessarily successful results) of this test. |
| 1096 * @see errors | 1103 * @see errors |
| 1097 * @see runTestFunction | 1104 * @see runTestFunction |
| 1098 */ | 1105 */ |
| 1099 function runTest(isAsync, testFunction, testArguments) { | 1106 function runTest(isAsync, testFunction, testArguments) { |
| 1100 // Avoid eval() if at all possible, since it will not work on pages | 1107 // Avoid eval() if at all possible, since it will not work on pages |
| 1101 // that have enabled content-security-policy. | 1108 // that have enabled content-security-policy. |
| 1102 var testBody = this[testFunction]; // global object -- not a method. | 1109 var testBody = this[testFunction]; // global object -- not a method. |
| 1103 var testName = testFunction; | 1110 var testName = testFunction; |
| 1111 |
| 1112 // Depending on how we were called, |this| might not resolve to the global |
| 1113 // context. |
| 1114 if (testName == 'RUN_TEST_F' && testBody === undefined) |
| 1115 testBody = RUN_TEST_F; |
| 1116 |
| 1104 if (typeof testBody === "undefined") { | 1117 if (typeof testBody === "undefined") { |
| 1105 testBody = eval(testFunction); | 1118 testBody = eval(testFunction); |
| 1106 testName = testBody.toString(); | 1119 testName = testBody.toString(); |
| 1107 } | 1120 } |
| 1108 if (testBody != RUN_TEST_F) { | 1121 if (testBody != RUN_TEST_F) { |
| 1109 console.log('Running test ' + testName); | 1122 console.log('Running test ' + testName); |
| 1110 } | 1123 } |
| 1111 | 1124 |
| 1112 // Async allow expect errors, but not assert errors. | 1125 // Async allow expect errors, but not assert errors. |
| 1113 var result = runTestFunction(testFunction, testBody, testArguments, | 1126 var result = runTestFunction(testFunction, testBody, testArguments, |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 exports.TEST = TEST; | 1788 exports.TEST = TEST; |
| 1776 exports.TEST_F = TEST_F; | 1789 exports.TEST_F = TEST_F; |
| 1777 exports.RUNTIME_TEST_F = TEST_F; | 1790 exports.RUNTIME_TEST_F = TEST_F; |
| 1778 exports.GEN = GEN; | 1791 exports.GEN = GEN; |
| 1779 exports.GEN_INCLUDE = GEN_INCLUDE; | 1792 exports.GEN_INCLUDE = GEN_INCLUDE; |
| 1780 exports.WhenTestDone = WhenTestDone; | 1793 exports.WhenTestDone = WhenTestDone; |
| 1781 | 1794 |
| 1782 // Import the Mock4JS helpers. | 1795 // Import the Mock4JS helpers. |
| 1783 Mock4JS.addMockSupport(exports); | 1796 Mock4JS.addMockSupport(exports); |
| 1784 })(this); | 1797 })(this); |
| OLD | NEW |