Chromium Code Reviews| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 * generation inside the function, and after any generated C++. | 80 * generation inside the function, and after any generated C++. |
| 81 * @type {function(string,string)} | 81 * @type {function(string,string)} |
| 82 */ | 82 */ |
| 83 testGenPostamble: null, | 83 testGenPostamble: null, |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * When set to a non-null string, auto-generate typedef before generating | 86 * When set to a non-null string, auto-generate typedef before generating |
| 87 * TEST*: {@code typedef typedefCppFixture testFixture}. | 87 * TEST*: {@code typedef typedefCppFixture testFixture}. |
| 88 * @type {string} | 88 * @type {string} |
| 89 */ | 89 */ |
| 90 typedefCppFixture: 'WebUIBrowserTest', | 90 typedefCppFixture: 'WebUIBrowserTest', |
|
dmazzoni
2014/06/09 06:59:46
Should this change or be refactored out?
| |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * This should be initialized by the test fixture and can be referenced | 93 * This should be initialized by the test fixture and can be referenced |
| 94 * during the test run. It holds any mocked handler methods. | 94 * during the test run. It holds any mocked handler methods. |
| 95 * @type {?Mock4JS.Mock} | 95 * @type {?Mock4JS.Mock} |
| 96 */ | 96 */ |
| 97 mockHandler: null, | 97 mockHandler: null, |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * This should be initialized by the test fixture and can be referenced | 100 * This should be initialized by the test fixture and can be referenced |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 var testIsDone = false; | 788 var testIsDone = false; |
| 789 | 789 |
| 790 /** | 790 /** |
| 791 * Holds the errors, if any, caught by expects so that the test case can | 791 * Holds the errors, if any, caught by expects so that the test case can |
| 792 * fail. Cleared when results are reported from runTest() or testDone(). | 792 * fail. Cleared when results are reported from runTest() or testDone(). |
| 793 * @type {Array.<Error>} | 793 * @type {Array.<Error>} |
| 794 */ | 794 */ |
| 795 var errors = []; | 795 var errors = []; |
| 796 | 796 |
| 797 /** | 797 /** |
| 798 * URL to dummy WebUI page for testing framework. | 798 * URL to dummy WebUI page for testing framework. |
|
dmazzoni
2014/06/09 06:59:46
There's so much webui-specific stuff in here, do y
| |
| 799 * @type {string} | 799 * @type {string} |
| 800 */ | 800 */ |
| 801 var DUMMY_URL = 'chrome://DummyURL'; | 801 var DUMMY_URL = 'chrome://DummyURL'; |
| 802 | 802 |
| 803 /** | 803 /** |
| 804 * Resets test state by clearing |errors| and |testIsDone| flags. | 804 * Resets test state by clearing |errors| and |testIsDone| flags. |
| 805 */ | 805 */ |
| 806 function resetTestState() { | 806 function resetTestState() { |
| 807 errors.splice(0, errors.length); | 807 errors.splice(0, errors.length); |
| 808 testIsDone = false; | 808 testIsDone = false; |
| (...skipping 14 matching lines...) Expand all 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) { |
|
dmazzoni
2014/06/09 06:59:46
I think it'd be more clear if you determined wheth
David Tseng
2014/06/10 05:35:22
There are just two instances with probably no more
| |
| 834 chrome.send('testResult', result); | |
| 835 } else if (window.domAutomationController.send) { | |
| 836 valueResult = { 'result': result[0], message: result[1]}; | |
|
Peter Lundblad
2014/06/08 23:27:22
nit: put a space before the last } to be symmetric
David Tseng
2014/06/10 05:35:22
Done.
| |
| 837 window.domAutomationController.send(JSON.stringify(valueResult)); | |
| 838 } | |
| 834 errors.splice(0, errors.length); | 839 errors.splice(0, errors.length); |
| 835 } else { | 840 } else { |
| 836 console.warn('testIsDone already'); | 841 console.warn('testIsDone already'); |
| 837 } | 842 } |
| 838 } | 843 } |
| 839 | 844 |
| 840 /** | 845 /** |
| 841 * Converts each Error in |errors| to a suitable message, adding them to | 846 * Converts each Error in |errors| to a suitable message, adding them to |
| 842 * |message|, and returns the message string. | 847 * |message|, and returns the message string. |
| 843 * @param {Array.<Error>} errors Array of errors to add to |message|. | 848 * @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 | 1099 * @return {boolean} true always to signal successful execution (but not |
| 1095 * necessarily successful results) of this test. | 1100 * necessarily successful results) of this test. |
| 1096 * @see errors | 1101 * @see errors |
| 1097 * @see runTestFunction | 1102 * @see runTestFunction |
| 1098 */ | 1103 */ |
| 1099 function runTest(isAsync, testFunction, testArguments) { | 1104 function runTest(isAsync, testFunction, testArguments) { |
| 1100 // Avoid eval() if at all possible, since it will not work on pages | 1105 // Avoid eval() if at all possible, since it will not work on pages |
| 1101 // that have enabled content-security-policy. | 1106 // that have enabled content-security-policy. |
| 1102 var testBody = this[testFunction]; // global object -- not a method. | 1107 var testBody = this[testFunction]; // global object -- not a method. |
| 1103 var testName = testFunction; | 1108 var testName = testFunction; |
| 1109 | |
| 1110 // Depending on how we were called, |this| might not resolve to the global | |
| 1111 // context. | |
| 1112 if (testName == 'RUN_TEST_F' && testBody === undefined) | |
| 1113 testBody = RUN_TEST_F; | |
| 1114 | |
| 1104 if (typeof testBody === "undefined") { | 1115 if (typeof testBody === "undefined") { |
| 1105 testBody = eval(testFunction); | 1116 testBody = eval(testFunction); |
| 1106 testName = testBody.toString(); | 1117 testName = testBody.toString(); |
| 1107 } | 1118 } |
| 1108 if (testBody != RUN_TEST_F) { | 1119 if (testBody != RUN_TEST_F) { |
| 1109 console.log('Running test ' + testName); | 1120 console.log('Running test ' + testName); |
| 1110 } | 1121 } |
| 1111 | 1122 |
| 1112 // Async allow expect errors, but not assert errors. | 1123 // Async allow expect errors, but not assert errors. |
| 1113 var result = runTestFunction(testFunction, testBody, testArguments, | 1124 var result = runTestFunction(testFunction, testBody, testArguments, |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1775 exports.TEST = TEST; | 1786 exports.TEST = TEST; |
| 1776 exports.TEST_F = TEST_F; | 1787 exports.TEST_F = TEST_F; |
| 1777 exports.RUNTIME_TEST_F = TEST_F; | 1788 exports.RUNTIME_TEST_F = TEST_F; |
| 1778 exports.GEN = GEN; | 1789 exports.GEN = GEN; |
| 1779 exports.GEN_INCLUDE = GEN_INCLUDE; | 1790 exports.GEN_INCLUDE = GEN_INCLUDE; |
| 1780 exports.WhenTestDone = WhenTestDone; | 1791 exports.WhenTestDone = WhenTestDone; |
| 1781 | 1792 |
| 1782 // Import the Mock4JS helpers. | 1793 // Import the Mock4JS helpers. |
| 1783 Mock4JS.addMockSupport(exports); | 1794 Mock4JS.addMockSupport(exports); |
| 1784 })(this); | 1795 })(this); |
| OLD | NEW |