OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * Test suite for interactive UI tests. | 6 * Test suite for interactive UI tests. |
7 * @constructor | 7 * @constructor |
8 * @param {Object} domAutomationController DomAutomationController instance. | 8 * @param {Object} domAutomationController DomAutomationController instance. |
9 */ | 9 */ |
10 WebInspector.TestBase = function(domAutomationController) | 10 WebInspector.TestBase = function(domAutomationController) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 /** | 73 /** |
74 * Releases control over execution. | 74 * Releases control over execution. |
75 */ | 75 */ |
76 WebInspector.TestBase.prototype.releaseControl = function() | 76 WebInspector.TestBase.prototype.releaseControl = function() |
77 { | 77 { |
78 if (this.timerId_ !== -1) { | 78 if (this.timerId_ !== -1) { |
79 clearTimeout(this.timerId_); | 79 clearTimeout(this.timerId_); |
80 this.timerId_ = -1; | 80 this.timerId_ = -1; |
81 } | 81 } |
| 82 this.controlTaken_ = false; |
82 this.reportOk_(); | 83 this.reportOk_(); |
83 }; | 84 }; |
84 | 85 |
85 | 86 |
86 /** | 87 /** |
87 * Async tests use this one to report that they are completed. | 88 * Async tests use this one to report that they are completed. |
88 */ | 89 */ |
89 WebInspector.TestBase.prototype.reportOk_ = function() | 90 WebInspector.TestBase.prototype.reportOk_ = function() |
90 { | 91 { |
91 this.domAutomationController_.send("[OK]"); | 92 this.domAutomationController_.send("[OK]"); |
92 }; | 93 }; |
93 | 94 |
94 | 95 |
95 /** | 96 /** |
96 * Async tests use this one to report failures. | 97 * Async tests use this one to report failures. |
97 */ | 98 */ |
98 WebInspector.TestBase.prototype.reportFailure_ = function(error) | 99 WebInspector.TestBase.prototype.reportFailure_ = function(error) |
99 { | 100 { |
100 if (this.timerId_ !== -1) { | 101 if (this.timerId_ !== -1) { |
101 clearTimeout(this.timerId_); | 102 clearTimeout(this.timerId_); |
102 this.timerId_ = -1; | 103 this.timerId_ = -1; |
103 } | 104 } |
104 this.domAutomationController_.send("[FAILED] " + error); | 105 this.domAutomationController_.send("[FAILED] " + error); |
105 }; | 106 }; |
106 | 107 |
107 | 108 |
108 /** | 109 /** |
109 * Run specified test on a fresh instance of the test suite. | 110 * Run specified test on a fresh instance of the test suite. |
110 * @param {string} name Name of a test method from implementation class. | 111 * @param {Array<string>} args method name followed by its parameters. |
111 */ | 112 */ |
112 WebInspector.TestBase.prototype.dispatch = function(args) | 113 WebInspector.TestBase.prototype.dispatch = function(args) |
113 { | 114 { |
114 var methodName = args.shift(); | 115 var methodName = args.shift(); |
115 try { | 116 try { |
116 this[methodName].apply(this, args); | 117 this[methodName].apply(this, args); |
117 if (!this.controlTaken_) | 118 if (!this.controlTaken_) |
118 this.reportOk_(); | 119 this.reportOk_(); |
119 } catch (e) { | 120 } catch (e) { |
120 this.reportFailure_(e); | 121 this.reportFailure_(e); |
121 } | 122 } |
122 }; | 123 }; |
123 | 124 |
124 | 125 |
125 /** | 126 /** |
| 127 * Wrap an async method with TestBase.{takeControl(), releaseControl()} |
| 128 * and invoke TestBase.reportOk_ upon completion. |
| 129 * @param {Array<string>} args method name followed by its parameters. |
| 130 */ |
| 131 WebInspector.TestBase.prototype.waitForAsync = function(var_args) |
| 132 { |
| 133 var args = Array.prototype.slice.call(arguments); |
| 134 this.takeControl(); |
| 135 args.push(this.releaseControl.bind(this)); |
| 136 this.dispatch(args); |
| 137 }; |
| 138 |
| 139 /** |
126 * Overrides the method with specified name until it's called first time. | 140 * Overrides the method with specified name until it's called first time. |
127 * @param {!Object} receiver An object whose method to override. | 141 * @param {!Object} receiver An object whose method to override. |
128 * @param {string} methodName Name of the method to override. | 142 * @param {string} methodName Name of the method to override. |
129 * @param {!Function} override A function that should be called right after the | 143 * @param {!Function} override A function that should be called right after the |
130 * overridden method returns. | 144 * overridden method returns. |
131 * @param {?boolean} opt_sticky Whether restore original method after first run | 145 * @param {?boolean} opt_sticky Whether restore original method after first run |
132 * or not. | 146 * or not. |
133 */ | 147 */ |
134 WebInspector.TestBase.prototype.addSniffer = function(receiver, methodName, over
ride, opt_sticky) | 148 WebInspector.TestBase.prototype.addSniffer = function(receiver, methodName, over
ride, opt_sticky) |
135 { | 149 { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 196 } |
183 | 197 |
184 function onSchedule() | 198 function onSchedule() |
185 { | 199 { |
186 if (scheduleShouldFail) | 200 if (scheduleShouldFail) |
187 test.fail("Unexpected Throttler.schedule"); | 201 test.fail("Unexpected Throttler.schedule"); |
188 } | 202 } |
189 | 203 |
190 checkState(); | 204 checkState(); |
191 }; | 205 }; |
OLD | NEW |