1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>CORS status</title>
<meta name=help href=http://dvcs.w3.org/hg/cors/raw-file/tip/Overview.html#cross-origin-request-with-preflight-0>
<meta name=author title="Odin Hørthe Omdal" href="mailto:odiho@opera.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js?pipe=sub"></script>
<h1>The returned status code in different scenarios</h1>
<script>
var counter = 0
function testit(allow, preflight, response, status) {
async_test(
(++counter) + '. ' +
(allow ? 'CORS allowed' : 'CORS disallowed') +
(preflight ? ', preflight status '+preflight : '') +
(response ? ', response status '+response : '') +
'.'
).step(function() {
var client = new XMLHttpRequest()
client.open('GET', CROSSDOMAIN + 'resources/cors-makeheader.py?' + counter +
(allow ? '&headers=x-custom': '&origin=none') +
(response ? '&code='+response : '') +
(preflight ? '&preflight='+preflight : '')
)
if (preflight)
client.setRequestHeader('X-Custom', 'preflight')
client.onload = this.step_func(function() {
if (!status)
assert_unreached("load event")
/* Allow spurious error events to fire */
setTimeout(this.step_func(function() {
assert_equals(client.status, status, "status")
this.done()
}), 10)
})
client.onerror = this.step_func(function() {
if (status)
assert_unreached("error event")
assert_equals(client.readyState, client.DONE, 'readyState')
assert_equals(client.status, 0, 'status')
this.done()
})
client.send()
})
}
/* allow pref resp status */
testit(false, null, 400, 0)
testit(false, 200, null, 0)
testit(true, null, 400, 400)
testit(true, 200, 400, 400)
testit(true, 400, null, 0)
</script>
<pre>
allowed preflight response | status |
------- --------- -------- | ------ |
1 no x 400 | 0 |
2 no 200 x | 0 |
3 yes x 400 | 400 |
4 yes 200 400 | 400 |
5 yes 400 x | 0 |
</pre>
<div id=log></div>
|