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 6e30cc549ccd8fad23a6da19426ce95f308bb068..1ec713c21dfa9c9b64d40312aa1c4ab1f45d3133 100644 |
--- a/content/browser/background_sync/background_sync_browsertest.cc |
+++ b/content/browser/background_sync/background_sync_browsertest.cc |
@@ -21,6 +21,7 @@ |
#include "content/public/browser/storage_partition.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_switches.h" |
+#include "content/public/test/background_sync_test_util.h" |
#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/content_browser_test.h" |
#include "content/public/test/content_browser_test_utils.h" |
@@ -110,7 +111,8 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
~BackgroundSyncBrowserTest() override {} |
void SetUp() override { |
- BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); |
+ background_sync_test_util::SetIgnoreNetworkChangeNotifier(true); |
+ |
ContentBrowserTest::SetUp(); |
} |
@@ -128,6 +130,8 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
return GetStorage()->GetBackgroundSyncContext(); |
} |
+ WebContents* web_contents() { return shell_->web_contents(); } |
+ |
void SetUpCommandLine(base::CommandLine* command_line) override { |
// TODO(jkarlin): Remove this once background sync is no longer |
// experimental. |
@@ -143,7 +147,7 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
SetIncognitoMode(false); |
SetMaxSyncAttempts(1); |
- SetOnline(true); |
+ background_sync_test_util::SetOnline(web_contents(), true); |
ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); |
ContentBrowserTest::SetUpOnMainThread(); |
@@ -156,18 +160,10 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
} |
bool RunScript(const std::string& script, std::string* result) { |
- return content::ExecuteScriptAndExtractString(shell_->web_contents(), |
- script, result); |
+ return content::ExecuteScriptAndExtractString(web_contents(), script, |
+ result); |
} |
- // This runs asynchronously on the IO thread, but we don't need to wait for it |
- // to complete before running a background sync operation, since those also |
- // run on the IO thread. |
- void SetOnline(bool online); |
- void SetOnlineOnIOThread( |
- const scoped_refptr<BackgroundSyncContext>& sync_context, |
- bool online); |
- |
// Returns true if the one-shot sync with tag is currently pending. Fails |
// (assertion failure) if the tag isn't registered. |
bool OneShotPending(const std::string& tag); |
@@ -199,31 +195,6 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); |
}; |
-void BackgroundSyncBrowserTest::SetOnline(bool online) { |
- ASSERT_TRUE(shell_); |
- BrowserThread::PostTask( |
- BrowserThread::IO, FROM_HERE, |
- base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, |
- base::Unretained(this), base::Unretained(GetSyncContext()), |
- online)); |
- base::RunLoop().RunUntilIdle(); |
-} |
- |
-void BackgroundSyncBrowserTest::SetOnlineOnIOThread( |
- const scoped_refptr<BackgroundSyncContext>& sync_context, |
- bool online) { |
- BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); |
- BackgroundSyncNetworkObserver* network_observer = |
- sync_manager->GetNetworkObserverForTesting(); |
- if (online) { |
- network_observer->NotifyManagerIfNetworkChangedForTesting( |
- NetworkChangeNotifier::CONNECTION_WIFI); |
- } else { |
- network_observer->NotifyManagerIfNetworkChangedForTesting( |
- NetworkChangeNotifier::CONNECTION_NONE); |
- } |
-} |
- |
bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { |
bool is_pending; |
base::RunLoop run_loop; |
@@ -406,13 +377,13 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, OneShotDelaysForNetwork) { |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
// Prevent firing by going offline. |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(RegisterOneShot("foo")); |
EXPECT_TRUE(GetRegistrationOneShot("foo")); |
EXPECT_TRUE(OneShotPending("foo")); |
// Resume firing by going online. |
- SetOnline(true); |
+ background_sync_test_util::SetOnline(web_contents(), true); |
EXPECT_TRUE(PopConsole("foo fired")); |
EXPECT_FALSE(GetRegistrationOneShot("foo")); |
} |
@@ -421,7 +392,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntil) { |
EXPECT_TRUE(RegisterServiceWorker()); |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
- SetOnline(true); |
+ background_sync_test_util::SetOnline(web_contents(), true); |
EXPECT_TRUE(RegisterOneShot("delay")); |
// Verify that it is firing. |
@@ -440,7 +411,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, WaitUntilReject) { |
EXPECT_TRUE(RegisterServiceWorker()); |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
- SetOnline(true); |
+ background_sync_test_util::SetOnline(web_contents(), true); |
EXPECT_TRUE(RegisterOneShot("delay")); |
// Verify that it is firing. |
@@ -457,7 +428,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { |
EXPECT_TRUE(RegisterServiceWorker()); |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(RegisterOneShot("normal")); |
EXPECT_TRUE(OneShotPending("normal")); |
@@ -467,7 +438,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, Incognito) { |
// Tell the new network observer that we're offline (it initializes from |
// NetworkChangeNotifier::GetCurrentConnectionType() which is not mocked out |
// in this test). |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); |
EXPECT_TRUE(RegisterServiceWorker()); |
@@ -493,7 +464,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, GetRegistrations) { |
std::vector<std::string> registered_tags; |
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
registered_tags.push_back("foo"); |
registered_tags.push_back("bar"); |
@@ -512,7 +483,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
std::vector<std::string> registered_tags; |
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
registered_tags.push_back("foo_sw"); |
registered_tags.push_back("bar_sw"); |
@@ -533,7 +504,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
std::vector<std::string> registered_tags; |
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); |
EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
@@ -548,7 +519,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
// Prevent firing by going offline. |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(RegisterOneShot("foo")); |
EXPECT_TRUE(GetRegistrationOneShot("foo")); |
EXPECT_TRUE(OneShotPending("foo")); |
@@ -570,7 +541,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
std::vector<std::string> registered_tags; |
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
EXPECT_TRUE(RegisterOneShotFromServiceWorker("foo_sw")); |
EXPECT_TRUE(PopConsole("ok - foo_sw registered in SW")); |
@@ -593,7 +564,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
std::vector<std::string> registered_tags; |
EXPECT_TRUE(GetRegistrationsOneShot(registered_tags)); |
- SetOnline(false); |
+ background_sync_test_util::SetOnline(web_contents(), false); |
registered_tags.push_back("foo"); |
registered_tags.push_back("bar"); |
@@ -620,7 +591,7 @@ IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, |
EXPECT_TRUE(RegisterServiceWorker()); |
EXPECT_TRUE(LoadTestPage(kDefaultTestURL)); // Control the page. |
- SetOnline(true); |
+ background_sync_test_util::SetOnline(web_contents(), true); |
EXPECT_TRUE(RegisterOneShot("delay")); |
// Verify that it is firing. |