Remove LOAD_SUB_FRAME load flag.
[chromium-blink-merge.git] / third_party / polymer / components / core-ajax / test / core-ajax-race.html
blob700ad12f8e6e8063eb0b7eb30511d053b1361981
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.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
9 -->
10 <html>
11 <head>
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">
21 </head>
22 <body>
24 <core-ajax
25 handleAs="json"
26 auto></core-ajax>
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 response
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"
40 var body = function(url) {
41 return '{"url": "' + url + '"}';
43 var requests = [];
44 xhr.onCreate = function (xhr) {
45 requests.push(xhr);
48 // Make request1, then request2. request2 returns first, followed by request1.
49 async.series([
50 function(cb) {
51 ajax.url="http://example.org/request1"
52 cb();
54 animationFrameFlush,
55 function(cb) {
56 ajax.url="http://example.org/request2"
57 cb();
59 animationFrameFlush,
60 function(cb) {
61 requests[0].respond(200, headers, body("http://example.org/request2"));
62 cb();
64 flush,
65 function(cb) {
66 requests[1].respond(200, headers, body("http://example.org/request1"));
67 cb();
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();
77 ], function(){});
78 });
79 </script>
80 </body>
81 </html>