OLD | NEW |
---|---|
1 <html> | 1 <html> |
2 <body> | 2 <body> |
3 <p>Test that upload progress events are not dispatched for simple cross-origin r equests | 3 <p>Test that upload progress events are not dispatched for simple cross-origin r equests |
4 (i.e. if the listener is set after calling send(), and there are no other reason s to make a preflight request).</p> | 4 (i.e. if the listener is set after calling send(), and there are no other reason s to make a preflight request).</p> |
5 <pre id="console"></pre> | 5 <pre id="console"></pre> |
6 <script> | 6 <script> |
7 if (window.testRunner) { | 7 if (window.testRunner) { |
8 testRunner.dumpAsText(); | 8 testRunner.dumpAsText(); |
9 testRunner.waitUntilDone(); | 9 testRunner.waitUntilDone(); |
10 } | 10 } |
11 | 11 |
12 function log(message) | 12 function log(message) |
13 { | 13 { |
14 document.getElementById('console').appendChild(document.createTextNode(messa ge + '\n')); | 14 document.getElementById('console').appendChild(document.createTextNode(messa ge + '\n')); |
15 } | 15 } |
16 | 16 |
17 var sawProgress; | 17 var sawProgress; |
18 var sawUploadProgress; | 18 var sawUploadProgress; |
19 var canSeeUploadProgress = false; | |
19 | 20 |
20 function progress(evt) | 21 function progress(evt) |
21 { | 22 { |
22 if (!sawProgress) | 23 if (!sawProgress) |
23 log("onprogress"); | 24 log("onprogress"); |
24 sawProgress = true; | 25 sawProgress = true; |
25 } | 26 } |
26 | 27 |
27 function uploadProgress(evt) | 28 function uploadProgress(evt) |
28 { | 29 { |
29 if (!sawUploadProgress) | 30 if (!sawUploadProgress) |
30 log("FAIL: upload.onprogress"); | 31 log((canSeeUploadProgress ? "" : "FAIL: ") + "upload.onprogress"); |
31 sawUploadProgress = true; | 32 sawUploadProgress = true; |
32 } | 33 } |
33 | 34 |
34 // Build a long string. | 35 // Build a long string. |
35 var stringToSend = "a"; | 36 var stringToSend = "a"; |
36 for (var i = 0; i < 23; ++i) | 37 for (var i = 0; i < 23; ++i) |
37 stringToSend += stringToSend; | 38 stringToSend += stringToSend; |
38 | 39 |
39 function test1() | 40 function test1() |
40 { | 41 { |
41 sawProgress = false; | 42 sawProgress = false; |
42 sawUploadProgress = false; | 43 sawUploadProgress = false; |
tyoshino (SeeGerritForStatus)
2013/11/19 16:57:38
let's set canSeeUploadProgress in each test case.
sof
2013/11/19 18:57:03
Yes, let's do that; needlessly stateful as it is.
| |
43 | 44 |
44 log("Test 1: The URL is allowed for cross-origin requests"); | 45 log("Test 1: The URL is allowed for cross-origin requests"); |
45 | 46 |
46 var xhr = new XMLHttpRequest(); | 47 var xhr = new XMLHttpRequest(); |
47 xhr.onprogress = progress; | 48 xhr.onprogress = progress; |
48 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site- progress-events.cgi?allow", true); | 49 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site- progress-events.cgi?allow", true); |
49 xhr.setRequestHeader("Content-Type", "text/plain"); | 50 xhr.setRequestHeader("Content-Type", "text/plain"); |
50 xhr.send(stringToSend); | 51 xhr.send(stringToSend); |
51 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart") } | 52 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart") } |
52 xhr.upload.onprogress = uploadProgress; | 53 xhr.upload.onprogress = uploadProgress; |
(...skipping 30 matching lines...) Expand all Loading... | |
83 } | 84 } |
84 xhr.onload = function() { | 85 xhr.onload = function() { |
85 log("onload"); | 86 log("onload"); |
86 } | 87 } |
87 } | 88 } |
88 | 89 |
89 function test3() | 90 function test3() |
90 { | 91 { |
91 sawProgress = false; | 92 sawProgress = false; |
92 sawUploadProgress = false; | 93 sawUploadProgress = false; |
94 canSeeUploadProgress = true; | |
93 | 95 |
94 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."); | 96 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."); |
95 | 97 |
96 var xhr = new XMLHttpRequest(); | 98 var xhr = new XMLHttpRequest(); |
97 xhr.onprogress = progress; | 99 xhr.onprogress = progress; |
98 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site- progress-events.cgi", true); | 100 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site- progress-events.cgi", true); |
99 xhr.setRequestHeader("Content-Type", "text/plain"); | 101 xhr.setRequestHeader("Content-Type", "text/plain"); |
100 xhr.upload.onloadstart = function() { log("upload.onloadstart") } | 102 xhr.upload.onloadstart = function() { log("upload.onloadstart") } |
101 xhr.send(stringToSend); | 103 xhr.send(stringToSend); |
102 xhr.upload.onprogress = uploadProgress; | 104 xhr.upload.onprogress = uploadProgress; |
103 xhr.upload.onload = function() { log("FAIL: upload.onload") } | 105 xhr.upload.onload = function() { log("FAIL: upload.onload") } |
104 xhr.upload.onerror = function() { | 106 xhr.upload.onerror = function() { |
105 log("upload.onerror (expected)") | 107 log("upload.onerror (expected)") |
106 } | 108 } |
107 xhr.onerror = function() { | 109 xhr.onerror = function() { |
108 log("onerror (expected)"); | 110 log("onerror (expected)"); |
109 log("Response length: " + xhr.responseText.length); | 111 log("Response length: " + xhr.responseText.length); |
110 if (window.testRunner) | 112 if (window.testRunner) |
111 testRunner.notifyDone(); | 113 testRunner.notifyDone(); |
112 } | 114 } |
113 xhr.onload = function() { | 115 xhr.onload = function() { |
114 log("onload"); | 116 log("onload"); |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
118 test1(); | 120 test1(); |
119 </script> | 121 </script> |
120 </body> | 122 </body> |
121 </html> | 123 </html> |
OLD | NEW |