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 keypressSucceeded = false; | |
7 var keypressText = ''; | |
8 | |
9 /** | |
10 * Method to make an XHR call to the server for status | |
11 */ | |
12 // 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.
| |
13 // test vars in each poll and stop when all are true. | |
14 function poll() { | |
15 | |
16 var request = new XMLHttpRequest(); | |
17 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.
| |
18 | |
19 request.onreadystatechange = function() { | |
Jamie
2014/03/04 21:40:35
Nit: Indentation.
chaitali
2014/03/05 22:02:22
Done.
| |
20 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.
| |
21 console.log('Polling status : ' + request.responseText); | |
22 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.
| |
23 // If keypress succeeded then | |
24 // update relevant vars and stop polling. | |
25 if (data.keypressSucceeded == true) { | |
26 keypressSucceeded = data.keypressSucceeded; | |
27 keypressText = data.keypressText; | |
28 } else { | |
29 // If keypress did not succeed we should | |
30 // continue polling. | |
31 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
| |
32 } | |
33 } | |
34 }; | |
35 | |
36 request.onerror = function() { | |
37 console.log('Polling failed'); | |
38 }; | |
39 | |
40 request.send(); | |
Jamie
2014/03/04 21:40:35
Nit: Indentation.
chaitali
2014/03/05 22:02:22
Done.
| |
41 }; | |
42 | |
43 window.addEventListener('load', function(){ | |
44 poll(); | |
45 }); | |
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.
| |
46 | |
OLD | NEW |