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>
8 if (window
.testRunner
) {
9 testRunner
.dumpAsText();
10 testRunner
.waitUntilDone();
15 document
.getElementById('console').appendChild(document
.createTextNode(message
+ '\n'));
19 var sawUploadProgress
;
21 function progress(evt
)
28 function allowedUploadProgress()
30 if (sawUploadProgress
)
33 sawUploadProgress
= true;
34 log("upload.onprogress");
37 function notAllowedUploadProgress()
39 if (sawUploadProgress
)
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
;
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() {
70 log("Response length: " + xhr
.responseText
.length
);
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
);
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();