Chromium Code Reviews| Index: chrome/test/remoting/http_server/clientpage.js |
| diff --git a/chrome/test/remoting/http_server/clientpage.js b/chrome/test/remoting/http_server/clientpage.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..62e58d527f054e5e277f29e02cf49f85346f6ea1 |
| --- /dev/null |
| +++ b/chrome/test/remoting/http_server/clientpage.js |
| @@ -0,0 +1,57 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Set some global variables for the browsertest to pick up |
| +var keyTestNamespace = { |
| + keypressSucceeded: false, |
| + keypressText: '' |
| +}; |
| + |
| +/** |
| + * Method to make an XHR call to the server for status |
| + */ |
| +// TODO(chaitali): Update this method to poll and get status of all |
| +// test vars in each poll and stop when all are true. |
| +function poll() { |
| + |
| + var request = new XMLHttpRequest(); |
| + request.open('GET', 'poll?test=keytest', true); |
| + |
| + request.onreadystatechange = function() { |
| + if (request.readyState == 4 && request.status == 200) { |
| + console.log('Polling status : ' + request.responseText); |
| + var data; |
| + try { |
| + data = JSON.parse(request.responseText); |
| + } catch (err) { |
| + console.log('Could not parse server response.'); |
| + return; |
| + } |
| + // If keypress succeeded then |
| + // update relevant vars and stop polling. |
| + if (data.keypressSucceeded == true) { |
| + keyTestNamespace.keypressSucceeded = data.keypressSucceeded; |
| + keyTestNamespace.keypressText = data.keypressText; |
| + } else { |
| + // If keypress did not succeed we should |
| + // continue polling. |
| + setTimeout(poll, 1000); |
| + } |
| + } |
| + }; |
| + |
| + request.onerror = function() { |
| + console.log('Polling failed'); |
| + }; |
| + |
| + request.send(); |
| +}; |
| + |
| +window.addEventListener( |
| + 'load', |
| + function(){ |
|
Jamie
2014/03/06 00:15:01
Nit: space before '{'. Or just use poll.bind(null)
chaitali
2014/03/06 00:41:51
Done.
|
| + poll(); |
| + }, |
| + false); |
| + |