2 <title>Service Worker: Fetch for the frame loading.
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharnessreport.js"></script>
5 <script src=
"../resources/get-host-info.js"></script>
6 <script src=
"resources/test-helpers.js"></script>
9 var worker
= 'resources/fetch-rewrite-worker.js';
10 var path
= base_path() + 'resources/fetch-access-control.php';
11 var host_info
= get_host_info();
13 if (window
.testRunner
) {
14 testRunner
.setCanOpenWindows();
17 async_test(function(t
) {
18 var scope
= 'resources/fetch-frame-resource/frame-basic';
19 service_worker_unregister_and_register(t
, worker
, scope
)
21 return wait_for_state(t
, reg
.installing
, 'activated');
26 encodeURIComponent(host_info
['HTTP_ORIGIN'] + path
));
28 .then(function(frame
) {
30 frame
.contentDocument
.body
.textContent
.substr(0, 7),
32 'Basic type response could be loaded in the iframe.');
34 return service_worker_unregister_and_done(t
, scope
);
36 .catch(unreached_rejection(t
));
37 }, 'Basic type response could be loaded in the iframe.');
39 async_test(function(t
) {
40 var scope
= 'resources/fetch-frame-resource/frame-cors';
41 service_worker_unregister_and_register(t
, worker
, scope
)
43 return wait_for_state(t
, reg
.installing
, 'activated');
47 scope
+ '?mode=cors&url=' +
48 encodeURIComponent(host_info
['HTTP_REMOTE_ORIGIN'] + path
+
49 '?ACAOrigin=' + host_info
['HTTP_ORIGIN']));
51 .then(function(frame
) {
53 frame
.contentDocument
.body
.textContent
.substr(0, 7),
55 'CORS type response could be loaded in the iframe.');
57 return service_worker_unregister_and_done(t
, scope
);
59 .catch(unreached_rejection(t
));
60 }, 'CORS type response could be loaded in the iframe.');
62 async_test(function(t
) {
63 var scope
= 'resources/fetch-frame-resource/frame-opaque';
64 service_worker_unregister_and_register(t
, worker
, scope
)
66 return wait_for_state(t
, reg
.installing
, 'activated');
69 var frame
= document
.createElement('iframe');
71 scope
+ '?mode=no-cors&url=' +
72 encodeURIComponent(host_info
['HTTP_REMOTE_ORIGIN'] + path
);
73 document
.body
.appendChild(frame
);
74 // We can't catch the network error on iframe. So we use the timer.
75 return new Promise(function(resolve
) {
76 setTimeout(function() { resolve(frame
); }, 1000);
79 .then(function(frame
) {
81 frame
.contentDocument
.body
.textContent
,
83 'Opaque type response could not be loaded in the iframe.');
85 return service_worker_unregister_and_done(t
, scope
);
87 .catch(unreached_rejection(t
));
88 }, 'Opaque type response could not be loaded in the iframe.');
90 async_test(function(t
) {
91 var scope
= 'resources/fetch-frame-resource/window-basic';
92 service_worker_unregister_and_register(t
, worker
, scope
)
94 return wait_for_state(t
, reg
.installing
, 'activated');
97 return new Promise(function(resolve
) {
98 var win
= window
.open(
100 encodeURIComponent(host_info
['HTTP_ORIGIN'] + path
));
101 win
.onload = function() { resolve(win
); };
104 .then(function(win
) {
106 win
.document
.body
.textContent
.substr(0, 7),
108 'Basic type response could be loaded in the new window.');
110 return service_worker_unregister_and_done(t
, scope
);
112 .catch(unreached_rejection(t
));
113 }, 'Basic type response could be loaded in the new window.');
115 async_test(function(t
) {
116 var scope
= 'resources/fetch-frame-resource/window-cors';
117 service_worker_unregister_and_register(t
, worker
, scope
)
118 .then(function(reg
) {
119 return wait_for_state(t
, reg
.installing
, 'activated');
122 return new Promise(function(resolve
) {
123 var win
= window
.open(
124 scope
+ '?mode=cors&url=' +
125 encodeURIComponent(host_info
['HTTP_REMOTE_ORIGIN'] + path
+
126 '?ACAOrigin=' + host_info
['HTTP_ORIGIN']));
127 win
.onload = function() { resolve(win
); };
130 .then(function(win
) {
132 win
.document
.body
.textContent
.substr(0, 7),
134 'CORS type response could be loaded in the new window.');
136 return service_worker_unregister_and_done(t
, scope
);
138 .catch(unreached_rejection(t
));
139 }, 'CORS type response could be loaded in the new window.');
141 async_test(function(t
) {
142 var scope
= 'resources/fetch-frame-resource/window-opaque';
143 service_worker_unregister_and_register(t
, worker
, scope
)
144 .then(function(reg
) {
145 return wait_for_state(t
, reg
.installing
, 'activated');
148 var win
= window
.open(
149 scope
+ '?mode=no-cors&url=' +
150 encodeURIComponent(host_info
['HTTP_REMOTE_ORIGIN'] + path
));
151 // We can't catch the network error on window. So we use the timer.
152 return new Promise(function(resolve
) {
153 setTimeout(function() { resolve(win
); }, 1000);
156 .then(function(win
) {
158 win
.document
.body
.textContent
,
160 'Opaque type response could not be loaded in the new window.');
162 return service_worker_unregister_and_done(t
, scope
);
164 .catch(unreached_rejection(t
));
165 }, 'Opaque type response could not be loaded in the new window.');