blob: 757eff4815a84af6b475fd769f0e911f4993b352 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>getBudget 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_AT = 2;
const TEST_BUDGET_TIME = new Date().getTime();
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: 'mockAddBudget',
budgetAt: TEST_BUDGET_AT,
time: TEST_BUDGET_TIME
});
assert_equals(data.command, 'mockAddBudget');
assert_true(data.success);
data = await sendCommand(port, { command: 'getBudget' });
assert_equals(data.command, 'getBudget');
assert_true(data.success,
'getBudget should succeed. Error message: ' + data.errorMessage);
assert_equals(data.budgetAt, TEST_BUDGET_AT);
assert_equals(data.time, TEST_BUDGET_TIME);
}, 'getBudget should succeed from Service Worker');
</script>
</body>
</html>