Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Unified Diff: content/browser/background_sync/background_sync_service_impl_unittest.cc

Issue 1316743002: Reland of [Background Sync] Allow sync manager access from uncontrolled clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/background_sync/background_sync_service_impl_unittest.cc
diff --git a/content/browser/background_sync/background_sync_service_impl_unittest.cc b/content/browser/background_sync/background_sync_service_impl_unittest.cc
index 5e177503d4ee938f9d0b59355319a939fb5eb2d1..93b0d396204bee96bee308c80a254fe7e8c14563 100644
--- a/content/browser/background_sync/background_sync_service_impl_unittest.cc
+++ b/content/browser/background_sync/background_sync_service_impl_unittest.cc
@@ -180,7 +180,17 @@ class BackgroundSyncServiceImplTest : public testing::Test {
void RegisterOneShot(
SyncRegistrationPtr sync,
const BackgroundSyncService::RegisterCallback& callback) {
- service_impl_->Register(sync.Pass(), sw_registration_id_, callback);
+ service_impl_->Register(sync.Pass(), sw_registration_id_,
+ true /* requested_from_service_worker */, callback);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void RegisterOneShotFromDocument(
+ SyncRegistrationPtr sync,
+ const BackgroundSyncService::RegisterCallback& callback) {
+ service_impl_->Register(sync.Pass(), sw_registration_id_,
+ false /* requested_from_service_worker */,
+ callback);
base::RunLoop().RunUntilIdle();
}
@@ -249,6 +259,31 @@ TEST_F(BackgroundSyncServiceImplTest, RegisterWithoutWindow) {
EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NOT_ALLOWED, error);
}
+TEST_F(BackgroundSyncServiceImplTest, RegisterFromControlledClient) {
+ bool called = false;
+ BackgroundSyncError error;
+ SyncRegistrationPtr reg;
+ RegisterOneShotFromDocument(
+ default_sync_registration_.Clone(),
+ base::Bind(&ErrorAndRegistrationCallback, &called, &error, &reg));
+ EXPECT_TRUE(called);
+ EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE, error);
+ EXPECT_EQ("", reg->tag);
+}
+
+TEST_F(BackgroundSyncServiceImplTest, RegisterFromUncontrolledClient) {
+ bool called = false;
+ BackgroundSyncError error;
+ SyncRegistrationPtr reg;
+ RemoveWindowClient();
+ RegisterOneShotFromDocument(
+ default_sync_registration_.Clone(),
+ base::Bind(&ErrorAndRegistrationCallback, &called, &error, &reg));
+ EXPECT_TRUE(called);
+ EXPECT_EQ(BackgroundSyncError::BACKGROUND_SYNC_ERROR_NONE, error);
+ EXPECT_EQ("", reg->tag);
+}
+
TEST_F(BackgroundSyncServiceImplTest, Unregister) {
bool unregister_called = false;
BackgroundSyncError unregister_error;

Powered by Google App Engine
This is Rietveld 408576698