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

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

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android fix 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_browsertest.cc
diff --git a/content/browser/background_sync/background_sync_browsertest.cc b/content/browser/background_sync/background_sync_browsertest.cc
index ed09304eec3b7945a35caab0870f42f201623020..e5daaf8341ca34ea55e5943f3125b385db4f2aaa 100644
--- a/content/browser/background_sync/background_sync_browsertest.cc
+++ b/content/browser/background_sync/background_sync_browsertest.cc
@@ -12,6 +12,7 @@
#include "base/task_runner_util.h"
#include "content/browser/background_sync/background_sync_manager.h"
#include "content/browser/background_sync/background_sync_status.h"
+#include "content/browser/background_sync/client_background_sync_registration.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration.h"
#include "content/public/browser/background_sync_context.h"
@@ -60,9 +61,9 @@ void OneShotPendingCallback(
void OneShotPendingDidGetSyncRegistration(
const base::Callback<void(bool)>& callback,
BackgroundSyncStatus error_type,
- const BackgroundSyncRegistration& registration) {
+ scoped_ptr<ClientBackgroundSyncRegistration> registration) {
ASSERT_EQ(BACKGROUND_SYNC_STATUS_OK, error_type);
- callback.Run(registration.sync_state() == SYNC_STATE_PENDING);
+ callback.Run(registration->sync_state() == SYNC_STATE_PENDING);
}
void OneShotPendingDidGetSWRegistration(
@@ -155,6 +156,8 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest {
bool PopConsole(const std::string& expected_msg);
bool RegisterServiceWorker();
bool RegisterOneShot(const std::string& tag);
+ bool UnregisterOneShot(const std::string& tag);
+ bool UnregisterOneShotTwice(const std::string& tag);
bool GetRegistrationOneShot(const std::string& tag);
bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
bool CompleteDelayedOneShot();
@@ -223,6 +226,21 @@ bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) {
return script_result == BuildExpectedResult(tag, "registered");
}
+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),
@@ -374,6 +392,26 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) {
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
}
+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"));
+}
+
} // namespace
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698