3 function fetch_url(url
) {
4 return new Promise(function(resolve
, reject
) {
5 var request
= new XMLHttpRequest();
6 request
.addEventListener('load', function(event
) {
9 request
.addEventListener('error', function(event
) {
12 request
.open('GET', url
);
17 function make_test(testcase
) {
18 var name
= testcase
.name
;
19 return fetch_url(window
.location
.href
+ '?' + name
)
22 if (testcase
.expect_load
)
23 return Promise
.resolve();
24 return Promise
.reject(new Error(
25 name
+ ': expected network error but loaded'));
28 if (!testcase
.expect_load
)
29 return Promise
.resolve();
30 return Promise
.reject(new Error(
31 name
+ ': expected to load but got network error'));
35 function run_tests() {
37 { name
: 'response-object', expect_load
: true },
38 { name
: 'response-promise-object', expect_load
: true },
39 { name
: 'other-value', expect_load
: false },
44 window
.parent
.notify_test_done('PASS');
46 .catch(function(error
) {
47 window
.parent
.notify_test_done('FAIL: ' + error
.message
);
51 if (!navigator
.serviceWorker
.controller
)
52 window
.parent
.notify_done('FAIL: no controller');