OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>getCost succeeds from a Service Worker</title> | 4 <title>getCost succeeds from a Service Worker</title> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
7 <script src="../serviceworker/resources/test-helpers.js"></script> | 7 <script src="../serviceworker/resources/test-helpers.js"></script> |
8 <script src="../notifications/resources/test-helpers.js"></script> | 8 <script src="../notifications/resources/test-helpers.js"></script> |
9 <script src="/js-test-resources/mojo-helpers.js"></script> | 9 <script src="/js-test-resources/mojo-helpers.js"></script> |
10 <script src="budget-service-mock.js"></script> | 10 <script src="budget-service-mock.js"></script> |
11 </head> | 11 </head> |
12 <body> | 12 <body> |
13 <script> | 13 <script> |
14 async_test(function(test) { | 14 promise_test(function(test) { |
15 var script = 'resources/instrumentation-service-worker.js'; | 15 const script = 'resources/instrumentation-service-worker.js'; |
16 var scope = 'resources/scope/' + location.pathname; | 16 const scope = 'resources/scope/' + location.pathname; |
17 var port; | 17 let port; |
18 | 18 |
19 budgetServiceMock.then(mock => { | 19 return budgetServiceMock.then(mock => { |
20 mock.setCost("silent-push", TEST_BUDGET_COST); | 20 mock.setCost("silent-push", TEST_BUDGET_COST); |
21 getActiveServiceWorkerWithMessagePort(test, script, scope) | 21 return getActiveServiceWorkerWithMessagePort(test, script, scope); |
22 .then(function(workerInfo) { | 22 }).then(function(workerInfo) { |
23 port = workerInfo.port; | 23 port = workerInfo.port; |
24 port.postMessage({ command: 'getCost' }); | |
25 | 24 |
26 port.addEventListener('message', function(event) { | 25 port.addEventListener('message', function(event) { |
27 if (typeof event.data != 'object' || !event.data.command) | 26 if (typeof event.data != 'object' || !event.data.command) |
28 assert_unreached('Invalid message from the service worker'); | 27 assert_unreached('Invalid message from the service worker'); |
29 | 28 |
30 assert_equals(event.data.command, 'getCost'); | 29 assert_equals(event.data.command, 'getCost'); |
31 assert_true(event.data.success, | 30 assert_true(event.data.success, |
32 'getCost should succeed. Error message: ' + event.data.error
Message); | 31 'getCost should succeed. Error message: ' + event.data.errorMess
age); |
33 assert_equals(event.data.cost, TEST_BUDGET_COST); | 32 assert_equals(event.data.cost, TEST_BUDGET_COST); |
34 test.done(); | 33 }); |
35 }); | 34 |
36 }) | 35 return sendCommand(port, { command: 'getCost' }); |
37 .catch(unreached_rejection(test)); | |
38 }); | 36 }); |
39 }, 'getCost should succeed from Service Worker'); | 37 }, 'getCost should succeed from Service Worker'); |
40 </script> | 38 </script> |
41 </body> | 39 </body> |
42 </html> | 40 </html> |
OLD | NEW |