Chromium Code Reviews| 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..70bd533ded99bd9ea908a3e693226a91b6d52cb4 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_status.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/browser/service_worker/service_worker_registration.h" |
| @@ -111,6 +112,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. |
| @@ -126,10 +133,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(); |
| @@ -147,6 +154,7 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
| } |
| void SetOnline(bool online); |
| + void SetOnlineOnIOThread(BackgroundSyncContext* sync_context, bool online); |
|
jkarlin
2015/09/11 00:05:23
const scoped_refptr<BackgroundSyncContext>&
iclelland
2015/09/16 17:17:11
Done.
|
| // Returns true if the one-shot sync with tag is currently pending. Fails |
| // (assertion failure) if the tag isn't registered. |
| @@ -168,14 +176,27 @@ class BackgroundSyncBrowserTest : public ContentBrowserTest { |
| }; |
| void BackgroundSyncBrowserTest::SetOnline(bool online) { |
| + if (shell_) { |
|
jkarlin
2015/09/11 00:05:23
What happens if there isn't a shell?
Perhaps ASSE
iclelland
2015/09/11 14:42:15
It would just not try to get the sync context from
iclelland
2015/09/16 17:17:11
Done.
|
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&BackgroundSyncBrowserTest::SetOnlineOnIOThread, |
| + base::Unretained(this), |
| + base::Unretained(GetSyncContextFromShell(shell_)), online)); |
| + } |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +void BackgroundSyncBrowserTest::SetOnlineOnIOThread( |
| + BackgroundSyncContext* sync_context, |
| + bool online) { |
| + BackgroundSyncManager* sync_manager = sync_context->background_sync_manager(); |
| + BackgroundSyncNetworkObserver* network_observer = |
| + sync_manager->GetNetworkObserverForTesting(); |
| if (online) { |
| - NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
| - NetworkChangeNotifier::CONNECTION_WIFI); |
| + network_observer->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_WIFI); |
| } else { |
| - NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
| - NetworkChangeNotifier::CONNECTION_NONE); |
| + network_observer->OnNetworkChanged(NetworkChangeNotifier::CONNECTION_NONE); |
| } |
| - base::RunLoop().RunUntilIdle(); |
| } |
| bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { |