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..86d5364b2984568eb65f0e4c63aeb2e7ee901bf8 100644 |
--- a/content/browser/background_sync/background_sync_browsertest.cc |
+++ b/content/browser/background_sync/background_sync_browsertest.cc |
@@ -11,6 +11,7 @@ |
#include "base/strings/stringprintf.h" |
#include "base/task_runner_util.h" |
#include "content/browser/background_sync/background_sync_manager.h" |
+#include "content/browser/background_sync/background_sync_network_observer.h" |
#include "content/browser/background_sync/background_sync_registration_handle.h" |
#include "content/browser/background_sync/background_sync_status.h" |
#include "content/browser/service_worker/service_worker_context_wrapper.h" |
@@ -28,6 +29,10 @@ |
#include "net/base/network_change_notifier.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#if defined(OS_ANDROID) |
jkarlin
2015/09/24 17:55:19
Remove this block
iclelland
2015/09/24 20:37:19
Done.
|
+#include "content/browser/android/background_sync_network_observer_android.h" |
+#endif |
+ |
using net::NetworkChangeNotifier; |
namespace content { |
@@ -98,7 +103,7 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
~BackgroundSyncBrowserTest() override {} |
void SetUp() override { |
- NetworkChangeNotifier::SetTestNotificationsOnly(true); |
+ BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); |
#if defined(OS_CHROMEOS) |
// ChromeOS's NetworkChangeNotifier doesn't get created in |
@@ -113,6 +118,12 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
shell_ = incognito ? CreateOffTheRecordBrowser() : shell(); |
} |
+ BackgroundSyncContext* GetSyncContextFromShell(Shell* shell) { |
+ StoragePartition* storage = BrowserContext::GetDefaultStoragePartition( |
+ shell_->web_contents()->GetBrowserContext()); |
+ return storage->GetBackgroundSyncContext(); |
+ } |
+ |
void SetUpCommandLine(base::CommandLine* command_line) override { |
// TODO(jkarlin): Remove this once background sync is no longer |
// experimental. |
@@ -128,10 +139,10 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
base::FilePath(FILE_PATH_LITERAL("content/test/data/")))); |
ASSERT_TRUE(https_server_->Start()); |
- SetOnline(true); |
- |
SetIncognitoMode(false); |
+ SetOnline(true); |
+ |
ASSERT_TRUE(LoadTestPage(kDefaultTestURL)); |
ContentBrowserTest::SetUpOnMainThread(); |
@@ -148,7 +159,13 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
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. |
@@ -175,14 +192,28 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
}; |
void BackgroundSyncBrowserTest::SetOnline(bool online) { |
+ ASSERT_TRUE(shell_); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, FROM_HERE, |
+ base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, |
+ base::Unretained(this), |
+ base::Unretained(GetSyncContextFromShell(shell_)), 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) { |
- NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
+ network_observer->NotifyManagerIfNetworkChanged( |
NetworkChangeNotifier::CONNECTION_WIFI); |
} else { |
- NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
+ network_observer->NotifyManagerIfNetworkChanged( |
NetworkChangeNotifier::CONNECTION_NONE); |
} |
- base::RunLoop().RunUntilIdle(); |
} |
bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { |