Index: content/browser/background_sync/background_sync_manager_unittest.cc |
diff --git a/content/browser/background_sync/background_sync_manager_unittest.cc b/content/browser/background_sync/background_sync_manager_unittest.cc |
index 4817b0c0db90e80f1c18bb0321287578c11ba66e..72db49fc0f5acf441b93fb32b27813b9ee0affd0 100644 |
--- a/content/browser/background_sync/background_sync_manager_unittest.cc |
+++ b/content/browser/background_sync/background_sync_manager_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "base/single_thread_task_runner.h" |
#include "base/test/mock_entropy_provider.h" |
#include "base/thread_task_runner_handle.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/browser_thread_impl.h" |
@@ -233,6 +234,9 @@ class BackgroundSyncManagerTest : public testing::Test { |
} |
void SetUp() override { |
+ // Don't let the tests be confused by the real-world device connectivity |
+ BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); |
+ |
helper_.reset( |
new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); |
@@ -251,6 +255,12 @@ class BackgroundSyncManagerTest : public testing::Test { |
RegisterServiceWorkers(); |
} |
+ void TearDown() override { |
+ // Restore the network observer functionality for subsequent tests |
+ BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests( |
+ false); |
+ } |
+ |
void RegisterServiceWorkers() { |
bool called_1 = false; |
bool called_2 = false; |
@@ -304,7 +314,12 @@ class BackgroundSyncManagerTest : public testing::Test { |
void SetNetwork(net::NetworkChangeNotifier::ConnectionType connection_type) { |
net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
connection_type); |
- base::RunLoop().RunUntilIdle(); |
+ if (test_background_sync_manager_) { |
+ BackgroundSyncNetworkObserver* network_observer = |
+ test_background_sync_manager_->GetNetworkObserverForTesting(); |
+ network_observer->NotifyManagerIfNetworkChanged(connection_type); |
+ base::RunLoop().RunUntilIdle(); |
+ } |
} |
void SetOnBatteryPower(bool on_battery_power) { |