blob: 24ae30ed7b343e7117411237250462efb5fbea54 [file] [log] [blame]
<!doctype html>
<meta charset="utf-8">
<title>Background Sync API: Verifies that the one-shot sync API works
correctly.</title>
<script src="../resources/permissions-helper.js"></script>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script>
promise_test(function(t) {
var url = 'resources/empty_worker.js';
var scope = 'resources/scope/background_sync/oneshot.html';
var sync_manager;
var sync_registration;
// This test verifies that registration of one-shots fails from an iframe.
return PermissionsHelper.setPermission('background-sync', 'granted')
.then(function() {
return service_worker_unregister_and_register(t, url, scope);
})
.then(function(sw_registration_page) {
return wait_for_state(t, sw_registration_page.installing, 'activated');
})
.then(function() {
return with_iframe(scope)
})
.then(function(frame) {
var w = frame.contentWindow;
return w.navigator.serviceWorker.getRegistration(scope);
})
.then(function(sw_registration_frame) {
sync_manager = sw_registration_frame.sync;
return sync_manager.getTags();
})
.then(function(tags) {
assert_equals(tags.length, 0, 'One-shot syncs should be ' +
'cleared at the start of the test.');
return sync_manager.register('iframe-oneshot');
})
.then(function() {
return service_worker_unregister(t, scope);
});
}, 'Background Sync API should allow one-shot syncs to be registered ' +
'from an iframe');
promise_test(function(t) {
var url = 'resources/empty_worker.js';
var scope = 'resources/scope/background_sync/oneshot-uncontrolled.html';
var sync_manager;
var sync_registration;
// This test verifies that one-shot syncs can be registered from uncontrolled
// documents.
return PermissionsHelper.setPermission('background-sync', 'granted')
.then(function() {
return service_worker_unregister_and_register(t, url, scope);
})
.then(function(sw_registration) {
sync_manager = sw_registration.sync;
return wait_for_state(t, sw_registration.installing, 'activated');
})
.then(function() { return sync_manager.getTags(); })
.then(function(tags) {
assert_equals(tags.length, 0, 'One-shot syncs should be ' +
'cleared at the start of the test.');
return sync_manager.register('abcde');
})
.then(function() {
return service_worker_unregister(t, scope);
})
}, 'Background Sync API should allow one-shot syncs to be registered ' +
'from an uncontrolled main-frame document');
</script>