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

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

Issue 1358063004: Use mojo to connect to BackgroundSyncManager object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add browser tests Created 5 years, 3 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 eb79df9d19cdc42283d0d01d922d32ff1d2d641b..38fddf2453278309de2ef3a5368ac986fa552f03 100644
--- a/content/browser/background_sync/background_sync_browsertest.cc
+++ b/content/browser/background_sync/background_sync_browsertest.cc
@@ -154,13 +154,20 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest {
// (assertion failure) if the tag isn't registered.
bool OneShotPending(const std::string& tag);
+ std::string PopConsoleString();
bool PopConsole(const std::string& expected_msg);
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,
+ const std::vector<std::string>& expected_tags);
bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
+ bool GetRegistrationsOneShotFromServiceWorker(
+ const std::vector<std::string>& expected_tags);
bool CompleteDelayedOneShot();
bool RejectDelayedOneShot();
bool NotifyWhenDoneOneShot(const std::string& tag);
@@ -211,9 +218,14 @@ bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) {
return is_pending;
}
-bool BackgroundSyncBrowserTest::PopConsole(const std::string& expected_msg) {
+std::string BackgroundSyncBrowserTest::PopConsoleString() {
std::string script_result;
EXPECT_TRUE(RunScript("resultQueue.pop()", &script_result));
+ return script_result;
+}
+
+bool BackgroundSyncBrowserTest::PopConsole(const std::string& expected_msg) {
+ std::string script_result = PopConsoleString();
return script_result == expected_msg;
}
@@ -230,6 +242,15 @@ bool BackgroundSyncBrowserTest::RegisterOneShot(const std::string& tag) {
return script_result == BuildExpectedResult(tag, "registered");
}
+bool BackgroundSyncBrowserTest::RegisterOneShotFromServiceWorker(
+ const std::string& tag) {
+ std::string script_result;
+ EXPECT_TRUE(
+ RunScript(BuildScriptString("registerOneShotFromServiceWorker", tag),
+ &script_result));
+ return script_result == BuildExpectedResult(tag, "register sent to SW");
+}
+
bool BackgroundSyncBrowserTest::UnregisterOneShot(const std::string& tag) {
std::string script_result;
EXPECT_TRUE(
@@ -252,21 +273,49 @@ bool BackgroundSyncBrowserTest::GetRegistrationOneShot(const std::string& tag) {
return script_result == BuildExpectedResult(tag, "found");
}
-bool BackgroundSyncBrowserTest::GetRegistrationsOneShot(
- const std::vector<std::string>& expected_tags) {
+bool BackgroundSyncBrowserTest::GetRegistrationOneShotFromServiceWorker(
+ const std::string& tag) {
std::string script_result;
- EXPECT_TRUE(RunScript("getRegistrationsOneShot()", &script_result));
+ EXPECT_TRUE(RunScript(
+ BuildScriptString("getRegistrationOneShotFromServiceWorker", tag),
+ &script_result));
+ EXPECT_TRUE(script_result == "ok - getRegistration sent to SW");
+
+ return PopConsole(BuildExpectedResult(tag, "found"));
+}
+bool BackgroundSyncBrowserTest::MatchRegistrations(
+ const std::string& script_result,
+ const std::vector<std::string>& expected_tags) {
EXPECT_TRUE(base::StartsWith(script_result, kSuccessfulOperationPrefix,
base::CompareCase::INSENSITIVE_ASCII));
- script_result = script_result.substr(strlen(kSuccessfulOperationPrefix));
+ std::string tag_string =
+ script_result.substr(strlen(kSuccessfulOperationPrefix));
std::vector<std::string> result_tags = base::SplitString(
- script_result, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ tag_string, ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
return std::set<std::string>(expected_tags.begin(), expected_tags.end()) ==
std::set<std::string>(result_tags.begin(), result_tags.end());
}
+bool BackgroundSyncBrowserTest::GetRegistrationsOneShot(
+ const std::vector<std::string>& expected_tags) {
+ std::string script_result;
+ EXPECT_TRUE(RunScript("getRegistrationsOneShot()", &script_result));
+
+ return MatchRegistrations(script_result, expected_tags);
+}
+
+bool BackgroundSyncBrowserTest::GetRegistrationsOneShotFromServiceWorker(
+ const std::vector<std::string>& expected_tags) {
+ std::string script_result;
+ EXPECT_TRUE(
+ RunScript("getRegistrationsOneShotFromServiceWorker()", &script_result));
+ EXPECT_TRUE(script_result == "ok - getRegistrations sent to SW");
+
+ return MatchRegistrations(PopConsoleString(), expected_tags);
+}
+
bool BackgroundSyncBrowserTest::CompleteDelayedOneShot() {
std::string script_result;
EXPECT_TRUE(RunScript("completeDelayedOneShot()", &script_result));
@@ -309,6 +358,18 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotFires) {
EXPECT_FALSE(GetRegistrationOneShot("foo"));
}
+// Verify that Register works in a service worker
+IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
+ OneShotFromServiceWorkerFires) {
+ EXPECT_TRUE(RegisterServiceWorker());
+ EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
+
+ EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw"));
+ EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW"));
+ EXPECT_TRUE(PopConsole("foo_sw fired"));
+ EXPECT_FALSE(GetRegistrationOneShot("foo_sw"));
+}
+
IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) {
EXPECT_TRUE(RegisterServiceWorker());
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
@@ -413,6 +474,43 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) {
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
}
+// Verify that GetRegistrations works in a service worker
+IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
+ GetRegistrationsFromServiceWorker) {
+ EXPECT_TRUE(RegisterServiceWorker());
+ EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
+
+ std::vector<std::string> registered_tags;
+ EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
+
+ SetOnline(false);
+ registered_tags.push_back("foo_sw");
+ registered_tags.push_back("bar_sw");
+
+ for (const std::string& tag : registered_tags) {
+ EXPECT_TRUE(RegisterOneShotFromServiceWorker(tag));
+ EXPECT_TRUE(PopConsole(BuildExpectedResult(tag, "registered in SW")));
+ }
+
+ EXPECT_TRUE(GetRegistrationsOneShotFromServiceWorker(registered_tags));
+}
+
+// Verify that GetRegistration works in a service worker
+IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
+ GetRegistrationFromServiceWorker) {
+ EXPECT_TRUE(RegisterServiceWorker());
+ EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.
+
+ std::vector<std::string> registered_tags;
+ EXPECT_TRUE(GetRegistrationsOneShot(registered_tags));
+
+ SetOnline(false);
+
+ EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw"));
+ EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW"));
+ EXPECT_TRUE(GetRegistrationOneShotFromServiceWorker("foo_sw"));
+}
+
IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Unregister) {
EXPECT_TRUE(RegisterServiceWorker());
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page.

Powered by Google App Engine
This is Rietveld 408576698