| 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 <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/test/histogram_tester.h" |
| 12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 14 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 15 #include "net/nqe/effective_connection_type.h" | 16 #include "net/nqe/effective_connection_type.h" |
| 16 #include "net/nqe/network_quality_estimator_test_util.h" | 17 #include "net/nqe/network_quality_estimator_test_util.h" |
| 17 #include "net/nqe/network_quality_store.h" | 18 #include "net/nqe/network_quality_store.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 } | 34 } |
| 34 | 35 |
| 35 void SetDictionaryValue(const base::DictionaryValue& value) override { | 36 void SetDictionaryValue(const base::DictionaryValue& value) override { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | 37 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 | 38 |
| 38 write_count_++; | 39 write_count_++; |
| 39 value_.reset(value.DeepCopy()); | 40 value_.reset(value.DeepCopy()); |
| 40 ASSERT_EQ(value.size(), value_->size()); | 41 ASSERT_EQ(value.size(), value_->size()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 const base::DictionaryValue& GetDictionaryValue() override { | 44 std::unique_ptr<base::DictionaryValue> GetDictionaryValue() override { |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 | 46 |
| 46 read_count_++; | 47 read_count_++; |
| 47 return *(value_.get()); | 48 return value_->CreateDeepCopy(); |
| 48 } | 49 } |
| 49 | 50 |
| 50 size_t write_count() const { | 51 size_t write_count() const { |
| 51 DCHECK(thread_checker_.CalledOnValidThread()); | 52 DCHECK(thread_checker_.CalledOnValidThread()); |
| 52 return write_count_; | 53 return write_count_; |
| 53 } | 54 } |
| 54 | 55 |
| 55 size_t read_count() const { | 56 size_t read_count() const { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 57 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 return read_count_; | 58 return read_count_; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 it->second.effective_connection_type()); | 219 it->second.effective_connection_type()); |
| 219 break; | 220 break; |
| 220 case NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI: | 221 case NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI: |
| 221 EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, | 222 EXPECT_EQ(EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
| 222 it->second.effective_connection_type()); | 223 it->second.effective_connection_type()); |
| 223 break; | 224 break; |
| 224 default: | 225 default: |
| 225 NOTREACHED(); | 226 NOTREACHED(); |
| 226 } | 227 } |
| 227 } | 228 } |
| 229 |
| 230 base::HistogramTester histogram_tester; |
| 231 estimator.OnPrefsRead(read_prefs); |
| 232 histogram_tester.ExpectUniqueSample("NQE.Prefs.ReadSize", 3, 1); |
| 233 |
| 228 manager.ShutdownOnPrefThread(); | 234 manager.ShutdownOnPrefThread(); |
| 229 } | 235 } |
| 230 | 236 |
| 231 // Verifies that the prefs are cleared correctly. | 237 // Verifies that the prefs are cleared correctly. |
| 232 TEST(NetworkQualitiesPrefManager, ClearPrefs) { | 238 TEST(NetworkQualitiesPrefManager, ClearPrefs) { |
| 233 std::map<std::string, std::string> variation_params; | 239 std::map<std::string, std::string> variation_params; |
| 234 TestNetworkQualityEstimator estimator(variation_params, nullptr); | 240 TestNetworkQualityEstimator estimator(variation_params, nullptr); |
| 235 | 241 |
| 236 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); | 242 std::unique_ptr<TestPrefDelegate> prefs_delegate(new TestPrefDelegate()); |
| 237 | 243 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 264 base::RunLoop().RunUntilIdle(); | 270 base::RunLoop().RunUntilIdle(); |
| 265 // Verify that the observer was notified, and the updated network quality was | 271 // Verify that the observer was notified, and the updated network quality was |
| 266 // written to the prefs. | 272 // written to the prefs. |
| 267 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size()); | 273 EXPECT_EQ(1u, manager.ForceReadPrefsForTesting().size()); |
| 268 manager.ShutdownOnPrefThread(); | 274 manager.ShutdownOnPrefThread(); |
| 269 } | 275 } |
| 270 | 276 |
| 271 } // namespace | 277 } // namespace |
| 272 | 278 |
| 273 } // namespace net | 279 } // namespace net |
| OLD | NEW |