OLD | NEW |
1 // OPTIONS: -base-https | 1 // OPTIONS: -base-https |
2 if (self.importScripts) { | 2 if (self.importScripts) { |
3 importScripts('../resources/fetch-test-helpers.js'); | 3 importScripts('../resources/fetch-test-helpers.js'); |
4 } | 4 } |
5 | 5 |
6 var BASE_URL = | 6 var BASE_URL = |
7 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control.php?ACAOri
gin=*&label='; | 7 'http://127.0.0.1:8000/serviceworker/resources/fetch-access-control.php?ACAOri
gin=*&label='; |
8 var HTTPS_BASE_URL = | 8 var HTTPS_BASE_URL = |
9 'https://127.0.0.1:8443/serviceworker/resources/fetch-access-control.php?ACAOr
igin=*&label='; | 9 'https://127.0.0.1:8443/serviceworker/resources/fetch-access-control.php?ACAOr
igin=*&label='; |
10 var HTTPS_OTHER_BASE_URL = | 10 var HTTPS_OTHER_BASE_URL = |
11 'https://localhost:8443/serviceworker/resources/fetch-access-control.php?ACAOr
igin=*&label='; | 11 'https://localhost:8443/serviceworker/resources/fetch-access-control.php?ACAOr
igin=*&label='; |
12 | 12 |
13 var REDIRECT_URL = | 13 var REDIRECT_URL = |
14 'http://127.0.0.1:8000/serviceworker/resources/redirect.php?ACAOrigin=*&Redire
ct='; | 14 'http://127.0.0.1:8000/serviceworker/resources/redirect.php?ACAOrigin=*&Redire
ct='; |
15 var HTTPS_REDIRECT_URL = | 15 var HTTPS_REDIRECT_URL = |
16 'https://127.0.0.1:8443/serviceworker/resources/redirect.php?ACAOrigin=*&Redir
ect='; | 16 'https://127.0.0.1:8443/serviceworker/resources/redirect.php?ACAOrigin=*&Redir
ect='; |
17 var HTTPS_OTHER_REDIRECT_URL = | 17 var HTTPS_OTHER_REDIRECT_URL = |
18 'https://localhost:8443/serviceworker/resources/redirect.php?ACAOrigin=*&Redir
ect='; | 18 'https://localhost:8443/serviceworker/resources/redirect.php?ACAOrigin=*&Redir
ect='; |
19 | 19 |
20 ['same-origin', 'cors', 'no-cors'].forEach(function(mode) { | 20 testBlockMixedContent('same-origin'); |
21 promise_test(function(t) { | 21 testBlockMixedContent('cors'); |
22 return Promise.resolve() | |
23 .then(function() { | |
24 // Test 1: Must fail: blocked as mixed content. | |
25 return fetch(BASE_URL + 'test1-' + mode, {mode: mode}) | |
26 .then(t.unreached_func('Test 1: Must be blocked (' + | |
27 mode + ', HTTPS->HTTP)'), | |
28 function() {}); | |
29 }) | |
30 .then(function() { | |
31 // Block mixed content in redirects. | |
32 // Test 2: Must fail: original fetch is not blocked but | |
33 // redirect is blocked. | |
34 return fetch(HTTPS_REDIRECT_URL + | |
35 encodeURIComponent(BASE_URL + 'test2-' + mode), | |
36 {mode: mode}) | |
37 .then(t.unreached_func('Test 2: Must be blocked (' + | |
38 mode + ', HTTPS->HTTPS->HTTP)'), | |
39 function() {}); | |
40 }) | |
41 .then(function() { | |
42 // Test 3: Must fail: original fetch is blocked. | |
43 return fetch(REDIRECT_URL + | |
44 encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode), | |
45 {mode: mode}) | |
46 .then(t.unreached_func('Test 3: Must be blocked (' + | |
47 mode + ', HTTPS->HTTP->HTTPS)'), | |
48 function() {}); | |
49 }) | |
50 .then(function() { | |
51 // Test 4: Must success. | |
52 // Test that the mixed contents above are not rejected due to | |
53 return fetch(HTTPS_REDIRECT_URL + | |
54 encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode), | |
55 {mode: mode}) | |
56 .then(function(res) {assert_equals(res.status, 200); }, | |
57 t.unreached_func('Test 4: Must success (' + | |
58 mode + ', HTTPS->HTTPS->HTTPS)')); | |
59 }) | |
60 .then(function() { | |
61 // Test 5: Must success if mode is not 'same-origin'. | |
62 // Test that the mixed contents above are not rejected due to | |
63 // CORS check. | |
64 return fetch(HTTPS_OTHER_REDIRECT_URL + | |
65 encodeURIComponent(HTTPS_BASE_URL + 'test5-' + mode), | |
66 {mode: mode}) | |
67 .then(function(res) { | |
68 if (mode === 'same-origin') { | |
69 assert_unreached( | |
70 'Test 5: Cross-origin HTTPS request must fail: ' + | |
71 'mode = ' + mode); | |
72 } | |
73 }, | |
74 function() { | |
75 if (mode !== 'same-origin') { | |
76 assert_unreached( | |
77 'Test 5: Cross-origin HTTPS request must success: ' + | |
78 'mode = ' + mode); | |
79 } | |
80 }); | |
81 }); | |
82 }, 'Block fetch() as mixed content (' + mode + ')'); | |
83 }); | |
84 | 22 |
85 done(); | 23 done(); |
OLD | NEW |