OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <!-- | |
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
7 Code distributed by Google as part of the polymer project is also | |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
9 --> | |
10 <html> | |
11 <head> | |
12 <title>core-ajax</title> | |
13 | |
14 <script src="../../webcomponentsjs/webcomponents.js"></script> | |
15 <script src="../../web-component-tester/browser.js"></script> | |
16 | |
17 | |
18 | |
19 <link rel="import" href="../core-ajax.html"> | |
20 | |
21 </head> | |
22 <body> | |
23 | |
24 <core-ajax | |
25 handleAs="json" | |
26 auto></core-ajax> | |
27 | |
28 <!-- | |
29 Test that when core-ajax fires multiple times as requests are updated, | |
30 only the response from the most recent request is used to update the respons
e | |
31 object. | |
32 --> | |
33 <script> | |
34 test('race-condition', function(done) { | |
35 var ajax = document.querySelector("core-ajax"); | |
36 var xhr = sinon.useFakeXMLHttpRequest(); | |
37 var headers = { | |
38 "Content-Type": "text/json" | |
39 }; | |
40 var body = function(url) { | |
41 return '{"url": "' + url + '"}'; | |
42 }; | |
43 var requests = []; | |
44 xhr.onCreate = function (xhr) { | |
45 requests.push(xhr); | |
46 }; | |
47 | |
48 // Make request1, then request2. request2 returns first, followed by reque
st1. | |
49 async.series([ | |
50 function(cb) { | |
51 ajax.url="http://example.org/request1" | |
52 cb(); | |
53 }, | |
54 animationFrameFlush, | |
55 function(cb) { | |
56 ajax.url="http://example.org/request2" | |
57 cb(); | |
58 }, | |
59 animationFrameFlush, | |
60 function(cb) { | |
61 requests[0].respond(200, headers, body("http://example.org/request2"))
; | |
62 cb(); | |
63 }, | |
64 flush, | |
65 function(cb) { | |
66 requests[1].respond(200, headers, body("http://example.org/request1"))
; | |
67 cb(); | |
68 }, | |
69 flush, | |
70 function(cb) { | |
71 assert(ajax.response.url.match('request1'), | |
72 "Race condition detected. An earlier request's delayed response "
+ | |
73 "caused the more recent request's response to be overwritten."); | |
74 done(); | |
75 cb(); | |
76 } | |
77 ], function(){}); | |
78 }); | |
79 </script> | |
80 </body> | |
81 </html> | |
OLD | NEW |