Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / fetch-request-resources.html
blob1bb7a0745492f4284558ddbde1d5be58e1cdc7da
1 <!DOCTYPE html>
2 <title>Service Worker: FetchEvent for resources</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?pipe=sub"></script>
7 <script>
8 var url_count = 0;
9 var expected_results = {};
11 function image_test(frame, url, cross_origin,
12 expected_mode, expected_credentials) {
13 var actual_url = url + (++url_count);
14 expected_results[actual_url] = {
15 cross_origin: cross_origin,
16 mode: expected_mode,
17 credentials: expected_credentials,
18 redirect: 'follow',
19 message: 'Image load (url:' +
20 actual_url + ' cross_origin:' + cross_origin + ')'
22 return frame.contentWindow.load_image(actual_url, cross_origin);
25 function script_test(frame, url, cross_origin,
26 expected_mode, expected_credentials) {
27 var actual_url = url + (++url_count);
28 expected_results[actual_url] = {
29 cross_origin: cross_origin,
30 mode: expected_mode,
31 credentials: expected_credentials,
32 redirect: 'follow',
33 message: 'Script load (url:' +
34 actual_url + ' cross_origin:' + cross_origin + ')'
36 return frame.contentWindow.load_script(actual_url, cross_origin);
39 function css_test(frame, url, cross_origin,
40 expected_mode, expected_credentials) {
41 var actual_url = url + (++url_count);
42 expected_results[actual_url] = {
43 cross_origin: cross_origin,
44 mode: expected_mode,
45 credentials: expected_credentials,
46 redirect: 'follow',
47 message: 'CSS load (url:' +
48 actual_url + ' cross_origin:' + cross_origin + ')'
50 return frame.contentWindow.load_css(actual_url, cross_origin);
53 function font_face_test(frame, url, expected_mode,
54 expected_credentials) {
55 var actual_url = url + (++url_count);
56 expected_results[actual_url] = {
57 url: actual_url,
58 mode: expected_mode,
59 credentials: expected_credentials,
60 redirect: 'follow',
61 message: 'FontFace load (url:' + actual_url + ')'
63 return frame.contentWindow.load_font(actual_url);
66 function css_image_test(frame, url, type,
67 expected_mode, expected_credentials) {
68 var actual_url = url + (++url_count);
69 expected_results[actual_url] = {
70 url: actual_url,
71 mode: expected_mode,
72 credentials: expected_credentials,
73 redirect: 'follow',
74 message: 'CSSImage load (url:' + actual_url + ' type:' + type + ')'
76 return frame.contentWindow.load_css_image(actual_url, type);
79 function css_image_set_test(frame, url, type,
80 expected_mode, expected_credentials) {
81 var actual_url = url + (++url_count);
82 expected_results[actual_url] = {
83 url: actual_url,
84 mode: expected_mode,
85 credentials: expected_credentials,
86 redirect: 'follow',
87 message: 'CSSImageSet load (url:' + actual_url + ' type:' + type + ')'
89 return frame.contentWindow.load_css_image_set(actual_url, type);
92 async_test(function(t) {
93 var SCOPE = 'resources/fetch-request-resources-iframe.html';
94 var SCRIPT = 'resources/fetch-request-resources-worker.js';
95 var host_info = get_host_info();
96 var LOCAL_URL =
97 host_info['HTTP_ORIGIN'] + base_path() + 'resources/dummy?test';
98 var REMOTE_URL =
99 host_info['HTTP_REMOTE_ORIGIN'] + base_path() + 'resources/dummy?test';
100 var worker;
101 var frame;
102 service_worker_unregister_and_register(t, SCRIPT, SCOPE)
103 .then(function(registration) {
104 worker = registration.installing;
105 return wait_for_state(t, worker, 'activated');
107 .then(function() {
108 return new Promise(function(resolve) {
109 var channel = new MessageChannel();
110 channel.port1.onmessage = t.step_func(function(msg) {
111 if (msg.data.ready) {
112 resolve();
113 return;
115 var result = msg.data;
116 var expected = expected_results[result.url];
117 if (!expected) {
118 return;
120 assert_equals(
121 result.mode, expected.mode,
122 'mode of ' + expected.message + ' must be ' +
123 expected.mode + '.');
124 assert_equals(
125 result.credentials, expected.credentials,
126 'credentials of ' + expected.message + ' must be ' +
127 expected.credentials + '.');
128 assert_equals(
129 result.redirect, expected.redirect,
130 'redirect mode of ' + expected.message + ' must be ' +
131 expected.redirect + '.');
132 --url_count;
133 delete expected_results[result.url];
134 if (url_count == 0) {
135 frame.remove();
136 service_worker_unregister_and_done(t, SCOPE);
139 worker.postMessage(
140 {port: channel.port2}, [channel.port2]);
143 .then(function() { return with_iframe(SCOPE); })
144 .then(function(f) {
145 frame = f;
146 image_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
147 image_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
148 image_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
149 image_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
150 image_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
151 image_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
153 script_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
154 script_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
155 script_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
156 script_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
157 script_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
158 script_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
160 css_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
161 css_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
162 css_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
163 css_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
164 css_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
165 css_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
167 font_face_test(f, LOCAL_URL, 'cors', 'include');
168 font_face_test(f, REMOTE_URL, 'cors', 'omit');
170 css_image_test(f, LOCAL_URL, 'backgroundImage',
171 'no-cors', 'same-origin');
172 css_image_test(f, REMOTE_URL, 'backgroundImage',
173 'no-cors', 'same-origin');
174 css_image_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'omit');
175 css_image_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'omit');
177 css_image_set_test(f, LOCAL_URL, 'backgroundImage',
178 'no-cors', 'same-origin');
179 css_image_set_test(f, REMOTE_URL, 'backgroundImage',
180 'no-cors', 'same-origin');
181 css_image_set_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'omit');
182 css_image_set_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'omit');
185 .catch(unreached_rejection(t));
186 }, 'Verify FetchEvent for resources.');
187 </script>