OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 | 31 |
32 /** | 32 /** |
33 * @fileoverview This file contains small testing framework along with the | 33 * @fileoverview This file contains small testing framework along with the |
34 * test suite for the frontend. These tests are a part of the continues build | 34 * test suite for the frontend. These tests are a part of the continues build |
35 * and are executed by the devtools_sanity_unittest.cc as a part of the | 35 * and are executed by the devtools_sanity_unittest.cc as a part of the |
36 * Interactive UI Test suite. | 36 * Interactive UI Test suite. |
37 * FIXME: change field naming style to use trailing underscore. | 37 * FIXME: change field naming style to use trailing underscore. |
38 */ | 38 */ |
39 | 39 |
40 if (window.domAutomationController) { | 40 function createTestSuite(domAutomationController) |
| 41 { |
41 | 42 |
42 var ___interactiveUiTestsMode = true; | 43 var ___interactiveUiTestsMode = true; |
43 | 44 |
44 /** | 45 /** |
45 * Test suite for interactive UI tests. | 46 * Test suite for interactive UI tests. |
46 * @constructor | 47 * @constructor |
47 */ | 48 */ |
48 TestSuite = function() | 49 function TestSuite() |
49 { | 50 { |
50 this.controlTaken_ = false; | 51 this.controlTaken_ = false; |
51 this.timerId_ = -1; | 52 this.timerId_ = -1; |
52 }; | 53 }; |
53 | 54 |
54 | 55 |
55 /** | 56 /** |
56 * Reports test failure. | 57 * Reports test failure. |
57 * @param {string} message Failure description. | 58 * @param {string} message Failure description. |
58 */ | 59 */ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 } | 142 } |
142 this.reportOk_(); | 143 this.reportOk_(); |
143 }; | 144 }; |
144 | 145 |
145 | 146 |
146 /** | 147 /** |
147 * Async tests use this one to report that they are completed. | 148 * Async tests use this one to report that they are completed. |
148 */ | 149 */ |
149 TestSuite.prototype.reportOk_ = function() | 150 TestSuite.prototype.reportOk_ = function() |
150 { | 151 { |
151 window.domAutomationController.send("[OK]"); | 152 domAutomationController.send("[OK]"); |
152 }; | 153 }; |
153 | 154 |
154 | 155 |
155 /** | 156 /** |
156 * Async tests use this one to report failures. | 157 * Async tests use this one to report failures. |
157 */ | 158 */ |
158 TestSuite.prototype.reportFailure_ = function(error) | 159 TestSuite.prototype.reportFailure_ = function(error) |
159 { | 160 { |
160 if (this.timerId_ !== -1) { | 161 if (this.timerId_ !== -1) { |
161 clearTimeout(this.timerId_); | 162 clearTimeout(this.timerId_); |
162 this.timerId_ = -1; | 163 this.timerId_ = -1; |
163 } | 164 } |
164 window.domAutomationController.send("[FAILED] " + error); | 165 domAutomationController.send("[FAILED] " + error); |
165 }; | 166 }; |
166 | 167 |
167 | 168 |
168 /** | 169 /** |
169 * Runs all global functions starting with "test" as unit tests. | 170 * Runs all global functions starting with "test" as unit tests. |
170 */ | 171 */ |
171 TestSuite.prototype.runTest = function(testName) | 172 TestSuite.prototype.runTest = function(testName) |
172 { | 173 { |
173 try { | 174 try { |
174 this[testName](); | 175 this[testName](); |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 */ | 899 */ |
899 TestSuite.createKeyEvent = function(keyIdentifier) | 900 TestSuite.createKeyEvent = function(keyIdentifier) |
900 { | 901 { |
901 var evt = document.createEvent("KeyboardEvent"); | 902 var evt = document.createEvent("KeyboardEvent"); |
902 evt.initKeyboardEvent("keydown", true /* can bubble */, true /* can cancel *
/, null /* view */, keyIdentifier, ""); | 903 evt.initKeyboardEvent("keydown", true /* can bubble */, true /* can cancel *
/, null /* view */, keyIdentifier, ""); |
903 return evt; | 904 return evt; |
904 }; | 905 }; |
905 | 906 |
906 | 907 |
907 /** | 908 /** |
908 * Test runner for the test suite. | |
909 */ | |
910 var uiTests = {}; | |
911 | |
912 | |
913 /** | |
914 * Run each test from the test suit on a fresh instance of the suite. | 909 * Run each test from the test suit on a fresh instance of the suite. |
915 */ | 910 */ |
916 uiTests.runAllTests = function() | 911 TestSuite._runAllTests = function() |
917 { | 912 { |
918 // For debugging purposes. | 913 // For debugging purposes. |
919 for (var name in TestSuite.prototype) { | 914 for (var name in TestSuite.prototype) { |
920 if (name.substring(0, 4) === "test" && typeof TestSuite.prototype[name]
=== "function") | 915 if (name.substring(0, 4) === "test" && typeof TestSuite.prototype[name]
=== "function") |
921 uiTests.runTest(name); | 916 TestSuite._runTest(name); |
922 } | 917 } |
923 }; | 918 }; |
924 | 919 |
925 | 920 |
926 /** | 921 /** |
927 * Run specified test on a fresh instance of the test suite. | 922 * Run specified test on a fresh instance of the test suite. |
928 * @param {string} name Name of a test method from TestSuite class. | 923 * @param {string} name Name of a test method from TestSuite class. |
929 */ | 924 */ |
930 uiTests.runTest = function(name) | 925 TestSuite._runTest = function(name) |
931 { | 926 { |
932 if (uiTests._populatedInterface) | 927 if (TestSuite._populatedInterface) |
933 new TestSuite().runTest(name); | 928 new TestSuite().runTest(name); |
934 else | 929 else |
935 uiTests._pendingTestName = name; | 930 TestSuite._pendingTestName = name; |
936 }; | 931 }; |
937 | 932 |
938 (function() { | |
939 | |
940 function runTests() | 933 function runTests() |
941 { | 934 { |
942 uiTests._populatedInterface = true; | 935 TestSuite._populatedInterface = true; |
943 var name = uiTests._pendingTestName; | 936 var name = TestSuite._pendingTestName; |
944 delete uiTests._pendingTestName; | 937 delete TestSuite._pendingTestName; |
945 if (name) | 938 if (name) |
946 new TestSuite().runTest(name); | 939 new TestSuite().runTest(name); |
947 } | 940 } |
948 | 941 |
949 WebInspector.notifications.addEventListener(WebInspector.NotificationService.Eve
nts.InspectorAgentEnabledForTests, runTests); | 942 WebInspector.notifications.addEventListener(WebInspector.NotificationService.Eve
nts.InspectorAgentEnabledForTests, runTests); |
950 | 943 |
951 })(); | 944 return TestSuite; |
952 | 945 |
953 } | 946 } |
| 947 |
| 948 if (window.parent && window.parent.uiTests) |
| 949 window.parent.uiTests.testSuiteReady(createTestSuite); |
OLD | NEW |