diff options
author | iclelland <iclelland@chromium.org> | 2015-11-17 04:49:19 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-17 12:50:08 +0000 |
commit | 449769316764e3922e50920bb62b186221301e47 (patch) | |
tree | f08ae24793215100914ca779621f6739306c7e68 | |
parent | 1ca86a9617476825ed3f4d65006dc69645a159ad (diff) | |
download | chromium_src-449769316764e3922e50920bb62b186221301e47.zip chromium_src-449769316764e3922e50920bb62b186221301e47.tar.gz chromium_src-449769316764e3922e50920bb62b186221301e47.tar.bz2 |
[Background Sync] Align exposed API with spec
This is the second of a series of commits to align the exposed
BackgroundSync API with the spec at https://wicg.github.io/BackgroundSync/spec/
Part 1: Removing Exposed Periodic Sync: https://crrev.com/1436723002/
BUG=552029
Review URL: https://codereview.chromium.org/1437883002
Cr-Commit-Position: refs/heads/master@{#360068}
21 files changed, 70 insertions, 429 deletions
diff --git a/content/browser/background_sync/background_sync_browsertest.cc b/content/browser/background_sync/background_sync_browsertest.cc index e3f8dc0..6e30cc5 100644 --- a/content/browser/background_sync/background_sync_browsertest.cc +++ b/content/browser/background_sync/background_sync_browsertest.cc @@ -182,8 +182,6 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { bool RegisterServiceWorker(); bool RegisterOneShot(const std::string& tag); bool RegisterOneShotFromServiceWorker(const std::string& tag); - bool UnregisterOneShot(const std::string& tag); - bool UnregisterOneShotTwice(const std::string& tag); bool GetRegistrationOneShot(const std::string& tag); bool GetRegistrationOneShotFromServiceWorker(const std::string& tag); bool MatchRegistrations(const std::string& script_result, @@ -193,9 +191,6 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { const std::vector<std::string>& expected_tags); bool CompleteDelayedOneShot(); bool RejectDelayedOneShot(); - bool NotifyWhenFinishedOneShot(const std::string& tag); - bool NotifyWhenFinishedImmediateOneShot(const std::string& expected_msg); - bool StoreRegistrationOneShot(const std::string& tag); private: scoped_ptr<net::EmbeddedTestServer> https_server_; @@ -323,21 +318,6 @@ bool BackgroundSyncBrowserTest::RegisterOneShotFromServiceWorker( return script_result == BuildExpectedResult(tag, "register sent to SW"); } -bool BackgroundSyncBrowserTest::UnregisterOneShot(const std::string& tag) { - std::string script_result; - EXPECT_TRUE( - RunScript(BuildScriptString("unregisterOneShot", tag), &script_result)); - return script_result == BuildExpectedResult(tag, "unregistered"); -} - -bool BackgroundSyncBrowserTest::UnregisterOneShotTwice(const std::string& tag) { - std::string script_result; - EXPECT_TRUE(RunScript(BuildScriptString("unregisterOneShotTwice", tag), - &script_result)); - return script_result == - BuildExpectedResult(tag, "failed to unregister twice"); -} - bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) { std::string script_result; EXPECT_TRUE(RunScript(BuildScriptString("getRegistrationOneShot", tag), @@ -400,30 +380,6 @@ bool BackgroundSyncBrowserTest::RejectDelayedOneShot() { return script_result == BuildExpectedResult("delay", "rejecting"); } -bool BackgroundSyncBrowserTest::NotifyWhenFinishedOneShot( - const std::string& tag) { - EXPECT_TRUE(content::ExecuteScript( - shell_->web_contents(), - BuildScriptString("notifyWhenFinishedOneShot", tag))); - return PopConsole(BuildExpectedResult(tag, "finished")); -} - -bool BackgroundSyncBrowserTest::NotifyWhenFinishedImmediateOneShot( - const std::string& expected_msg) { - std::string script_result; - EXPECT_TRUE( - RunScript("notifyWhenFinishedImmediateOneShot()", &script_result)); - return script_result == expected_msg; -} - -bool BackgroundSyncBrowserTest::StoreRegistrationOneShot( - const std::string& tag) { - std::string script_result; - EXPECT_TRUE( - RunScript(BuildScriptString("storeRegistration", tag), &script_result)); - return script_result == BuildExpectedResult(tag, "stored"); -} - IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFires) { EXPECT_TRUE(RegisterServiceWorker()); EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. @@ -477,8 +433,6 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { EXPECT_TRUE(PopConsole("ok - delay completed")); // Verify that it finished firing. - // TODO(jkarlin): Use registration.finished to verify that the event actually - // completed successfully. EXPECT_FALSE(GetRegistrationOneShot("delay")); } @@ -586,108 +540,6 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw")); } -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(false); - EXPECT_TRUE(RegisterOneShot("foo")); - EXPECT_TRUE(UnregisterOneShot("foo")); - EXPECT_FALSE(GetRegistrationOneShot("foo")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterTwice) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(false); - EXPECT_TRUE(RegisterOneShot("foo")); - EXPECT_TRUE(UnregisterOneShotTwice("foo")); - EXPECT_FALSE(GetRegistrationOneShot("foo")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, UnregisterMidSync) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - EXPECT_TRUE(RegisterOneShot("unregister")); - EXPECT_TRUE(PopConsole("ok - unregister completed")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, - CallFinishedBeforeSyncSucceeds) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(false); - EXPECT_TRUE(RegisterOneShot("foo")); - EXPECT_TRUE(NotifyWhenFinishedOneShot("foo")); - - SetOnline(true); - // The ordering of PopConsole messages tells us that the event fired - // before finished resolved. - EXPECT_TRUE(PopConsole("foo fired")); - EXPECT_TRUE(PopConsole("foo finished result: true")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedBeforeSyncFails) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(true); - EXPECT_TRUE(RegisterOneShot("delay")); - EXPECT_FALSE(OneShotPending("delay")); - EXPECT_TRUE(NotifyWhenFinishedOneShot("delay")); - - EXPECT_TRUE(RejectDelayedOneShot()); - // The ordering of PopConsole messages tells us that the event fired - // before finished resolved. - EXPECT_TRUE(PopConsole("ok - delay rejected")); - EXPECT_TRUE(PopConsole("delay finished result: false")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, - CallFinishedAfterSyncSucceeds) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(false); - EXPECT_TRUE(RegisterOneShot("foo")); - EXPECT_TRUE(StoreRegistrationOneShot("foo")); - - SetOnline(true); - EXPECT_TRUE(PopConsole("foo fired")); - EXPECT_FALSE(GetRegistrationOneShot("foo")); - EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: true")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, - CallFinishedAfterSyncUnregistered) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(false); - EXPECT_TRUE(RegisterOneShot("foo")); - EXPECT_TRUE(StoreRegistrationOneShot("foo")); - EXPECT_TRUE(UnregisterOneShot("foo")); - EXPECT_FALSE(GetRegistrationOneShot("foo")); - EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - foo result: false")); -} - -IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, CallFinishedAfterSyncFails) { - EXPECT_TRUE(RegisterServiceWorker()); - EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. - - SetOnline(true); - EXPECT_TRUE(RegisterOneShot("delay")); - EXPECT_FALSE(OneShotPending("delay")); - EXPECT_TRUE(StoreRegistrationOneShot("delay")); - - EXPECT_TRUE(RejectDelayedOneShot()); - EXPECT_TRUE(PopConsole("ok - delay rejected")); - EXPECT_TRUE(NotifyWhenFinishedImmediateOneShot("ok - delay result: false")); -} - // Verify that a background sync registration is deleted when site data is // cleared. IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, diff --git a/content/test/data/background_sync/background_sync_test_helpers.js b/content/test/data/background_sync/background_sync_test_helpers.js index b4cd8b6..7900526 100644 --- a/content/test/data/background_sync/background_sync_test_helpers.js +++ b/content/test/data/background_sync/background_sync_test_helpers.js @@ -5,7 +5,6 @@ 'use strict'; var resultQueue = new ResultQueue(); -var registrationReference = null; // Sends data back to the test. This must be in response to an earlier // request, but it's ok to respond asynchronously. The request blocks until @@ -35,9 +34,9 @@ function registerServiceWorker() { function registerOneShot(tag) { navigator.serviceWorker.ready .then(function(swRegistration) { - return swRegistration.sync.register({'tag': tag}); + return swRegistration.sync.register(tag); }) - .then(function(syncRegistration) { + .then(function() { sendResultToTest('ok - ' + tag + ' registered'); }) .catch(sendErrorToTest); @@ -52,56 +51,18 @@ function registerOneShotFromServiceWorker(tag) { .catch(sendErrorToTest); } -function unregisterOneShot(tag) { - navigator.serviceWorker.ready - .then(function(swRegistration) { - return swRegistration.sync.getRegistration(tag); - }) - .then(function(syncRegistration) { - if (!syncRegistration) { - sendResultToTest('error - ' + tag + ' not found'); - return; - } - return syncRegistration.unregister(); - }) - .then(function() { - sendResultToTest('ok - ' + tag + ' unregistered'); - }) - .catch(sendErrorToTest); -} - -function unregisterOneShotTwice(tag) { - navigator.serviceWorker.ready - .then(function(swRegistration) { - return swRegistration.sync.getRegistration(tag); - }) - .then(function(syncRegistration) { - if (!syncRegistration) { - sendResultToTest('error - ' + tag + ' not found'); - return; - } - return syncRegistration.unregister(); - }) - .then(function() { - return syncRegistration.unregister(); - }) - .then(sendErrorToTest, function() { - sendResultToTest('ok - ' + tag + ' failed to unregister twice'); - }) - .catch(sendErrorToTest); -} - function getRegistrationOneShot(tag) { navigator.serviceWorker.ready .then(function(swRegistration) { - return swRegistration.sync.getRegistration(tag); + return swRegistration.sync.getTags(); }) - .then(function(syncRegistration) { - if (!syncRegistration) { + .then(function(tags) { + if (tags.indexOf(tag) >= 0) { + sendResultToTest('ok - ' + tag + ' found'); + } else { sendResultToTest('error - ' + tag + ' not found'); return; } - sendResultToTest('ok - ' + tag + ' found'); }) .catch(sendErrorToTest); } @@ -119,12 +80,9 @@ function getRegistrationOneShotFromServiceWorker(tag) { function getRegistrationsOneShot(tag) { navigator.serviceWorker.ready .then(function(swRegistration) { - return swRegistration.sync.getRegistrations(); + return swRegistration.sync.getTags(); }) - .then(function(syncRegistrations) { - var tags = syncRegistrations.map(function(syncRegistration) { - return syncRegistration.tag; - }); + .then(function(tags) { sendResultToTest('ok - ' + tags.toString()); }) .catch(sendErrorToTest); @@ -157,44 +115,6 @@ function rejectDelayedOneShot() { .catch(sendErrorToTest); } -function notifyWhenFinishedOneShot(tag) { - navigator.serviceWorker.ready - .then(function(swRegistration) { - swRegistration.active.postMessage( - {action: 'notifyWhenFinished', tag: tag}); - }) - .catch(sendErrorToTest); -} - -function notifyWhenFinishedImmediateOneShot(tag) { - if (registrationReference == null) { - sendResultToTest('error - must call storeRegistration first'); - return; - } - - registrationReference.finished - .then(function(success) { - sendResultToTest('ok - ' + registrationReference.tag + - ' result: true') - }, function(err) { - sendResultToTest('ok - ' + registrationReference.tag + - ' result: false') - }) - .catch(sendErrorToTest) -} - - -function storeRegistration(tag) { - navigator.serviceWorker.ready - .then(function(swRegistration) { - return swRegistration.sync.getRegistration(tag); - }) - .then(function(syncRegistration) { - registrationReference = syncRegistration; - sendResultToTest('ok - ' + tag + ' stored'); - }) - .catch(sendErrorToTest); -} // Queue storing asynchronous results received from the Service Worker. Results // are sent to the test when requested. diff --git a/content/test/data/background_sync/service_worker.js b/content/test/data/background_sync/service_worker.js index 6fedae8..e04bf30 100644 --- a/content/test/data/background_sync/service_worker.js +++ b/content/test/data/background_sync/service_worker.js @@ -9,7 +9,6 @@ // "delay" - Delays finishing the sync event with event.waitUntil. // Send a postMessage of "completeDelayedOneShot" to finish the // event. -// "unregister" - Unregisters the sync registration from within the sync event. 'use strict'; @@ -38,25 +37,10 @@ this.onmessage = function(event) { sendMessageToClients('sync', 'ok - delay rejected'); } - if (event.data['action'] === 'notifyWhenFinished') { - var tag = event.data['tag']; - registration.sync.getRegistration(tag) - .then(function (syncRegistration) { - sendMessageToClients('sync', 'ok - ' + tag + ' finished'); - return syncRegistration.finished; - }) - .then(function() { - sendMessageToClients('sync', tag + " finished result: true"); - }, function(error) { - sendMessageToClients('sync', tag + " finished result: false"); - }) - .catch(sendSyncErrorToClients); - } - if (event.data['action'] === 'registerOneShot') { var tag = event.data['tag']; - registration.sync.register({'tag': tag}) - .then(function (syncRegistration) { + registration.sync.register(tag) + .then(function () { sendMessageToClients('register', 'ok - ' + tag + ' registered in SW'); }) .catch(sendSyncErrorToClients); @@ -64,23 +48,21 @@ this.onmessage = function(event) { if (event.data['action'] === 'getRegistrationOneShot') { var tag = event.data['tag']; - registration.sync.getRegistration(tag) - .then(function(syncRegistration) { - if (!syncRegistration) { + registration.sync.getTags(tag) + .then(function(tags) { + if (tags.indexOf(tag) >= 0) { + sendMessageToClients('register', 'ok - ' + tag + ' found'); + } else { sendMessageToClients('register', 'error - ' + tag + ' not found'); return; } - sendMessageToClients('register', 'ok - ' + tag + ' found'); }) .catch(sendSyncErrorToClients); } if (event.data['action'] === 'getRegistrationsOneShot') { - registration.sync.getRegistrations() - .then(function(syncRegistrations) { - var tags = syncRegistrations.map(function(syncRegistration) { - return syncRegistration.tag; - }); + registration.sync.getTags() + .then(function(tags) { sendMessageToClients('register', 'ok - ' + tags.toString()); }) .catch(sendSyncErrorToClients); @@ -103,17 +85,12 @@ this.onsync = function(event) { sendMessageToClients('sync', 'error - wrong wait until type'); } - if (event.registration === undefined) { - sendMessageToClients('sync', 'error - event missing registration'); - return; - } - - if (event.registration.tag === undefined) { + if (event.tag === undefined) { sendMessageToClients('sync', 'error - registration missing tag'); return; } - var tag = event.registration.tag; + var tag = event.tag; if (tag === 'delay') { var syncPromise = new Promise(function(resolve, reject) { @@ -124,14 +101,6 @@ this.onsync = function(event) { return; } - if (tag === 'unregister') { - event.waitUntil(event.registration.unregister() - .then(function() { - sendMessageToClients('sync', 'ok - unregister completed'); - })); - return; - } - sendMessageToClients('sync', tag + ' fired'); }; diff --git a/third_party/WebKit/LayoutTests/http/tests/background_sync/interfaces.html b/third_party/WebKit/LayoutTests/http/tests/background_sync/interfaces.html index c5d4e1b2..d183f40 100644 --- a/third_party/WebKit/LayoutTests/http/tests/background_sync/interfaces.html +++ b/third_party/WebKit/LayoutTests/http/tests/background_sync/interfaces.html @@ -18,23 +18,9 @@ assert_own_property(self, 'SyncManager', 'SyncManager needs to be exposed as a global.'); assert_own_property(SyncManager.prototype, 'register'); - assert_own_property(SyncManager.prototype, 'getRegistration'); - assert_own_property(SyncManager.prototype, 'getRegistrations'); - assert_own_property(SyncManager.prototype, 'permissionState'); + assert_own_property(SyncManager.prototype, 'getTags'); }, 'SyncManager should be exposed and have the expected interface in a Document.'); - - test(function() { - assert_own_property(self, 'SyncRegistration', 'SyncRegistration needs to be exposed as a global.'); - - // FIXME: Assert existence of the attributes when they are properly - // exposed in the prototype chain. https://crbug.com/43394 - - assert_own_property(SyncRegistration.prototype, 'finished'); - assert_own_property(SyncRegistration.prototype, 'unregister'); - assert_own_property(SyncRegistration.prototype, 'tag'); - - }, 'SyncRegistration should be exposed and have the expected interface in a Document.'); </script> </body> </html> diff --git a/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot-register-failure-worker-not-activated.html b/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot-register-failure-worker-not-activated.html index 7768008..9b35a5e 100644 --- a/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot-register-failure-worker-not-activated.html +++ b/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot-register-failure-worker-not-activated.html @@ -17,7 +17,7 @@ async_test(function(test) { swRegistration = serviceWorkerRegistration; assert_not_equals(swRegistration.installing, null, 'The worker should be installing'); assert_equals(swRegistration.active, null, 'The worker should not be active yet'); - return swRegistration.sync.register(); + return swRegistration.sync.register('abcde'); }) .then(function(syncRegistration) { assert_unreached('sync.register() must not succeed without an active service worker'); diff --git a/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot.html b/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot.html index 87663fa..e2090b9 100644 --- a/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot.html +++ b/third_party/WebKit/LayoutTests/http/tests/background_sync/oneshot.html @@ -6,7 +6,6 @@ <script src="../resources/testharness-helpers.js"></script> <script src="../resources/testharnessreport.js"></script> <script src="../serviceworker/resources/test-helpers.js"></script> -<script src="resources/test-helpers.js"></script> <script> promise_test(function(t) { @@ -15,9 +14,9 @@ promise_test(function(t) { var sync_manager; var sync_registration; - // One-shot syncs can only be registered from a controlled document. This - // test creates a frame, after the service worker is active, in order to use - // its service worker registration. + // This test verifies that one-shot syncs can be registered from service- + // worker-controlled documents. It creates a frame, after the service worker + // is active, in order to use its service worker registration. return service_worker_unregister_and_register(t, url, scope) .then(function(sw_registration_page) { return wait_for_state(t, sw_registration_page.installing, 'activated'); @@ -31,21 +30,14 @@ promise_test(function(t) { }) .then(function(sw_registration_frame) { sync_manager = sw_registration_frame.sync; - return clear_registered_syncs(sync_manager); + return sync_manager.getTags(); }) - .then(function() { return sync_manager.getRegistrations(); }) - .then(function(registrations) { - assert_equals(registrations.length, 0, 'One-shot syncs should be ' + + .then(function(tags) { + assert_equals(tags.length, 0, 'One-shot syncs should be ' + 'cleared at the start of the test.'); - return sync_manager.register({tag: 'abcde'}); + return sync_manager.register('abcde'); }) - .then(function(registration) { - sync_registration = registration; - assert_class_string(sync_registration, 'SyncRegistration', 'One-' + - 'shot sync registrations should have the correct ' + - 'class name.'); - assert_equals('abcde', registration.tag, 'Sync registration tag ' + - 'returned should match the tag registered.'); + .then(function() { return service_worker_unregister(t, scope); }); }, 'Background Sync API should allow one-shot syncs to be registered from ' + @@ -57,31 +49,22 @@ promise_test(function(t) { var sync_manager; var sync_registration; - // One-shot syncs can also be registered from uncontrolled documents. This - // test creates a frame, after the service worker is active, in order to use - // its service worker registration. + // This test verifies that one-shot syncs can be registered from uncontrolled + // documents. 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 clear_registered_syncs(sync_manager); }) - .then(function() { return sync_manager.getRegistrations(); }) - .then(function(registrations) { - assert_equals(registrations.length, 0, 'One-shot syncs should be ' + + .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({tag: 'abcde'}); + return sync_manager.register('abcde'); }) - .then(function(registration) { - sync_registration = registration; - assert_class_string(sync_registration, 'SyncRegistration', 'One-' + - 'shot sync registrations should have the correct ' + - 'class name.'); - assert_equals('abcde', registration.tag, 'Sync registration tag ' + - 'returned should match the tag registered.'); + .then(function() { return service_worker_unregister(t, scope); }) - .then(function() { return service_worker_unregister(t, scope); }) }, 'Background Sync API should allow one-shot syncs to be registered ' + 'with window clients not currently controlled by service worker'); </script> diff --git a/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/interfaces-worker.js b/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/interfaces-worker.js index c638025..0df2dca 100644 --- a/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/interfaces-worker.js +++ b/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/interfaces-worker.js @@ -6,27 +6,14 @@ test(function() { assert_idl_attribute(registration, 'sync', 'One-shot SyncManager needs to be exposed on the registration.'); assert_inherits(registration.sync, 'register'); - assert_inherits(registration.sync, 'getRegistration'); - assert_inherits(registration.sync, 'getRegistrations'); - assert_inherits(registration.sync, 'permissionState'); + assert_inherits(registration.sync, 'getTags'); }, 'SyncManager should be exposed and have the expected interface.'); test(function() { - assert_own_property(self, 'SyncRegistration', 'SyncRegistration needs to be exposed as a global.'); - - // FIXME: Assert existence of the attributes when they are properly - // exposed in the prototype chain. https://crbug.com/43394 - assert_own_property(SyncRegistration.prototype, 'finished'); - assert_own_property(SyncRegistration.prototype, 'unregister'); - assert_own_property(SyncRegistration.prototype, 'tag'); - -}, 'SyncRegistration should be exposed and have the expected interface.'); - -test(function() { assert_own_property(self, 'SyncEvent'); - assert_will_be_idl_attribute(SyncEvent.prototype, 'registration'); + assert_will_be_idl_attribute(SyncEvent.prototype, 'tag'); // SyncEvent should be extending ExtendableEvent. assert_inherits(SyncEvent.prototype, 'waitUntil'); diff --git a/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/test-helpers.js b/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/test-helpers.js deleted file mode 100644 index da0b7e9..0000000 --- a/third_party/WebKit/LayoutTests/http/tests/background_sync/resources/test-helpers.js +++ /dev/null @@ -1,13 +0,0 @@ -// Returns a promise which resolves when all registrations have been cleared -// from the given background sync manager. -function clear_registered_syncs(sync_manager) { - return sync_manager.getRegistrations().then(function(registrations) { - return Promise.all( - registrations.map(registration => registration.unregister())); - }); -} - -// Clears all background sync registrations from the sync manager. -function clear_all_syncs(serviceworker_registration) { - return clear_registered_syncs(serviceworker_registration.sync); -} diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/webexposed/global-interface-listing-service-worker-expected.txt b/third_party/WebKit/LayoutTests/http/tests/serviceworker/webexposed/global-interface-listing-service-worker-expected.txt index bf66956..f6ff90d 100644 --- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/webexposed/global-interface-listing-service-worker-expected.txt +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/webexposed/global-interface-listing-service-worker-expected.txt @@ -587,19 +587,12 @@ interface SubtleCrypto method wrapKey interface SyncEvent : ExtendableEvent getter lastChance - getter registration + getter tag method constructor interface SyncManager method constructor - method getRegistration - method getRegistrations - method permissionState + method getTags method register -interface SyncRegistration - getter finished - getter tag - method constructor - method unregister interface TextDecoder getter encoding getter fatal diff --git a/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt b/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt index f468c4a..1f0a02b 100644 --- a/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt +++ b/third_party/WebKit/LayoutTests/webexposed/global-interface-listing-expected.txt @@ -5160,15 +5160,8 @@ interface SubtleCrypto method wrapKey interface SyncManager method constructor - method getRegistration - method getRegistrations - method permissionState + method getTags method register -interface SyncRegistration - getter finished - getter tag - method constructor - method unregister interface Text : CharacterData getter wholeText method constructor diff --git a/third_party/WebKit/Source/core/frame/UseCounter.h b/third_party/WebKit/Source/core/frame/UseCounter.h index afc2599..895bda7 100644 --- a/third_party/WebKit/Source/core/frame/UseCounter.h +++ b/third_party/WebKit/Source/core/frame/UseCounter.h @@ -884,6 +884,7 @@ public: CSSFilterContrast = 1022, CSSFilterBlur = 1023, CSSFilterDropShadow = 1024, + BackgroundSyncRegister = 1025, // Add new features immediately above this line. Don't change assigned // numbers of any item, and don't reuse removed slots. diff --git a/third_party/WebKit/Source/modules/background_sync/SyncCallbacks.cpp b/third_party/WebKit/Source/modules/background_sync/SyncCallbacks.cpp index c0cd78e..9f31ab1 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncCallbacks.cpp +++ b/third_party/WebKit/Source/modules/background_sync/SyncCallbacks.cpp @@ -120,20 +120,14 @@ SyncGetRegistrationsCallbacks::~SyncGetRegistrationsCallbacks() void SyncGetRegistrationsCallbacks::onSuccess(const WebVector<WebSyncRegistration*>& webSyncRegistrations) { - Vector<OwnPtr<WebSyncRegistration>> registrations; - for (WebSyncRegistration* r : webSyncRegistrations) { - registrations.append(adoptPtr(r)); - } if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) { return; } - - HeapVector<Member<SyncRegistration>> syncRegistrations; - for (auto& r : registrations) { - SyncRegistration* reg = SyncRegistration::take(m_resolver.get(), r.release(), m_serviceWorkerRegistration); - syncRegistrations.append(reg); + Vector<String> tags; + for (const WebSyncRegistration* r : webSyncRegistrations) { + tags.append(r->tag); } - m_resolver->resolve(syncRegistrations); + m_resolver->resolve(tags); } void SyncGetRegistrationsCallbacks::onError(const WebSyncError& error) diff --git a/third_party/WebKit/Source/modules/background_sync/SyncEvent.cpp b/third_party/WebKit/Source/modules/background_sync/SyncEvent.cpp index b109a11..c4f7906 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncEvent.cpp +++ b/third_party/WebKit/Source/modules/background_sync/SyncEvent.cpp @@ -11,9 +11,9 @@ SyncEvent::SyncEvent() { } -SyncEvent::SyncEvent(const AtomicString& type, SyncRegistration* syncRegistration, bool lastChance, WaitUntilObserver* observer) +SyncEvent::SyncEvent(const AtomicString& type, const String& tag, bool lastChance, WaitUntilObserver* observer) : ExtendableEvent(type, ExtendableEventInit(), observer) - , m_syncRegistration(syncRegistration) + , m_tag(tag) , m_lastChance(lastChance) { } @@ -21,7 +21,7 @@ SyncEvent::SyncEvent(const AtomicString& type, SyncRegistration* syncRegistratio SyncEvent::SyncEvent(const AtomicString& type, const SyncEventInit& init) : ExtendableEvent(type, init) { - m_syncRegistration = init.registration(); + m_tag = init.tag(); m_lastChance = init.lastChance(); } @@ -34,9 +34,9 @@ const AtomicString& SyncEvent::interfaceName() const return EventNames::SyncEvent; } -SyncRegistration* SyncEvent::registration() +String SyncEvent::tag() { - return m_syncRegistration.get(); + return m_tag; } bool SyncEvent::lastChance() @@ -46,7 +46,6 @@ bool SyncEvent::lastChance() DEFINE_TRACE(SyncEvent) { - visitor->trace(m_syncRegistration); ExtendableEvent::trace(visitor); } diff --git a/third_party/WebKit/Source/modules/background_sync/SyncEvent.h b/third_party/WebKit/Source/modules/background_sync/SyncEvent.h index d5b8665..5b969a5 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncEvent.h +++ b/third_party/WebKit/Source/modules/background_sync/SyncEvent.h @@ -22,9 +22,9 @@ public: { return adoptRefWillBeNoop(new SyncEvent); } - static PassRefPtrWillBeRawPtr<SyncEvent> create(const AtomicString& type, SyncRegistration* syncRegistration, bool lastChance, WaitUntilObserver* observer) + static PassRefPtrWillBeRawPtr<SyncEvent> create(const AtomicString& type, const String& tag, bool lastChance, WaitUntilObserver* observer) { - return adoptRefWillBeNoop(new SyncEvent(type, syncRegistration, lastChance, observer)); + return adoptRefWillBeNoop(new SyncEvent(type, tag, lastChance, observer)); } static PassRefPtrWillBeRawPtr<SyncEvent> create(const AtomicString& type, const SyncEventInit& init) { @@ -35,17 +35,17 @@ public: const AtomicString& interfaceName() const override; - SyncRegistration* registration(); + String tag(); bool lastChance(); DECLARE_VIRTUAL_TRACE(); private: SyncEvent(); - SyncEvent(const AtomicString& type, SyncRegistration*, bool, WaitUntilObserver*); + SyncEvent(const AtomicString& type, const String&, bool, WaitUntilObserver*); SyncEvent(const AtomicString& type, const SyncEventInit&); - PersistentWillBeMember<SyncRegistration> m_syncRegistration; + String m_tag; bool m_lastChance; }; diff --git a/third_party/WebKit/Source/modules/background_sync/SyncEvent.idl b/third_party/WebKit/Source/modules/background_sync/SyncEvent.idl index f828e49..f663de05 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncEvent.idl +++ b/third_party/WebKit/Source/modules/background_sync/SyncEvent.idl @@ -7,6 +7,6 @@ Exposed=ServiceWorker, RuntimeEnabled=BackgroundSync, ] interface SyncEvent : ExtendableEvent { - readonly attribute SyncRegistration registration; + readonly attribute DOMString tag; readonly attribute boolean lastChance; }; diff --git a/third_party/WebKit/Source/modules/background_sync/SyncEventInit.idl b/third_party/WebKit/Source/modules/background_sync/SyncEventInit.idl index df44f64..1a2a804 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncEventInit.idl +++ b/third_party/WebKit/Source/modules/background_sync/SyncEventInit.idl @@ -3,6 +3,6 @@ // found in the LICENSE file. dictionary SyncEventInit : ExtendableEventInit { - required SyncRegistration registration; - required boolean lastChance; + required DOMString tag; + boolean lastChance = false; }; diff --git a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp index dae56c1ee..4593672 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp +++ b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp @@ -40,7 +40,7 @@ SyncManager::SyncManager(ServiceWorkerRegistration* registration) ASSERT(registration); } -ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionContext* context, const SyncRegistrationOptions& options) +ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionContext* context, const String& tag) { // TODO(jkarlin): Wait for the registration to become active instead of rejecting. See crbug.com/542437. if (!m_registration->active()) @@ -52,7 +52,7 @@ ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, WebSyncRegistration::PeriodicityOneShot, - options.tag(), + tag, 0 /* minPeriod */, WebSyncRegistration::NetworkStateOnline /* networkState */, WebSyncRegistration::PowerStateAuto /* powerState */ @@ -62,17 +62,7 @@ ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC return promise; } -ScriptPromise SyncManager::getRegistration(ScriptState* scriptState, const String& syncRegistrationId) -{ - ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); - ScriptPromise promise = resolver->promise(); - - backgroundSyncProvider()->getRegistration(WebSyncRegistration::PeriodicityOneShot, syncRegistrationId, m_registration->webRegistration(), new SyncRegistrationCallbacks(resolver, m_registration)); - - return promise; -} - -ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) +ScriptPromise SyncManager::getTags(ScriptState* scriptState) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); @@ -82,16 +72,6 @@ ScriptPromise SyncManager::getRegistrations(ScriptState* scriptState) return promise; } -ScriptPromise SyncManager::permissionState(ScriptState* scriptState) -{ - ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); - ScriptPromise promise = resolver->promise(); - - backgroundSyncProvider()->getPermissionStatus(WebSyncRegistration::PeriodicityOneShot, m_registration->webRegistration(), new SyncGetPermissionStatusCallbacks(resolver, m_registration)); - - return promise; -} - DEFINE_TRACE(SyncManager) { visitor->trace(m_registration); diff --git a/third_party/WebKit/Source/modules/background_sync/SyncManager.h b/third_party/WebKit/Source/modules/background_sync/SyncManager.h index 8690788..2529574 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncManager.h +++ b/third_party/WebKit/Source/modules/background_sync/SyncManager.h @@ -27,10 +27,8 @@ public: unsigned long minAllowablePeriod(); - ScriptPromise registerFunction(ScriptState*, ExecutionContext*, const SyncRegistrationOptions&); - ScriptPromise getRegistration(ScriptState*, const String&); - ScriptPromise getRegistrations(ScriptState*); - ScriptPromise permissionState(ScriptState*); + ScriptPromise registerFunction(ScriptState*, ExecutionContext*, const String&); + ScriptPromise getTags(ScriptState*); DECLARE_TRACE(); diff --git a/third_party/WebKit/Source/modules/background_sync/SyncManager.idl b/third_party/WebKit/Source/modules/background_sync/SyncManager.idl index 30f3ada..de186a1 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncManager.idl +++ b/third_party/WebKit/Source/modules/background_sync/SyncManager.idl @@ -14,8 +14,6 @@ enum SyncPermissionState { RuntimeEnabled=BackgroundSync, TypeChecking=Interface, ] interface SyncManager { - [CallWith=(ScriptState,ExecutionContext),ImplementedAs=registerFunction] Promise<SyncRegistration> register([RuntimeEnabled=BackgroundSyncV2] optional SyncRegistrationOptions options); - [CallWith=ScriptState] Promise<SyncRegistration> getRegistration(DOMString tag); - [CallWith=ScriptState] Promise<sequence<SyncRegistration>> getRegistrations(); - [RuntimeEnabled=BackgroundSyncV2, CallWith=ScriptState] Promise<SyncPermissionState> permissionState(); + [MeasureAs=BackgroundSyncRegister,CallWith=(ScriptState,ExecutionContext),ImplementedAs=registerFunction] Promise<void> register(DOMString tag); + [CallWith=ScriptState] Promise<sequence<DOMString>> getTags(); }; diff --git a/third_party/WebKit/Source/modules/background_sync/SyncRegistration.idl b/third_party/WebKit/Source/modules/background_sync/SyncRegistration.idl index add356e..ccc69db 100644 --- a/third_party/WebKit/Source/modules/background_sync/SyncRegistration.idl +++ b/third_party/WebKit/Source/modules/background_sync/SyncRegistration.idl @@ -3,8 +3,8 @@ // found in the LICENSE file. [ - Exposed=(Window,ServiceWorker), GarbageCollected, + NoInterfaceObject, RuntimeEnabled=BackgroundSync, ] interface SyncRegistration { readonly attribute DOMString tag; diff --git a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp index 3a311b1..fbf8875 100644 --- a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp +++ b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeProxy.cpp @@ -61,6 +61,7 @@ #include "modules/serviceworkers/WaitUntilObserver.h" #include "platform/RuntimeEnabledFeatures.h" #include "public/platform/WebCrossOriginServiceWorkerClient.h" +#include "public/platform/modules/background_sync/WebSyncRegistration.h" #include "public/platform/modules/notifications/WebNotificationData.h" #include "public/platform/modules/serviceworker/WebServiceWorkerEventResult.h" #include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h" @@ -177,7 +178,7 @@ void ServiceWorkerGlobalScopeProxy::dispatchSyncEvent(int eventID, const WebSync return; } WaitUntilObserver* observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Sync, eventID); - RefPtrWillBeRawPtr<Event> event(SyncEvent::create(EventTypeNames::sync, SyncRegistration::create(registration, m_workerGlobalScope->registration()), lastChance == IsLastChance, observer)); + RefPtrWillBeRawPtr<Event> event(SyncEvent::create(EventTypeNames::sync, registration.tag, lastChance == IsLastChance, observer)); m_workerGlobalScope->dispatchExtendableEvent(event.release(), observer); } |