| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>getCost succeeds from a Service Worker</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="../serviceworker/resources/test-helpers.js"></script> |
| <script src="../notifications/resources/test-helpers.js"></script> |
| </head> |
| <body> |
| <script> |
| const TEST_BUDGET_COST = 1.2; |
| |
| promise_test(async function(test) { |
| const script = 'resources/instrumentation-service-worker.js'; |
| const scope = 'resources/scope/' + location.pathname; |
| |
| let workerInfo = |
| await getActiveServiceWorkerWithMessagePort(test, script, scope); |
| let port = workerInfo.port; |
| |
| let data = await sendCommand(port, { |
| command: 'mockSetCost', |
| operation: 'silent-push', |
| cost: TEST_BUDGET_COST |
| }); |
| assert_equals(data.command, 'mockSetCost'); |
| assert_true(data.success); |
| |
| data = await sendCommand(port, { command: 'getCost' }); |
| assert_equals(data.command, 'getCost'); |
| assert_true(data.success, |
| 'getCost should succeed. Error message: ' + data.errorMessage); |
| assert_equals(data.cost, TEST_BUDGET_COST); |
| }, 'getCost should succeed from Service Worker'); |
| </script> |
| </body> |
| </html> |