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 * @fileoverview | 6 * @fileoverview |
7 * | 7 * |
8 * Provides basic functionality for JavaScript based browser test. | 8 * Provides basic functionality for JavaScript based browser test. |
9 * | 9 * |
10 * To define a browser test, create a class under the browserTest namespace. | 10 * To define a browser test, create a class under the browserTest namespace. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 */ | 123 */ |
124 browserTest.pass = function() { | 124 browserTest.pass = function() { |
125 browserTest.automationController_.send(JSON.stringify({ | 125 browserTest.automationController_.send(JSON.stringify({ |
126 succeeded: true, | 126 succeeded: true, |
127 error_message: '', | 127 error_message: '', |
128 stack_trace: '' | 128 stack_trace: '' |
129 })); | 129 })); |
130 }; | 130 }; |
131 | 131 |
132 /** | 132 /** |
133 * @param {string} id | 133 * @param {string} id The id or the selector of the element. |
134 * @return {void} | 134 * @return {void} |
135 */ | 135 */ |
136 browserTest.clickOnControl = function(id) { | 136 browserTest.clickOnControl = function(id) { |
137 var element = document.getElementById(id); | 137 var element = document.getElementById(id); |
| 138 if (!element) { |
| 139 element = document.querySelector(id); |
| 140 } |
138 browserTest.expect(element, 'No such element: ' + id); | 141 browserTest.expect(element, 'No such element: ' + id); |
139 element.click(); | 142 element.click(); |
140 }; | 143 }; |
141 | 144 |
142 /** | 145 /** |
143 * @param {remoting.AppMode} expectedMode | 146 * @param {remoting.AppMode} expectedMode |
144 * @param {number=} opt_timeout | 147 * @param {number=} opt_timeout |
145 * @return {Promise} | 148 * @return {Promise} |
146 */ | 149 */ |
147 browserTest.onUIMode = function(expectedMode, opt_timeout) { | 150 browserTest.onUIMode = function(expectedMode, opt_timeout) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 }; | 189 }; |
187 | 190 |
188 /** | 191 /** |
189 * @return {Promise} | 192 * @return {Promise} |
190 */ | 193 */ |
191 browserTest.connectMe2Me = function() { | 194 browserTest.connectMe2Me = function() { |
192 var AppMode = remoting.AppMode; | 195 var AppMode = remoting.AppMode; |
193 // The one second timeout is necessary because the click handler of | 196 // The one second timeout is necessary because the click handler of |
194 // 'this-host-connect' is registered asynchronously. | 197 // 'this-host-connect' is registered asynchronously. |
195 return base.Promise.sleep(1000).then(function() { | 198 return base.Promise.sleep(1000).then(function() { |
196 browserTest.clickOnControl('this-host-connect'); | 199 browserTest.clickOnControl('local-host-connect-button'); |
197 }).then(function(){ | 200 }).then(function(){ |
198 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE); | 201 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE); |
199 }).then(function() { | 202 }).then(function() { |
200 // On fulfilled. | 203 // On fulfilled. |
201 browserTest.clickOnControl('host-needs-update-connect-button'); | 204 browserTest.clickOnControl('host-needs-update-connect-button'); |
202 }, function() { | 205 }, function() { |
203 // On time out. | 206 // On time out. |
204 return Promise.resolve(); | 207 return Promise.resolve(); |
205 }).then(function() { | 208 }).then(function() { |
206 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); | 209 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 * @param {string} pin | 404 * @param {string} pin |
402 * @return {Promise} | 405 * @return {Promise} |
403 */ | 406 */ |
404 browserTest.ensureHostStartedWithPIN = function(pin) { | 407 browserTest.ensureHostStartedWithPIN = function(pin) { |
405 // Return if host is already | 408 // Return if host is already |
406 return browserTest.isLocalHostStarted().then( | 409 return browserTest.isLocalHostStarted().then( |
407 /** @param {boolean} started */ | 410 /** @param {boolean} started */ |
408 function(started){ | 411 function(started){ |
409 if (!started) { | 412 if (!started) { |
410 console.log('browserTest: Enabling remote connection.'); | 413 console.log('browserTest: Enabling remote connection.'); |
411 browserTest.clickOnControl('start-daemon'); | 414 browserTest.clickOnControl('.start-daemon'); |
412 } else { | 415 } else { |
413 console.log('browserTest: Changing the PIN of the host to: ' + | 416 console.log('browserTest: Changing the PIN of the host to: ' + |
414 pin + '.'); | 417 pin + '.'); |
415 browserTest.clickOnControl('change-daemon-pin'); | 418 browserTest.clickOnControl('.change-daemon-pin'); |
416 } | 419 } |
417 return browserTest.setupPIN(pin); | 420 return browserTest.setupPIN(pin); |
418 }); | 421 }); |
419 }; | 422 }; |
420 | 423 |
421 /** | 424 /** |
422 * Called by Browser Test in C++ | 425 * Called by Browser Test in C++ |
423 * @param {string} pin | 426 * @param {string} pin |
424 * @suppress {checkTypes} | 427 * @suppress {checkTypes} |
425 */ | 428 */ |
426 browserTest.ensureRemoteConnectionEnabled = function(pin) { | 429 browserTest.ensureRemoteConnectionEnabled = function(pin) { |
427 browserTest.ensureHostStartedWithPIN(pin).then(function() { | 430 browserTest.ensureHostStartedWithPIN(pin).then(function() { |
428 browserTest.pass(); | 431 browserTest.pass(); |
429 }, function(reason) { | 432 }, function(reason) { |
430 browserTest.fail(reason); | 433 browserTest.fail(reason); |
431 }); | 434 }); |
432 }; | 435 }; |
433 | 436 |
434 browserTest.init(); | 437 browserTest.init(); |
OLD | NEW |