Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: net/nqe/network_qualities_prefs_manager_unittest.cc

Issue 2596983003: Use net::TestNetworkQualityEstimator in resource loader unittests (Closed)
Patch Set: Rebased, bengr comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 // Current value of the prefs. 66 // Current value of the prefs.
67 std::unique_ptr<base::DictionaryValue> value_; 67 std::unique_ptr<base::DictionaryValue> value_;
68 68
69 base::ThreadChecker thread_checker_; 69 base::ThreadChecker thread_checker_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(TestPrefDelegate); 71 DISALLOW_COPY_AND_ASSIGN(TestPrefDelegate);
72 }; 72 };
73 73
74 TEST(NetworkQualitiesPrefManager, Write) { 74 TEST(NetworkQualitiesPrefManager, Write) {
75 std::map<std::string, std::string> variation_params; 75 TestNetworkQualityEstimator estimator;
76 TestNetworkQualityEstimator estimator(variation_params, nullptr);
77 76
78 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); 77 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate());
79 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get(); 78 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get();
80 79
81 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); 80 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate));
82 manager.InitializeOnNetworkThread(&estimator); 81 manager.InitializeOnNetworkThread(&estimator);
83 base::RunLoop().RunUntilIdle(); 82 base::RunLoop().RunUntilIdle();
84 83
85 // Prefs must be read at when NetworkQualitiesPrefsManager is constructed. 84 // Prefs must be read at when NetworkQualitiesPrefsManager is constructed.
86 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); 85 EXPECT_EQ(1u, prefs_delegate_ptr->read_count());
(...skipping 17 matching lines...) Expand all
104 EXPECT_EQ(2u, prefs_delegate_ptr->write_count()); 103 EXPECT_EQ(2u, prefs_delegate_ptr->write_count());
105 104
106 // Prefs should not be read again. 105 // Prefs should not be read again.
107 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); 106 EXPECT_EQ(1u, prefs_delegate_ptr->read_count());
108 107
109 manager.ShutdownOnPrefThread(); 108 manager.ShutdownOnPrefThread();
110 } 109 }
111 110
112 // Verify that the pref is not written if the network ID contains a period. 111 // Verify that the pref is not written if the network ID contains a period.
113 TEST(NetworkQualitiesPrefManager, WriteWithPeriodInNetworkID) { 112 TEST(NetworkQualitiesPrefManager, WriteWithPeriodInNetworkID) {
114 std::map<std::string, std::string> variation_params; 113 TestNetworkQualityEstimator estimator;
115 TestNetworkQualityEstimator estimator(variation_params, nullptr);
116 114
117 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); 115 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate());
118 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get(); 116 TestPrefDelegate* prefs_delegate_ptr = prefs_delegate.get();
119 117
120 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); 118 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate));
121 manager.InitializeOnNetworkThread(&estimator); 119 manager.InitializeOnNetworkThread(&estimator);
122 base::RunLoop().RunUntilIdle(); 120 base::RunLoop().RunUntilIdle();
123 121
124 EXPECT_EQ(1u, prefs_delegate_ptr->read_count()); 122 EXPECT_EQ(1u, prefs_delegate_ptr->read_count());
125 123
126 estimator.SimulateNetworkChange( 124 estimator.SimulateNetworkChange(
127 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "te.st"); 125 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "te.st");
128 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); 126 EXPECT_EQ(0u, prefs_delegate_ptr->write_count());
129 127
130 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); 128 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
131 // Run a request so that effective connection type is recomputed, and 129 // Run a request so that effective connection type is recomputed, and
132 // observers are notified of change in the network quality. 130 // observers are notified of change in the network quality.
133 estimator.RunOneRequest(); 131 estimator.RunOneRequest();
134 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
135 EXPECT_EQ(0u, prefs_delegate_ptr->write_count()); 133 EXPECT_EQ(0u, prefs_delegate_ptr->write_count());
136 134
137 manager.ShutdownOnPrefThread(); 135 manager.ShutdownOnPrefThread();
138 } 136 }
139 137
140 TEST(NetworkQualitiesPrefManager, WriteAndReadWithMultipleNetworkIDs) { 138 TEST(NetworkQualitiesPrefManager, WriteAndReadWithMultipleNetworkIDs) {
141 std::map<std::string, std::string> variation_params; 139 TestNetworkQualityEstimator estimator;
142 TestNetworkQualityEstimator estimator(variation_params, nullptr);
143 140
144 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); 141 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate());
145 142
146 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); 143 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate));
147 manager.InitializeOnNetworkThread(&estimator); 144 manager.InitializeOnNetworkThread(&estimator);
148 base::RunLoop().RunUntilIdle(); 145 base::RunLoop().RunUntilIdle();
149 146
150 estimator.SimulateNetworkChange( 147 estimator.SimulateNetworkChange(
151 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); 148 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
152 149
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 226
230 base::HistogramTester histogram_tester; 227 base::HistogramTester histogram_tester;
231 estimator.OnPrefsRead(read_prefs); 228 estimator.OnPrefsRead(read_prefs);
232 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", 3, 1); 229 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", 3, 1);
233 230
234 manager.ShutdownOnPrefThread(); 231 manager.ShutdownOnPrefThread();
235 } 232 }
236 233
237 // Verifies that the prefs are cleared correctly. 234 // Verifies that the prefs are cleared correctly.
238 TEST(NetworkQualitiesPrefManager, ClearPrefs) { 235 TEST(NetworkQualitiesPrefManager, ClearPrefs) {
239 std::map<std::string, std::string> variation_params; 236 TestNetworkQualityEstimator estimator;
240 TestNetworkQualityEstimator estimator(variation_params, nullptr);
241 237
242 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); 238 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate());
243 239
244 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate)); 240 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate));
245 manager.InitializeOnNetworkThread(&estimator); 241 manager.InitializeOnNetworkThread(&estimator);
246 base::RunLoop().RunUntilIdle(); 242 base::RunLoop().RunUntilIdle();
247 243
248 estimator.SimulateNetworkChange( 244 estimator.SimulateNetworkChange(
249 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); 245 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
250 246
(...skipping 19 matching lines...) Expand all
270 base::RunLoop().RunUntilIdle(); 266 base::RunLoop().RunUntilIdle();
271 // Verify that the observer was notified, and the updated network quality was 267 // Verify that the observer was notified, and the updated network quality was
272 // written to the prefs. 268 // written to the prefs.
273 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size()); 269 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size());
274 manager.ShutdownOnPrefThread(); 270 manager.ShutdownOnPrefThread();
275 } 271 }
276 272
277 } // namespace 273 } // namespace
278 274
279 } // namespace net 275 } // namespace net
OLDNEW
« no previous file with comments | « content/browser/loader/resource_loader_unittest.cc ('k') | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698