Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / xmlhttprequest / simple-cross-origin-progress-events.html
blob4735be930570526bc560c4b9b8168c1613d7e224
1 <!doctype html>
2 <html>
3 <body>
4 <p>Test that upload progress events are not dispatched for simple cross-origin requests
5 (i.e. if the listener is set after calling send(), and there are no other reasons to make a preflight request).</p>
6 <pre id="console"></pre>
7 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 function log(message)
15 document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
18 var sawProgress;
19 var sawUploadProgress;
21 function progress(evt)
23 if (!sawProgress)
24 log("onprogress");
25 sawProgress = true;
28 function allowedUploadProgress()
30 if (sawUploadProgress)
31 return;
33 sawUploadProgress = true;
34 log("upload.onprogress");
37 function notAllowedUploadProgress()
39 if (sawUploadProgress)
40 return;
42 sawUploadProgress = true;
43 log("FAIL: upload.onprogress");
46 // Build a long string.
47 var stringToSend = "a";
48 for (var i = 0; i < 23; ++i)
49 stringToSend += stringToSend;
51 function test1()
53 sawProgress = false;
54 sawUploadProgress = false;
56 log("Test 1: The URL is allowed for cross-origin requests");
58 var xhr = new XMLHttpRequest();
59 xhr.onprogress = progress;
60 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-progress-events.cgi?allow", true);
61 xhr.setRequestHeader("Content-Type", "text/plain");
62 xhr.send(stringToSend);
63 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart"); };
64 xhr.upload.onprogress = notAllowedUploadProgress;
65 xhr.upload.onload = function() { log("FAIL: upload.onload"); };
66 xhr.upload.onerror = function() { log("FAIL: upload.onerror"); };
67 xhr.onerror = function() { log("onerror") };
68 xhr.onload = function() {
69 log("onload");
70 log("Response length: " + xhr.responseText.length);
71 test2();
75 function test2()
77 sawProgress = false;
78 sawUploadProgress = false;
80 log("\nTest 2: The URL is not allowed for cross-origin requests");
82 var xhr = new XMLHttpRequest();
83 xhr.onprogress = progress;
84 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-progress-events.cgi", true);
85 xhr.setRequestHeader("Content-Type", "text/plain");
86 xhr.send(stringToSend);
87 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart"); };
88 xhr.upload.onprogress = notAllowedUploadProgress;
89 xhr.upload.onload = function() { log("FAIL: upload.onload"); };
90 xhr.upload.onerror = function() { log("FAIL: upload.onerror"); };
91 xhr.onload = function() { log("onload"); };
92 xhr.onerror = function() {
93 log("onerror (expected)");
94 log("Response length: " + xhr.responseText.length);
95 test3();
99 function test3()
101 sawProgress = false;
102 sawUploadProgress = false;
104 log("\nTest 3: The URL is not allowed for cross-origin requests and at least one upload event is listened for before doing the send.");
106 var xhr = new XMLHttpRequest();
107 xhr.onprogress = progress;
108 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-progress-events.cgi", true);
109 xhr.setRequestHeader("Content-Type", "text/plain");
110 xhr.upload.onloadstart = function() { log("upload.onloadstart"); };
111 xhr.send(stringToSend);
112 xhr.upload.onprogress = allowedUploadProgress;
113 xhr.upload.onload = function() { log("FAIL: upload.onload"); };
114 xhr.upload.onerror = function() { log("upload.onerror (expected)"); };
115 xhr.onload = function() { log("onload"); }
116 xhr.onerror = function() {
117 log("onerror (expected)");
118 log("Response length: " + xhr.responseText.length);
119 if (window.testRunner)
120 testRunner.notifyDone();
124 test1();
125 </script>
126 </body>
127 </html>