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.github.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/CONTRIBUTORS.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/PATENTS.txt
12 <title>core-ajax
</title>
14 <script src=
"../../webcomponentsjs/webcomponents.js"></script>
15 <script src=
"../../web-component-tester/browser.js"></script>
19 <link rel=
"import" href=
"../core-ajax.html">
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 response
34 test('race-condition', function(done
) {
35 var ajax
= document
.querySelector("core-ajax");
36 var xhr
= sinon
.useFakeXMLHttpRequest();
38 "Content-Type": "text/json"
40 var body = function(url
) {
41 return '{"url": "' + url
+ '"}';
44 xhr
.onCreate = function (xhr
) {
48 // Make request1, then request2. request2 returns first, followed by request1.
51 ajax
.url
="http://example.org/request1"
56 ajax
.url
="http://example.org/request2"
61 requests
[0].respond(200, headers
, body("http://example.org/request2"));
66 requests
[1].respond(200, headers
, body("http://example.org/request1"));
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.");