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..c9ce6e54310222738fbcd0c67eb372c75b5f8c2a |
| --- /dev/null |
| +++ b/chrome/test/remoting/http_server/clientpage.js |
| @@ -0,0 +1,46 @@ |
| +// 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 keypressSucceeded = false; |
| +var keypressText = ''; |
| + |
| +/** |
| + * Method to make an XHR call to the server for status |
| + */ |
| +// TODO(chaitali):Update this method to poll and get status of all |
|
Jamie
2014/03/04 21:40:35
Nit: Space before "Update".
chaitali
2014/03/05 22:02:22
Done.
|
| +// test vars in each poll and stop when all are true. |
| +function poll() { |
| + |
| + var request = new XMLHttpRequest(); |
| + request.open('GET', '/poll?test=keytest', true); |
|
Jamie
2014/03/04 21:40:35
Can we use a relative URL here too?
chaitali
2014/03/05 22:02:22
Removed the /. The rest of it needs to remain so c
Jamie
2014/03/06 00:15:01
Yes, that's what I had in mind.
|
| + |
| +request.onreadystatechange = function() { |
|
Jamie
2014/03/04 21:40:35
Nit: Indentation.
chaitali
2014/03/05 22:02:22
Done.
|
| + if(request.readyState == 4 && request.status == 200) { |
|
Jamie
2014/03/04 21:40:35
Nit: Space after "if".
chaitali
2014/03/05 22:02:22
Done.
|
| + console.log('Polling status : ' + request.responseText); |
| + data = JSON.parse(request.responseText); |
|
Jamie
2014/03/04 21:40:35
This should be in a try...catch block, or there's
chaitali
2014/03/05 22:02:22
Done.
|
| + // If keypress succeeded then |
| + // update relevant vars and stop polling. |
| + if (data.keypressSucceeded == true) { |
| + keypressSucceeded = data.keypressSucceeded; |
| + keypressText = data.keypressText; |
| + } else { |
| + // If keypress did not succeed we should |
| + // continue polling. |
| + setTimeout(poll, 3000); |
|
Jamie
2014/03/04 21:40:35
3s seems like quite a long time to wait. I think w
chaitali
2014/03/05 22:02:22
Changed to 1s.
I thought about long polling but w
Jamie
2014/03/06 00:15:01
This is fine for now, but let's talk off-line abou
|
| + } |
| + } |
| + }; |
| + |
| + request.onerror = function() { |
| + console.log('Polling failed'); |
| + }; |
| + |
| +request.send(); |
|
Jamie
2014/03/04 21:40:35
Nit: Indentation.
chaitali
2014/03/05 22:02:22
Done.
|
| +}; |
| + |
| +window.addEventListener('load', function(){ |
| + poll(); |
| +}); |
|
Jamie
2014/03/04 21:40:35
I think you're missing a 'false' parameter for add
chaitali
2014/03/05 22:02:22
Done.
|
| + |