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

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

Issue 2322183002: Add Network Quality Estimator (NQE) pref manager (Closed)
Patch Set: Addressed kundaji comments Created 4 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/nqe/network_qualities_prefs_manager.h"
6
7 #include <map>
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/run_loop.h"
12 #include "base/values.h"
13 #include "net/base/network_change_notifier.h"
14 #include "net/nqe/effective_connection_type.h"
15 #include "net/nqe/network_quality_estimator_test_util.h"
16 #include "net/nqe/network_quality_store.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace net {
20
21 namespace {
22
23 class MockPrefDelegate : public NetworkQualitiesPrefsManager::PrefDelegate {
24 public:
25 MockPrefDelegate() : write_count_(0) {}
26 ~MockPrefDelegate() {}
27
28 void SetDictionaryValue(const base::DictionaryValue& value) override {
29 write_count_++;
30 }
31
32 size_t write_count() const { return write_count_; }
33
34 private:
35 // Number of times prefs were written.
36 mutable size_t write_count_;
37
38 DISALLOW_COPY_AND_ASSIGN(MockPrefDelegate);
39 };
40
41 TEST(NetworkQualitiesPrefManager, Write) {
42 std::map<std::string, std::string> variation_params;
43 TestNetworkQualityEstimator estimator(variation_params, nullptr);
44
45 std::unique_ptr<MockPrefDelegate> prefs_delegate(new MockPrefDelegate());
46 MockPrefDelegate* prefs_delegate_ptr = prefs_delegate.get();
47
48 NetworkQualitiesPrefsManager manager(std::move(prefs_delegate));
49 manager.InitializeOnNetworkThread(&estimator);
50 base::RunLoop().RunUntilIdle();
51
52 estimator.SimulateNetworkChange(
53 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
54 EXPECT_EQ(0u, prefs_delegate_ptr->write_count());
55
56 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G);
57 // Run a request so that effective connection type is recomputed, and
58 // observers are notified of change in the network quality.
59 estimator.RunOneRequest();
60 base::RunLoop().RunUntilIdle();
61 EXPECT_EQ(1u, prefs_delegate_ptr->write_count());
62
63 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G);
64 // Run a request so that effective connection type is recomputed, and
65 // observers are notified of change in the network quality..
66 estimator.RunOneRequest();
67 base::RunLoop().RunUntilIdle();
68 EXPECT_EQ(2u, prefs_delegate_ptr->write_count());
69
70 manager.ShutdownOnPrefThread();
71 }
72
73 } // namespace
74
75 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698