| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/nqe/network_qualities_prefs_manager.h" | 5 #include "net/nqe/network_qualities_prefs_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); | 100 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
| 101 // Run a request so that effective connection type is recomputed, and | 101 // Run a request so that effective connection type is recomputed, and |
| 102 // observers are notified of change in the network quality.. | 102 // observers are notified of change in the network quality.. |
| 103 estimator.RunOneRequest(); | 103 estimator.RunOneRequest(); |
| 104 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 105 EXPECT_EQ(2u, prefs_delegate_ptr->write_count()); | 105 EXPECT_EQ(2u, prefs_delegate_ptr->write_count()); |
| 106 | 106 |
| 107 // Prefs should not be read again. | 107 // Prefs should not be read again. |
| 108 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); | 108 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); |
| 109 | 109 |
| 110 manager.ShutdownOnPrefThread(); | 110 manager.ShutdownOnPrefSequence(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Verify that the pref is not written if the network ID contains a period. | 113 // Verify that the pref is not written if the network ID contains a period. |
| 114 TEST(NetworkQualitiesPrefManager, WriteWithPeriodInNetworkID) { | 114 TEST(NetworkQualitiesPrefManager, WriteWithPeriodInNetworkID) { |
| 115 TestNetworkQualityEstimator estimator; | 115 TestNetworkQualityEstimator estimator; |
| 116 | 116 |
| 117 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); | 117 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); |
| 118 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get(); | 118 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get(); |
| 119 | 119 |
| 120 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); | 120 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); |
| 121 manager.InitializeOnNetworkThread(&estimator); | 121 manager.InitializeOnNetworkThread(&estimator); |
| 122 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
| 123 | 123 |
| 124 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); | 124 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); |
| 125 | 125 |
| 126 estimator.SimulateNetworkChange( | 126 estimator.SimulateNetworkChange( |
| 127 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "te.st"); | 127 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "te.st"); |
| 128 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); | 128 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); |
| 129 | 129 |
| 130 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 130 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| 131 // Run a request so that effective connection type is recomputed, and | 131 // Run a request so that effective connection type is recomputed, and |
| 132 // observers are notified of change in the network quality. | 132 // observers are notified of change in the network quality. |
| 133 estimator.RunOneRequest(); | 133 estimator.RunOneRequest(); |
| 134 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
| 135 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); | 135 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); |
| 136 | 136 |
| 137 manager.ShutdownOnPrefThread(); | 137 manager.ShutdownOnPrefSequence(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST(NetworkQualitiesPrefManager, WriteAndReadWithMultipleNetworkIDs) { | 140 TEST(NetworkQualitiesPrefManager, WriteAndReadWithMultipleNetworkIDs) { |
| 141 static const size_t kMaxCacheSize = 10u; | 141 static const size_t kMaxCacheSize = 10u; |
| 142 TestNetworkQualityEstimator estimator; | 142 TestNetworkQualityEstimator estimator; |
| 143 | 143 |
| 144 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); | 144 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); |
| 145 | 145 |
| 146 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); | 146 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); |
| 147 manager.InitializeOnNetworkThread(&estimator); | 147 manager.InitializeOnNetworkThread(&estimator); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_2G, | 187 EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_2G, |
| 188 it->first.type); | 188 it->first.type); |
| 189 EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 189 EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 190 it->second.effective_connection_type()); | 190 it->second.effective_connection_type()); |
| 191 } | 191 } |
| 192 | 192 |
| 193 base::HistogramTester histogram_tester; | 193 base::HistogramTester histogram_tester; |
| 194 estimator.OnPrefsRead(read_prefs); | 194 estimator.OnPrefsRead(read_prefs); |
| 195 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", kMaxCacheSize, 1); | 195 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", kMaxCacheSize, 1); |
| 196 | 196 |
| 197 manager.ShutdownOnPrefThread(); | 197 manager.ShutdownOnPrefSequence(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Verifies that the prefs are cleared correctly. | 200 // Verifies that the prefs are cleared correctly. |
| 201 TEST(NetworkQualitiesPrefManager, ClearPrefs) { | 201 TEST(NetworkQualitiesPrefManager, ClearPrefs) { |
| 202 TestNetworkQualityEstimator estimator; | 202 TestNetworkQualityEstimator estimator; |
| 203 | 203 |
| 204 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); | 204 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); |
| 205 | 205 |
| 206 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); | 206 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); |
| 207 manager.InitializeOnNetworkThread(&estimator); | 207 manager.InitializeOnNetworkThread(&estimator); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 226 manager.ClearPrefs(); | 226 manager.ClearPrefs(); |
| 227 EXPECT_EQ(0u, manager.ForceReadPrefsForTesting().size()); | 227 EXPECT_EQ(0u, manager.ForceReadPrefsForTesting().size()); |
| 228 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 228 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| 229 // Run a request so that effective connection type is recomputed, and | 229 // Run a request so that effective connection type is recomputed, and |
| 230 // observers are notified of change in the network quality. | 230 // observers are notified of change in the network quality. |
| 231 estimator.RunOneRequest(); | 231 estimator.RunOneRequest(); |
| 232 base::RunLoop().RunUntilIdle(); | 232 base::RunLoop().RunUntilIdle(); |
| 233 // Verify that the observer was notified, and the updated network quality was | 233 // Verify that the observer was notified, and the updated network quality was |
| 234 // written to the prefs. | 234 // written to the prefs. |
| 235 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size()); | 235 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size()); |
| 236 manager.ShutdownOnPrefThread(); | 236 manager.ShutdownOnPrefSequence(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace | 239 } // namespace |
| 240 | 240 |
| 241 } // namespace net | 241 } // namespace net |
| OLD | NEW |