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