Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / fetch-event-respond-with-argument-iframe.html
blob33b47e78a349dfda70f9dc9a230a34152305640c
1 <!DOCTYPE html>
2 <script>
3 function fetch_url(url) {
4 return new Promise(function(resolve, reject) {
5 var request = new XMLHttpRequest();
6 request.addEventListener('load', function(event) {
7 resolve();
8 });
9 request.addEventListener('error', function(event) {
10 reject();
11 });
12 request.open('GET', url);
13 request.send();
14 });
17 function make_test(testcase) {
18 var name = testcase.name;
19 return fetch_url(window.location.href + '?' + name)
20 .then(
21 function() {
22 if (testcase.expect_load)
23 return Promise.resolve();
24 return Promise.reject(new Error(
25 name + ': expected network error but loaded'));
27 function() {
28 if (!testcase.expect_load)
29 return Promise.resolve();
30 return Promise.reject(new Error(
31 name + ': expected to load but got network error'));
32 });
35 function run_tests() {
36 var tests = [
37 { name: 'response-object', expect_load: true },
38 { name: 'response-promise-object', expect_load: true },
39 { name: 'other-value', expect_load: false },
40 ].map(make_test);
42 Promise.all(tests)
43 .then(function() {
44 window.parent.notify_test_done('PASS');
46 .catch(function(error) {
47 window.parent.notify_test_done('FAIL: ' + error.message);
48 });
51 if (!navigator.serviceWorker.controller)
52 window.parent.notify_done('FAIL: no controller');
53 else
54 run_tests();
55 </script>