| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/run_loop.h" |
| 7 #include "components/prefs/testing_pref_service.h" | 8 #include "components/prefs/testing_pref_service.h" |
| 8 #include "components/web_resource/eula_accepted_notifier.h" | 9 #include "components/web_resource/eula_accepted_notifier.h" |
| 9 #include "components/web_resource/resource_request_allowed_notifier_test_util.h" | 10 #include "components/web_resource/resource_request_allowed_notifier_test_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace web_resource { | 13 namespace web_resource { |
| 13 | 14 |
| 14 // Override NetworkChangeNotifier to simulate connection type changes for tests. | 15 // Override NetworkChangeNotifier to simulate connection type changes for tests. |
| 15 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier { | 16 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier { |
| 16 public: | 17 public: |
| 17 TestNetworkChangeNotifier() | 18 TestNetworkChangeNotifier() |
| 18 : net::NetworkChangeNotifier(), | 19 : net::NetworkChangeNotifier(), |
| 19 connection_type_to_return_( | 20 connection_type_to_return_( |
| 20 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { | 21 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 // Simulates a change of the connection type to |type|. This will notify any | 24 // Simulates a change of the connection type to |type|. This will notify any |
| 24 // objects that are NetworkChangeNotifiers. | 25 // objects that are NetworkChangeNotifiers. |
| 25 void SimulateNetworkConnectionChange( | 26 void SimulateNetworkConnectionChange( |
| 26 net::NetworkChangeNotifier::ConnectionType type) { | 27 net::NetworkChangeNotifier::ConnectionType type) { |
| 27 connection_type_to_return_ = type; | 28 connection_type_to_return_ = type; |
| 28 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( | 29 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( |
| 29 connection_type_to_return_); | 30 connection_type_to_return_); |
| 30 base::MessageLoop::current()->RunUntilIdle(); | 31 base::RunLoop().RunUntilIdle(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 ConnectionType GetCurrentConnectionType() const override { | 35 ConnectionType GetCurrentConnectionType() const override { |
| 35 return connection_type_to_return_; | 36 return connection_type_to_return_; |
| 36 } | 37 } |
| 37 | 38 |
| 38 // The currently simulated network connection type. If this is set to | 39 // The currently simulated network connection type. If this is set to |
| 39 // CONNECTION_NONE, then NetworkChangeNotifier::IsOffline will return true. | 40 // CONNECTION_NONE, then NetworkChangeNotifier::IsOffline will return true. |
| 40 net::NetworkChangeNotifier::ConnectionType connection_type_to_return_; | 41 net::NetworkChangeNotifier::ConnectionType connection_type_to_return_; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 DisableEulaAndNetwork(); | 273 DisableEulaAndNetwork(); |
| 273 | 274 |
| 274 SimulateNetworkConnectionChange(net::NetworkChangeNotifier::CONNECTION_WIFI); | 275 SimulateNetworkConnectionChange(net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 275 EXPECT_FALSE(was_notified()); | 276 EXPECT_FALSE(was_notified()); |
| 276 | 277 |
| 277 SimulateEulaAccepted(); | 278 SimulateEulaAccepted(); |
| 278 EXPECT_FALSE(was_notified()); | 279 EXPECT_FALSE(was_notified()); |
| 279 } | 280 } |
| 280 | 281 |
| 281 } // namespace web_resource | 282 } // namespace web_resource |
| OLD | NEW |