OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Set some global variables for the browsertest to pick up |
| 6 var keyTestNamespace = { |
| 7 keypressSucceeded: false, |
| 8 keypressText: '' |
| 9 }; |
| 10 |
| 11 /** |
| 12 * Method to make an XHR call to the server for status |
| 13 */ |
| 14 // TODO(chaitali): Update this method to poll and get status of all |
| 15 // test vars in each poll and stop when all are true. |
| 16 function poll() { |
| 17 |
| 18 var request = new XMLHttpRequest(); |
| 19 request.open('GET', 'poll?test=keytest', true); |
| 20 |
| 21 request.onreadystatechange = function() { |
| 22 if (request.readyState == 4 && request.status == 200) { |
| 23 console.log('Polling status : ' + request.responseText); |
| 24 var data; |
| 25 try { |
| 26 data = JSON.parse(request.responseText); |
| 27 } catch (err) { |
| 28 console.log('Could not parse server response.'); |
| 29 return; |
| 30 } |
| 31 // If keypress succeeded then |
| 32 // update relevant vars and stop polling. |
| 33 if (data.keypressSucceeded == true) { |
| 34 keyTestNamespace.keypressSucceeded = data.keypressSucceeded; |
| 35 keyTestNamespace.keypressText = data.keypressText; |
| 36 } else { |
| 37 // If keypress did not succeed we should |
| 38 // continue polling. |
| 39 setTimeout(poll, 1000); |
| 40 } |
| 41 } |
| 42 }; |
| 43 |
| 44 request.onerror = function() { |
| 45 console.log('Polling failed'); |
| 46 }; |
| 47 |
| 48 request.send(); |
| 49 } |
| 50 |
| 51 window.addEventListener( |
| 52 'load', |
| 53 poll.bind(null), |
| 54 false); |
| 55 |
OLD | NEW |