OLD | NEW |
1 <title>Mixed range responses must be handled as an error.</title> | 1 <title>Mixed range responses must be handled as an error.</title> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/get-host-info.js"></script> | 4 <script src="../resources/get-host-info.js"></script> |
5 <script src="../../media-resources/media-file.js"></script> | 5 <script src="../../media-resources/media-file.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 // This file tests the following behavior: | 8 // This file tests the following behavior: |
9 // 1. The audio element sends the first request. | 9 // 1. The audio element sends the first request. |
10 // 2. mixed-range-response.php returns the first 3 bytes ("Ogg"). | 10 // 2. mixed-range-response.php returns the first 3 bytes ("Ogg"). |
11 // 3. The element sends the second request with "Range: bytes=3-" header. | 11 // 3. The element sends the second request with "Range: bytes=3-" header. |
12 // 4. mixed-range-response.php returns 206 response. | 12 // 4. mixed-range-response.php returns 206 response. |
13 // 5. The element sends the third request to load-video.php. | 13 // 5. The element sends the third request to load-video.php. |
14 // 6. load-video.php returns the audio file from the fourth byte. | 14 // 6. load-video.php returns the audio file from the fourth byte. |
15 // | 15 // |
16 // If the origin of 2. (mixed-range-response.php) and 6. (load-video.php) are | 16 // If the origin of 2. (mixed-range-response.php) and 6. (load-video.php) are |
17 // different, an error should occur. | 17 // different, an error should occur. |
18 | 18 |
19 function create_failure_audio_test(url) { | 19 function create_failure_audio_test(url, crossOrigin) { |
20 return new Promise(function(resolve, reject) { | 20 return new Promise(function(resolve, reject) { |
21 var audio = document.createElement('audio'); | 21 var audio = document.createElement('audio'); |
| 22 if (crossOrigin) |
| 23 audio.crossOrigin = crossOrigin; |
22 audio.oncanplay = function() { | 24 audio.oncanplay = function() { |
23 reject('canplay event should not be fired. url: ' + url); | 25 reject('canplay event should not be fired. url: ' + url); |
24 }; | 26 }; |
25 audio.onerror = resolve; | 27 audio.onerror = resolve; |
26 audio.src = url; | 28 audio.src = url; |
27 document.body.appendChild(audio); | 29 document.body.appendChild(audio); |
28 }); | 30 }); |
29 } | 31 } |
30 | 32 |
31 function create_success_audio_test(url) { | 33 function create_success_audio_test(url, crossOrigin) { |
32 return new Promise(function(resolve, reject) { | 34 return new Promise(function(resolve, reject) { |
33 var audio = document.createElement('audio'); | 35 var audio = document.createElement('audio'); |
| 36 if (crossOrigin) |
| 37 audio.crossOrigin = crossOrigin; |
34 audio.oncanplay = resolve; | 38 audio.oncanplay = resolve; |
35 audio.onerror = function(e) { | 39 audio.onerror = function(e) { |
36 reject('error event should not be fired. url: ' + url); | 40 reject('error event should not be fired. url: ' + url); |
37 }; | 41 }; |
38 audio.src = url; | 42 audio.src = url; |
39 document.body.appendChild(audio); | 43 document.body.appendChild(audio); |
40 }); | 44 }); |
41 } | 45 } |
42 | 46 |
43 var HOST_INFO = get_host_info(); | 47 var HOST_INFO = get_host_info(); |
44 var MIX_RESPONSE_PHP_PATH = '/media/resources/mixed-range-response.php'; | 48 var MIX_RESPONSE_PHP_PATH = '/media/resources/mixed-range-response.php'; |
| 49 var REDIRECT_PHP_PATH = '/resources/redirect.php' |
45 var AUDIO_PATH = '/media/resources/load-video.php?' + | 50 var AUDIO_PATH = '/media/resources/load-video.php?' + |
46 'name=../../../../media/content/silence.oga&type=audio/ogg'; | 51 'name=../../../../media/content/silence.oga&type=audio/ogg'; |
47 | 52 |
48 promise_test(function(t) { | 53 promise_test(function(t) { |
| 54 return create_success_audio_test( |
| 55 HOST_INFO['HTTP_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 56 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH)); |
| 57 }, 'Redirect from same-origin to same-origin must succeed.'); |
| 58 |
| 59 promise_test(function(t) { |
| 60 return create_success_audio_test( |
| 61 HOST_INFO['HTTP_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 62 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH)); |
| 63 }, 'Redirect from same-origin to remote-origin must succeed.'); |
| 64 |
| 65 promise_test(function(t) { |
| 66 return create_failure_audio_test( |
| 67 HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH , |
| 68 'anonymous'); |
| 69 }, 'CORS-disallowed remote-origin with crossOrigin=anonymous must fail.'); |
| 70 |
| 71 |
| 72 promise_test(function(t) { |
| 73 return create_success_audio_test( |
| 74 HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + '&cors_allow_origin=' + H
OST_INFO['HTTP_ORIGIN'], |
| 75 'anonymous'); |
| 76 }, 'CORS-allowed remote-origin with crossOrigin=anonymous must succeed.'); |
| 77 |
| 78 promise_test(function(t) { |
| 79 return create_success_audio_test( |
| 80 HOST_INFO['HTTP_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 81 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH), |
| 82 'anonymous'); |
| 83 }, 'Redirect from same-origin to same-origin with crossOrigin=anonymous must
succeed.'); |
| 84 |
| 85 promise_test(function(t) { |
| 86 return create_failure_audio_test( |
| 87 HOST_INFO['HTTP_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 88 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH), |
| 89 'anonymous'); |
| 90 }, 'Redirect from same-origin to CORS-disallowed remote-origin with crossOrigi
n=anonymous must fail.'); |
| 91 |
| 92 promise_test(function(t) { |
| 93 return create_success_audio_test( |
| 94 HOST_INFO['HTTP_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 95 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + |
| 96 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN']), |
| 97 'anonymous'); |
| 98 }, 'Redirect from same-origin to CORS-allowed remote-origin with crossOrigin=a
nonymous must succeed.'); |
| 99 |
| 100 promise_test(function(t) { |
| 101 return create_failure_audio_test( |
| 102 HOST_INFO['HTTP_REMOTE_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 103 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + |
| 104 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN']), |
| 105 'anonymous'); |
| 106 }, 'Redirect from CORS-disallowed remote-origin to CORS-allowed remote-origin
with crossOrigin=anonymous must fail.'); |
| 107 |
| 108 promise_test(function(t) { |
| 109 return create_success_audio_test( |
| 110 HOST_INFO['HTTP_REMOTE_ORIGIN'] + REDIRECT_PHP_PATH + '?url=' + |
| 111 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + |
| 112 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN']) + |
| 113 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN'], |
| 114 'anonymous'); |
| 115 }, 'Redirect from CORS-allowed remote-origin to CORS-allowed remote-origin wit
h crossOrigin=anonymous must succeed.'); |
| 116 |
| 117 promise_test(function(t) { |
49 return create_success_audio_test( | 118 return create_success_audio_test( |
50 HOST_INFO['HTTP_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + | 119 HOST_INFO['HTTP_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
51 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH)); | 120 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH)); |
52 }, 'Mixing same-origin responses must succeed.'); | 121 }, 'Mixing same-origin responses must succeed.'); |
53 | 122 |
54 promise_test(function(t) { | 123 promise_test(function(t) { |
55 return create_failure_audio_test( | 124 return create_failure_audio_test( |
56 HOST_INFO['HTTP_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + | 125 HOST_INFO['HTTP_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
57 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH)); | 126 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH)); |
58 }, 'Mixing same-origin response and remote-origin response must fail.'); | 127 }, 'Mixing same-origin response and remote-origin response must fail.'); |
59 | 128 |
60 promise_test(function(t) { | 129 promise_test(function(t) { |
61 return create_failure_audio_test( | 130 return create_failure_audio_test( |
62 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + | 131 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
63 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH)); | 132 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH)); |
64 }, 'Mixing remote-origin response and same-origin response must fail.'); | 133 }, 'Mixing remote-origin response and same-origin response must fail.'); |
65 | 134 |
66 promise_test(function(t) { | 135 promise_test(function(t) { |
67 return create_success_audio_test( | 136 return create_success_audio_test( |
68 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + | 137 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
69 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH)); | 138 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH)); |
70 }, 'Mixing same remote-origin responses must succeed.'); | 139 }, 'Mixing same remote-origin responses must succeed.'); |
71 | 140 |
| 141 promise_test(function(t) { |
| 142 return create_success_audio_test( |
| 143 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
| 144 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + |
| 145 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN']) + |
| 146 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN'], |
| 147 'anonymous'); |
| 148 }, 'Mixing same CORS-allowed remote-origin responses with crossOrigin=anonymou
s must succeed.'); |
| 149 |
| 150 promise_test(function(t) { |
| 151 return create_success_audio_test( |
| 152 HOST_INFO['HTTP_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
| 153 encodeURIComponent(HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH + |
| 154 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN']), |
| 155 'anonymous'); |
| 156 }, 'Mixing same-origin response and CORS-allowed remote-origin response with c
rossOrigin=anonymous must succeed.'); |
| 157 |
| 158 promise_test(function(t) { |
| 159 return create_success_audio_test( |
| 160 HOST_INFO['HTTP_REMOTE_ORIGIN'] + MIX_RESPONSE_PHP_PATH + '?location=' + |
| 161 encodeURIComponent(HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH + '&cors_allow_
origin=*') + |
| 162 '&cors_allow_origin=' + HOST_INFO['HTTP_ORIGIN'], |
| 163 'anonymous'); |
| 164 }, 'Mixing CORS-allowed remote-origin response and same-origin response with c
rossOrigin=anonymous must succeed.'); |
72 </script> | 165 </script> |
73 </body> | 166 </body> |
OLD | NEW |