| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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|. | 
| 11  * @type {Object} | 11  * @type {Object} | 
| 12  */ | 12  */ | 
| 13 var testing = {}; | 13 var testing = {}; | 
| 14 (function(window) { | 14 (function(exports) { | 
| 15   /** | 15   /** | 
| 16    * Hold the currentTestCase across between preLoad and run. | 16    * Hold the currentTestCase across between preLoad and run. | 
| 17    * @type {TestCase} | 17    * @type {TestCase} | 
| 18    */ | 18    */ | 
| 19   var currentTestCase = null; | 19   var currentTestCase = null; | 
| 20 | 20 | 
| 21   /** | 21   /** | 
| 22    * The string representation of the currently running test function. | 22    * The string representation of the currently running test function. | 
| 23    * @type {?string} | 23    * @type {?string} | 
| 24    */ | 24    */ | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103      */ | 103      */ | 
| 104     isAsync: false, | 104     isAsync: false, | 
| 105 | 105 | 
| 106     /** | 106     /** | 
| 107      * True when the test is expected to fail for testing the test framework. | 107      * True when the test is expected to fail for testing the test framework. | 
| 108      * @type {boolean} | 108      * @type {boolean} | 
| 109      */ | 109      */ | 
| 110     testShouldFail: false, | 110     testShouldFail: false, | 
| 111 | 111 | 
| 112     /** | 112     /** | 
|  | 113      * Extra libraries to add before loading this test file. | 
|  | 114      * @type {Array.<string>} | 
|  | 115      */ | 
|  | 116     extraLibraries: [], | 
|  | 117 | 
|  | 118     /** | 
| 113      * Override this method to perform initialization during preload (such as | 119      * Override this method to perform initialization during preload (such as | 
| 114      * creating mocks and registering handlers). | 120      * creating mocks and registering handlers). | 
| 115      * @type {Function} | 121      * @type {Function} | 
| 116      */ | 122      */ | 
| 117     preLoad: function() {}, | 123     preLoad: function() {}, | 
| 118 | 124 | 
| 119     /** | 125     /** | 
| 120      * Override this method to perform tasks before running your test. | 126      * Override this method to perform tasks before running your test. | 
| 121      * @type {Function} | 127      * @type {Function} | 
| 122      */ | 128      */ | 
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 822    * method. This is called before the page is loaded, so the |chrome| object is | 828    * method. This is called before the page is loaded, so the |chrome| object is | 
| 823    * not yet bound and this DOMContentLoaded listener will be called first to | 829    * not yet bound and this DOMContentLoaded listener will be called first to | 
| 824    * override |chrome| in order to route messages registered in |sendCallbacks|. | 830    * override |chrome| in order to route messages registered in |sendCallbacks|. | 
| 825    * @param {string} testFixture The test fixture name. | 831    * @param {string} testFixture The test fixture name. | 
| 826    * @param {string} testName The test name. | 832    * @param {string} testName The test name. | 
| 827    * @see sendCallbacks | 833    * @see sendCallbacks | 
| 828    */ | 834    */ | 
| 829   function preloadJavascriptLibraries(testFixture, testName) { | 835   function preloadJavascriptLibraries(testFixture, testName) { | 
| 830     deferGlobalOverrides = true; | 836     deferGlobalOverrides = true; | 
| 831 | 837 | 
| 832     window.addEventListener('DOMContentLoaded', function() { | 838     exports.addEventListener('DOMContentLoaded', function() { | 
| 833       var oldChrome = chrome; | 839       var oldChrome = chrome; | 
| 834       chrome = { | 840       chrome = { | 
| 835         __proto__: oldChrome, | 841         __proto__: oldChrome, | 
| 836         send: send, | 842         send: send, | 
| 837       }; | 843       }; | 
| 838 | 844 | 
| 839       // Override globals at load time so they will be defined. | 845       // Override globals at load time so they will be defined. | 
| 840       assertTrue(deferGlobalOverrides); | 846       assertTrue(deferGlobalOverrides); | 
| 841       deferGlobalOverrides = false; | 847       deferGlobalOverrides = false; | 
| 842       for (var funcName in globalOverrides) | 848       for (var funcName in globalOverrides) | 
| 843         overrideGlobal(funcName); | 849         overrideGlobal(funcName); | 
| 844     }); | 850     }); | 
| 845     currentTestCase = createTestCase(testFixture, testName); | 851     currentTestCase = createTestCase(testFixture, testName); | 
| 846     currentTestCase.preLoad(); | 852     currentTestCase.preLoad(); | 
| 847   } | 853   } | 
| 848 | 854 | 
| 849   /** | 855   /** | 
| 850    * During generation phase, this outputs; do nothing at runtime. | 856    * During generation phase, this outputs; do nothing at runtime. | 
| 851    */ | 857    */ | 
| 852   function GEN() {} | 858   function GEN() {} | 
| 853 | 859 | 
| 854   /** | 860   /** | 
|  | 861    * During generation phase, this outputs; do nothing at runtime. | 
|  | 862    */ | 
|  | 863   function GEN_INCLUDE() {} | 
|  | 864 | 
|  | 865   /** | 
| 855    * At runtime, register the testName with a test fixture. Since this method | 866    * At runtime, register the testName with a test fixture. Since this method | 
| 856    * doesn't have a test fixture, create a dummy fixture to hold its |name| | 867    * doesn't have a test fixture, create a dummy fixture to hold its |name| | 
| 857    * and |testCaseBodies|. | 868    * and |testCaseBodies|. | 
| 858    * @param {string} testCaseName The name of the test case. | 869    * @param {string} testCaseName The name of the test case. | 
| 859    * @param {string} testName The name of the test function. | 870    * @param {string} testName The name of the test function. | 
| 860    * @param {Function} testBody The body to execute when running this test. | 871    * @param {Function} testBody The body to execute when running this test. | 
| 861    */ | 872    */ | 
| 862   function TEST(testCaseName, testName, testBody) { | 873   function TEST(testCaseName, testName, testBody) { | 
| 863     var fixtureConstructor = this[testCaseName]; | 874     var fixtureConstructor = this[testCaseName]; | 
| 864     if (fixtureConstructor === undefined) { | 875     if (fixtureConstructor === undefined) { | 
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1261    * @param {...Object} var_actions Actions to run. | 1272    * @param {...Object} var_actions Actions to run. | 
| 1262    * @return {RunAllAction} Action for use in will. | 1273    * @return {RunAllAction} Action for use in will. | 
| 1263    */ | 1274    */ | 
| 1264   function runAllActionsAsync(whenTestDone) { | 1275   function runAllActionsAsync(whenTestDone) { | 
| 1265     return new RunAllAction(true, whenTestDone, | 1276     return new RunAllAction(true, whenTestDone, | 
| 1266                             Array.prototype.slice.call(arguments, 1)); | 1277                             Array.prototype.slice.call(arguments, 1)); | 
| 1267   } | 1278   } | 
| 1268 | 1279 | 
| 1269   // Exports. | 1280   // Exports. | 
| 1270   testing.Test = Test; | 1281   testing.Test = Test; | 
| 1271   window.testDone = testDone; | 1282   exports.testDone = testDone; | 
| 1272   window.assertTrue = assertTrue; | 1283   exports.assertTrue = assertTrue; | 
| 1273   window.assertFalse = assertFalse; | 1284   exports.assertFalse = assertFalse; | 
| 1274   window.assertGE = assertGE; | 1285   exports.assertGE = assertGE; | 
| 1275   window.assertGT = assertGT; | 1286   exports.assertGT = assertGT; | 
| 1276   window.assertEquals = assertEquals; | 1287   exports.assertEquals = assertEquals; | 
| 1277   window.assertLE = assertLE; | 1288   exports.assertLE = assertLE; | 
| 1278   window.assertLT = assertLT; | 1289   exports.assertLT = assertLT; | 
| 1279   window.assertNotEquals = assertNotEquals; | 1290   exports.assertNotEquals = assertNotEquals; | 
| 1280   window.assertNotReached = assertNotReached; | 1291   exports.assertNotReached = assertNotReached; | 
| 1281   window.callFunction = callFunction; | 1292   exports.callFunction = callFunction; | 
| 1282   window.callFunctionWithSavedArgs = callFunctionWithSavedArgs; | 1293   exports.callFunctionWithSavedArgs = callFunctionWithSavedArgs; | 
| 1283   window.callGlobalWithSavedArgs = callGlobalWithSavedArgs; | 1294   exports.callGlobalWithSavedArgs = callGlobalWithSavedArgs; | 
| 1284   window.expectTrue = createExpect(assertTrue); | 1295   exports.expectTrue = createExpect(assertTrue); | 
| 1285   window.expectFalse = createExpect(assertFalse); | 1296   exports.expectFalse = createExpect(assertFalse); | 
| 1286   window.expectGE = createExpect(assertGE); | 1297   exports.expectGE = createExpect(assertGE); | 
| 1287   window.expectGT = createExpect(assertGT); | 1298   exports.expectGT = createExpect(assertGT); | 
| 1288   window.expectEquals = createExpect(assertEquals); | 1299   exports.expectEquals = createExpect(assertEquals); | 
| 1289   window.expectLE = createExpect(assertLE); | 1300   exports.expectLE = createExpect(assertLE); | 
| 1290   window.expectLT = createExpect(assertLT); | 1301   exports.expectLT = createExpect(assertLT); | 
| 1291   window.expectNotEquals = createExpect(assertNotEquals); | 1302   exports.expectNotEquals = createExpect(assertNotEquals); | 
| 1292   window.expectNotReached = createExpect(assertNotReached); | 1303   exports.expectNotReached = createExpect(assertNotReached); | 
| 1293   window.preloadJavascriptLibraries = preloadJavascriptLibraries; | 1304   exports.preloadJavascriptLibraries = preloadJavascriptLibraries; | 
| 1294   window.registerMessageCallback = registerMessageCallback; | 1305   exports.registerMessageCallback = registerMessageCallback; | 
| 1295   window.registerMockGlobals = registerMockGlobals; | 1306   exports.registerMockGlobals = registerMockGlobals; | 
| 1296   window.registerMockMessageCallbacks = registerMockMessageCallbacks; | 1307   exports.registerMockMessageCallbacks = registerMockMessageCallbacks; | 
| 1297   window.resetTestState = resetTestState; | 1308   exports.resetTestState = resetTestState; | 
| 1298   window.runAllActions = runAllActions; | 1309   exports.runAllActions = runAllActions; | 
| 1299   window.runAllActionsAsync = runAllActionsAsync; | 1310   exports.runAllActionsAsync = runAllActionsAsync; | 
| 1300   window.runTest = runTest; | 1311   exports.runTest = runTest; | 
| 1301   window.runTestFunction = runTestFunction; | 1312   exports.runTestFunction = runTestFunction; | 
| 1302   window.SaveMockArguments = SaveMockArguments; | 1313   exports.SaveMockArguments = SaveMockArguments; | 
| 1303   window.DUMMY_URL = DUMMY_URL; | 1314   exports.DUMMY_URL = DUMMY_URL; | 
| 1304   window.TEST = TEST; | 1315   exports.TEST = TEST; | 
| 1305   window.TEST_F = TEST_F; | 1316   exports.TEST_F = TEST_F; | 
| 1306   window.GEN = GEN; | 1317   exports.GEN = GEN; | 
| 1307   window.WhenTestDone = WhenTestDone; | 1318   exports.GEN_INCLUDE = GEN_INCLUDE; | 
|  | 1319   exports.WhenTestDone = WhenTestDone; | 
| 1308 | 1320 | 
| 1309   // Import the Mock4JS helpers. | 1321   // Import the Mock4JS helpers. | 
| 1310   Mock4JS.addMockSupport(window); | 1322   Mock4JS.addMockSupport(exports); | 
| 1311 })(('window' in this) ? window : this); | 1323 })(this); | 
| OLD | NEW | 
|---|