| OLD | NEW |
| 1 <!doctype html> |
| 1 <html> | 2 <html> |
| 2 <body> | 3 <body> |
| 3 <p>Test that upload progress events are not dispatched for simple cross-origin r
equests | 4 <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> | 5 (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> | 6 <pre id="console"></pre> |
| 6 <script> | 7 <script> |
| 7 if (window.testRunner) { | 8 if (window.testRunner) { |
| 8 testRunner.dumpAsText(); | 9 testRunner.dumpAsText(); |
| 9 testRunner.waitUntilDone(); | 10 testRunner.waitUntilDone(); |
| 10 } | 11 } |
| 11 | 12 |
| 12 function log(message) | 13 function log(message) |
| 13 { | 14 { |
| 14 document.getElementById('console').appendChild(document.createTextNode(messa
ge + '\n')); | 15 document.getElementById('console').appendChild(document.createTextNode(messa
ge + '\n')); |
| 15 } | 16 } |
| 16 | 17 |
| 17 var sawProgress; | 18 var sawProgress; |
| 18 var sawUploadProgress; | 19 var sawUploadProgress; |
| 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 allowedUploadProgress() |
| 28 { | 29 { |
| 29 if (!sawUploadProgress) | 30 if (sawUploadProgress) |
| 30 log("FAIL: upload.onprogress"); | 31 return; |
| 32 |
| 31 sawUploadProgress = true; | 33 sawUploadProgress = true; |
| 34 log("upload.onprogress"); |
| 35 } |
| 36 |
| 37 function notAllowedUploadProgress() |
| 38 { |
| 39 if (sawUploadProgress) |
| 40 return; |
| 41 |
| 42 sawUploadProgress = true; |
| 43 log("FAIL: upload.onprogress"); |
| 32 } | 44 } |
| 33 | 45 |
| 34 // Build a long string. | 46 // Build a long string. |
| 35 var stringToSend = "a"; | 47 var stringToSend = "a"; |
| 36 for (var i = 0; i < 23; ++i) | 48 for (var i = 0; i < 23; ++i) |
| 37 stringToSend += stringToSend; | 49 stringToSend += stringToSend; |
| 38 | 50 |
| 39 function test1() | 51 function test1() |
| 40 { | 52 { |
| 41 sawProgress = false; | 53 sawProgress = false; |
| 42 sawUploadProgress = false; | 54 sawUploadProgress = false; |
| 43 | 55 |
| 44 log("Test 1: The URL is allowed for cross-origin requests"); | 56 log("Test 1: The URL is allowed for cross-origin requests"); |
| 45 | 57 |
| 46 var xhr = new XMLHttpRequest(); | 58 var xhr = new XMLHttpRequest(); |
| 47 xhr.onprogress = progress; | 59 xhr.onprogress = progress; |
| 48 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi?allow", true); | 60 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi?allow", true); |
| 49 xhr.setRequestHeader("Content-Type", "text/plain"); | 61 xhr.setRequestHeader("Content-Type", "text/plain"); |
| 50 xhr.send(stringToSend); | 62 xhr.send(stringToSend); |
| 51 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart") } | 63 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart"); }; |
| 52 xhr.upload.onprogress = uploadProgress; | 64 xhr.upload.onprogress = notAllowedUploadProgress; |
| 53 xhr.upload.onload = function() { log("FAIL: upload.onload") } | 65 xhr.upload.onload = function() { log("FAIL: upload.onload"); }; |
| 54 xhr.upload.onerror = function() { log("FAIL: upload.onerror") } | 66 xhr.upload.onerror = function() { log("FAIL: upload.onerror"); }; |
| 55 xhr.onerror = function() { log("onerror") } | 67 xhr.onerror = function() { log("onerror") }; |
| 56 xhr.onload = function() { | 68 xhr.onload = function() { |
| 57 log("onload"); | 69 log("onload"); |
| 58 log("Response length: " + xhr.responseText.length); | 70 log("Response length: " + xhr.responseText.length); |
| 59 test2(); | 71 test2(); |
| 60 } | 72 }; |
| 61 } | 73 } |
| 62 | 74 |
| 63 function test2() | 75 function test2() |
| 64 { | 76 { |
| 65 sawProgress = false; | 77 sawProgress = false; |
| 66 sawUploadProgress = false; | 78 sawUploadProgress = false; |
| 67 | 79 |
| 68 log("\nTest 2: The URL is not allowed for cross-origin requests"); | 80 log("\nTest 2: The URL is not allowed for cross-origin requests"); |
| 69 | 81 |
| 70 var xhr = new XMLHttpRequest(); | 82 var xhr = new XMLHttpRequest(); |
| 71 xhr.onprogress = progress; | 83 xhr.onprogress = progress; |
| 72 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi", true); | 84 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi", true); |
| 73 xhr.setRequestHeader("Content-Type", "text/plain"); | 85 xhr.setRequestHeader("Content-Type", "text/plain"); |
| 74 xhr.send(stringToSend); | 86 xhr.send(stringToSend); |
| 75 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart") } | 87 xhr.upload.onloadstart = function() { log("FAIL: upload.onloadstart"); }; |
| 76 xhr.upload.onprogress = uploadProgress; | 88 xhr.upload.onprogress = notAllowedUploadProgress; |
| 77 xhr.upload.onload = function() { log("FAIL: upload.onload") } | 89 xhr.upload.onload = function() { log("FAIL: upload.onload"); }; |
| 78 xhr.upload.onerror = function() { log("FAIL: upload.onerror") } | 90 xhr.upload.onerror = function() { log("FAIL: upload.onerror"); }; |
| 91 xhr.onload = function() { log("onload"); }; |
| 79 xhr.onerror = function() { | 92 xhr.onerror = function() { |
| 80 log("onerror (expected)"); | 93 log("onerror (expected)"); |
| 81 log("Response length: " + xhr.responseText.length); | 94 log("Response length: " + xhr.responseText.length); |
| 82 test3(); | 95 test3(); |
| 83 } | 96 }; |
| 84 xhr.onload = function() { | |
| 85 log("onload"); | |
| 86 } | |
| 87 } | 97 } |
| 88 | 98 |
| 89 function test3() | 99 function test3() |
| 90 { | 100 { |
| 91 sawProgress = false; | 101 sawProgress = false; |
| 92 sawUploadProgress = false; | 102 sawUploadProgress = false; |
| 93 | 103 |
| 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."); | 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."); |
| 95 | 105 |
| 96 var xhr = new XMLHttpRequest(); | 106 var xhr = new XMLHttpRequest(); |
| 97 xhr.onprogress = progress; | 107 xhr.onprogress = progress; |
| 98 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi", true); | 108 xhr.open("POST", "http://localhost:8000/xmlhttprequest/resources/cross-site-
progress-events.cgi", true); |
| 99 xhr.setRequestHeader("Content-Type", "text/plain"); | 109 xhr.setRequestHeader("Content-Type", "text/plain"); |
| 100 xhr.upload.onloadstart = function() { log("upload.onloadstart") } | 110 xhr.upload.onloadstart = function() { log("upload.onloadstart"); }; |
| 101 xhr.send(stringToSend); | 111 xhr.send(stringToSend); |
| 102 xhr.upload.onprogress = uploadProgress; | 112 xhr.upload.onprogress = allowedUploadProgress; |
| 103 xhr.upload.onload = function() { log("FAIL: upload.onload") } | 113 xhr.upload.onload = function() { log("FAIL: upload.onload"); }; |
| 104 xhr.upload.onerror = function() { | 114 xhr.upload.onerror = function() { log("upload.onerror (expected)"); }; |
| 105 log("upload.onerror (expected)") | 115 xhr.onload = function() { log("onload"); } |
| 106 } | |
| 107 xhr.onerror = function() { | 116 xhr.onerror = function() { |
| 108 log("onerror (expected)"); | 117 log("onerror (expected)"); |
| 109 log("Response length: " + xhr.responseText.length); | 118 log("Response length: " + xhr.responseText.length); |
| 110 if (window.testRunner) | 119 if (window.testRunner) |
| 111 testRunner.notifyDone(); | 120 testRunner.notifyDone(); |
| 112 } | 121 }; |
| 113 xhr.onload = function() { | |
| 114 log("onload"); | |
| 115 } | |
| 116 } | 122 } |
| 117 | 123 |
| 118 test1(); | 124 test1(); |
| 119 </script> | 125 </script> |
| 120 </body> | 126 </body> |
| 121 </html> | 127 </html> |
| OLD | NEW |