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

Side by Side Diff: third_party/WebKit/Source/platform/network/NetworkStateNotifierTest.cpp

Issue 2883763002: Expose ECT to render frames, Blink and NetInfo (Closed)
Patch Set: rebased Created 3 years, 6 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 /* 1 /*
2 * Copyright (c) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "platform/network/NetworkStateNotifier.h" 31 #include "platform/network/NetworkStateNotifier.h"
32 32
33 #include "platform/scheduler/test/fake_web_task_runner.h" 33 #include "platform/scheduler/test/fake_web_task_runner.h"
34 #include "platform/testing/UnitTestHelpers.h" 34 #include "platform/testing/UnitTestHelpers.h"
35 #include "platform/wtf/Functional.h" 35 #include "platform/wtf/Functional.h"
36 #include "platform/wtf/Optional.h" 36 #include "platform/wtf/Optional.h"
37 #include "platform/wtf/Time.h" 37 #include "platform/wtf/Time.h"
38 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
39 #include "public/platform/WebConnectionType.h" 39 #include "public/platform/WebConnectionType.h"
40 #include "public/platform/WebEffectiveConnectionType.h"
40 #include "public/platform/WebThread.h" 41 #include "public/platform/WebThread.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 43
43 namespace blink { 44 namespace blink {
44 45
45 using scheduler::FakeWebTaskRunner; 46 using scheduler::FakeWebTaskRunner;
46 47
47 namespace { 48 namespace {
48 const double kNoneMaxBandwidthMbps = 0.0; 49 const double kNoneMaxBandwidthMbps = 0.0;
49 const double kBluetoothMaxBandwidthMbps = 1.0; 50 const double kBluetoothMaxBandwidthMbps = 1.0;
50 const double kEthernetMaxBandwidthMbps = 2.0; 51 const double kEthernetMaxBandwidthMbps = 2.0;
51 const Optional<TimeDelta> kEthernetHttpRtt(TimeDelta::FromMilliseconds(50)); 52 const Optional<TimeDelta> kEthernetHttpRtt(TimeDelta::FromMilliseconds(50));
52 const Optional<TimeDelta> kEthernetTransportRtt( 53 const Optional<TimeDelta> kEthernetTransportRtt(
53 TimeDelta::FromMilliseconds(25)); 54 TimeDelta::FromMilliseconds(25));
54 const Optional<double> kEthernetThroughputMbps(75.0); 55 const Optional<double> kEthernetThroughputMbps(75.0);
55 const Optional<TimeDelta> kUnknownRtt; 56 const Optional<TimeDelta> kUnknownRtt;
56 const Optional<double> kUnknownThroughputMbps; 57 const Optional<double> kUnknownThroughputMbps;
57 } 58 }
58 59
59 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { 60 class StateObserver : public NetworkStateNotifier::NetworkStateObserver {
60 public: 61 public:
61 StateObserver() 62 StateObserver()
62 : observed_type_(kWebConnectionTypeNone), 63 : observed_type_(kWebConnectionTypeNone),
63 observed_max_bandwidth_mbps_(0.0), 64 observed_max_bandwidth_mbps_(0.0),
65 observed_effective_type_(WebEffectiveConnectionType::kTypeUnknown),
64 observed_http_rtt_(kUnknownRtt), 66 observed_http_rtt_(kUnknownRtt),
65 observed_transport_rtt_(kUnknownRtt), 67 observed_transport_rtt_(kUnknownRtt),
66 observed_downlink_throughput_mbps_(kUnknownThroughputMbps), 68 observed_downlink_throughput_mbps_(kUnknownThroughputMbps),
67 observed_on_line_state_(false), 69 observed_on_line_state_(false),
68 callback_count_(0) {} 70 callback_count_(0) {}
69 71
70 virtual void ConnectionChange( 72 virtual void ConnectionChange(
71 WebConnectionType type, 73 WebConnectionType type,
72 double max_bandwidth_mbps, 74 double max_bandwidth_mbps,
75 WebEffectiveConnectionType effective_type,
73 const Optional<TimeDelta>& http_rtt, 76 const Optional<TimeDelta>& http_rtt,
74 const Optional<TimeDelta>& transport_rtt, 77 const Optional<TimeDelta>& transport_rtt,
75 const Optional<double>& downlink_throughput_mbps) { 78 const Optional<double>& downlink_throughput_mbps) {
76 observed_type_ = type; 79 observed_type_ = type;
77 observed_max_bandwidth_mbps_ = max_bandwidth_mbps; 80 observed_max_bandwidth_mbps_ = max_bandwidth_mbps;
81 observed_effective_type_ = effective_type;
78 observed_http_rtt_ = http_rtt; 82 observed_http_rtt_ = http_rtt;
79 observed_transport_rtt_ = transport_rtt; 83 observed_transport_rtt_ = transport_rtt;
80 observed_downlink_throughput_mbps_ = downlink_throughput_mbps; 84 observed_downlink_throughput_mbps_ = downlink_throughput_mbps;
81 callback_count_ += 1; 85 callback_count_ += 1;
82 86
83 if (closure_) 87 if (closure_)
84 (*closure_)(); 88 (*closure_)();
85 } 89 }
86 90
87 virtual void OnLineStateChange(bool on_line) { 91 virtual void OnLineStateChange(bool on_line) {
88 observed_on_line_state_ = on_line; 92 observed_on_line_state_ = on_line;
89 callback_count_ += 1; 93 callback_count_ += 1;
90 94
91 if (closure_) 95 if (closure_)
92 (*closure_)(); 96 (*closure_)();
93 } 97 }
94 98
95 WebConnectionType ObservedType() const { return observed_type_; } 99 WebConnectionType ObservedType() const { return observed_type_; }
96 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; } 100 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; }
101 WebEffectiveConnectionType ObservedEffectiveType() const {
102 return observed_effective_type_;
103 }
97 Optional<TimeDelta> ObservedHttpRtt() const { return observed_http_rtt_; } 104 Optional<TimeDelta> ObservedHttpRtt() const { return observed_http_rtt_; }
98 Optional<TimeDelta> ObservedTransportRtt() const { 105 Optional<TimeDelta> ObservedTransportRtt() const {
99 return observed_transport_rtt_; 106 return observed_transport_rtt_;
100 } 107 }
101 Optional<double> ObservedDownlinkThroughputMbps() const { 108 Optional<double> ObservedDownlinkThroughputMbps() const {
102 return observed_downlink_throughput_mbps_; 109 return observed_downlink_throughput_mbps_;
103 } 110 }
104 bool ObservedOnLineState() const { return observed_on_line_state_; } 111 bool ObservedOnLineState() const { return observed_on_line_state_; }
105 int CallbackCount() const { return callback_count_; } 112 int CallbackCount() const { return callback_count_; }
106 113
107 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) { 114 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) {
108 closure_ = std::move(closure); 115 closure_ = std::move(closure);
109 } 116 }
110 117
111 private: 118 private:
112 std::unique_ptr<WTF::Closure> closure_; 119 std::unique_ptr<WTF::Closure> closure_;
113 WebConnectionType observed_type_; 120 WebConnectionType observed_type_;
114 double observed_max_bandwidth_mbps_; 121 double observed_max_bandwidth_mbps_;
122 WebEffectiveConnectionType observed_effective_type_;
115 Optional<TimeDelta> observed_http_rtt_; 123 Optional<TimeDelta> observed_http_rtt_;
116 Optional<TimeDelta> observed_transport_rtt_; 124 Optional<TimeDelta> observed_transport_rtt_;
117 Optional<double> observed_downlink_throughput_mbps_; 125 Optional<double> observed_downlink_throughput_mbps_;
118 bool observed_on_line_state_; 126 bool observed_on_line_state_;
119 int callback_count_; 127 int callback_count_;
120 }; 128 };
121 129
122 class NetworkStateNotifierTest : public ::testing::Test { 130 class NetworkStateNotifierTest : public ::testing::Test {
123 public: 131 public:
124 NetworkStateNotifierTest() 132 NetworkStateNotifierTest()
(...skipping 15 matching lines...) Expand all
140 } 148 }
141 149
142 protected: 150 protected:
143 void RunPendingTasks() { 151 void RunPendingTasks() {
144 task_runner_->RunUntilIdle(); 152 task_runner_->RunUntilIdle();
145 task_runner2_->RunUntilIdle(); 153 task_runner2_->RunUntilIdle();
146 } 154 }
147 155
148 void SetConnection(WebConnectionType type, 156 void SetConnection(WebConnectionType type,
149 double max_bandwidth_mbps, 157 double max_bandwidth_mbps,
158 WebEffectiveConnectionType effective_type,
150 const Optional<TimeDelta>& http_rtt, 159 const Optional<TimeDelta>& http_rtt,
151 const Optional<TimeDelta>& transport_rtt, 160 const Optional<TimeDelta>& transport_rtt,
152 const Optional<double>& downlink_throughput_mbps) { 161 const Optional<double>& downlink_throughput_mbps) {
153 notifier_.SetWebConnection(type, max_bandwidth_mbps); 162 notifier_.SetWebConnection(type, max_bandwidth_mbps);
154 notifier_.SetNetworkQuality( 163 notifier_.SetNetworkQuality(
164 effective_type,
155 http_rtt.has_value() ? http_rtt.value() 165 http_rtt.has_value() ? http_rtt.value()
156 : base::TimeDelta::FromMilliseconds(-1), 166 : base::TimeDelta::FromMilliseconds(-1),
157 transport_rtt.has_value() ? transport_rtt.value() 167 transport_rtt.has_value() ? transport_rtt.value()
158 : base::TimeDelta::FromMilliseconds(-1), 168 : base::TimeDelta::FromMilliseconds(-1),
159 downlink_throughput_mbps.has_value() 169 downlink_throughput_mbps.has_value()
160 ? downlink_throughput_mbps.value() * 1000 170 ? downlink_throughput_mbps.value() * 1000
161 : -1); 171 : -1);
162 RunPendingTasks(); 172 RunPendingTasks();
163 } 173 }
164 void SetOnLine(bool on_line) { 174 void SetOnLine(bool on_line) {
(...skipping 14 matching lines...) Expand all
179 observer->SetNotificationCallback( 189 observer->SetNotificationCallback(
180 Bind(&NetworkStateNotifier::RemoveConnectionObserver, 190 Bind(&NetworkStateNotifier::RemoveConnectionObserver,
181 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_remove), 191 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_remove),
182 WTF::Unretained(GetTaskRunner()))); 192 WTF::Unretained(GetTaskRunner())));
183 } 193 }
184 194
185 bool VerifyObservations( 195 bool VerifyObservations(
186 const StateObserver& observer, 196 const StateObserver& observer,
187 WebConnectionType type, 197 WebConnectionType type,
188 double max_bandwidth_mbps, 198 double max_bandwidth_mbps,
199 WebEffectiveConnectionType effective_type,
189 const Optional<TimeDelta>& http_rtt, 200 const Optional<TimeDelta>& http_rtt,
190 const Optional<TimeDelta>& transport_rtt, 201 const Optional<TimeDelta>& transport_rtt,
191 const Optional<double>& downlink_throughput_mbps) const { 202 const Optional<double>& downlink_throughput_mbps) const {
192 EXPECT_EQ(type, observer.ObservedType()); 203 EXPECT_EQ(type, observer.ObservedType());
193 EXPECT_EQ(max_bandwidth_mbps, observer.ObservedMaxBandwidth()); 204 EXPECT_EQ(max_bandwidth_mbps, observer.ObservedMaxBandwidth());
205 EXPECT_EQ(effective_type, observer.ObservedEffectiveType());
194 EXPECT_EQ(http_rtt, observer.ObservedHttpRtt()); 206 EXPECT_EQ(http_rtt, observer.ObservedHttpRtt());
195 EXPECT_EQ(transport_rtt, observer.ObservedTransportRtt()); 207 EXPECT_EQ(transport_rtt, observer.ObservedTransportRtt());
196 EXPECT_EQ(downlink_throughput_mbps, 208 EXPECT_EQ(downlink_throughput_mbps,
197 observer.ObservedDownlinkThroughputMbps()); 209 observer.ObservedDownlinkThroughputMbps());
198 210
199 return observer.ObservedType() == type && 211 return observer.ObservedType() == type &&
200 observer.ObservedMaxBandwidth() == max_bandwidth_mbps && 212 observer.ObservedMaxBandwidth() == max_bandwidth_mbps &&
213 observer.ObservedEffectiveType() == effective_type &&
201 observer.ObservedHttpRtt() == http_rtt && 214 observer.ObservedHttpRtt() == http_rtt &&
202 observer.ObservedTransportRtt() == transport_rtt && 215 observer.ObservedTransportRtt() == transport_rtt &&
203 observer.ObservedDownlinkThroughputMbps() == 216 observer.ObservedDownlinkThroughputMbps() ==
204 downlink_throughput_mbps; 217 downlink_throughput_mbps;
205 } 218 }
206 219
207 RefPtr<FakeWebTaskRunner> task_runner_; 220 RefPtr<FakeWebTaskRunner> task_runner_;
208 RefPtr<FakeWebTaskRunner> task_runner2_; 221 RefPtr<FakeWebTaskRunner> task_runner2_;
209 NetworkStateNotifier notifier_; 222 NetworkStateNotifier notifier_;
210 }; 223 };
211 224
212 TEST_F(NetworkStateNotifierTest, AddObserver) { 225 TEST_F(NetworkStateNotifierTest, AddObserver) {
213 StateObserver observer; 226 StateObserver observer;
214 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 227 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
215 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, 228 EXPECT_TRUE(VerifyObservations(
216 kNoneMaxBandwidthMbps, kUnknownRtt, 229 observer, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
217 kUnknownRtt, kUnknownThroughputMbps)); 230 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
231 kUnknownThroughputMbps));
218 232
219 // Change max. bandwidth and the network quality estimates. 233 // Change max. bandwidth and the network quality estimates.
220 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 234 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
221 kEthernetHttpRtt, kEthernetTransportRtt, 235 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
222 kEthernetThroughputMbps); 236 kEthernetTransportRtt, kEthernetThroughputMbps);
223 EXPECT_TRUE(VerifyObservations( 237 EXPECT_TRUE(VerifyObservations(
224 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 238 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
225 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 239 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
240 kEthernetTransportRtt, kEthernetThroughputMbps));
226 EXPECT_EQ(observer.CallbackCount(), 2); 241 EXPECT_EQ(observer.CallbackCount(), 2);
227 242
228 // Only change the connection type. 243 // Only change the connection type.
229 SetConnection(kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps, 244 SetConnection(kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps,
230 kEthernetHttpRtt, kEthernetTransportRtt, 245 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
231 kEthernetThroughputMbps); 246 kEthernetTransportRtt, kEthernetThroughputMbps);
232 EXPECT_TRUE(VerifyObservations( 247 EXPECT_TRUE(VerifyObservations(
233 observer, kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps, 248 observer, kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps,
234 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 249 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
250 kEthernetTransportRtt, kEthernetThroughputMbps));
235 EXPECT_EQ(observer.CallbackCount(), 3); 251 EXPECT_EQ(observer.CallbackCount(), 3);
236 252
237 // Only change the max. bandwidth. 253 // Only change the max. bandwidth.
238 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 254 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
239 kEthernetHttpRtt, kEthernetTransportRtt, 255 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
240 kEthernetThroughputMbps); 256 kEthernetTransportRtt, kEthernetThroughputMbps);
241 EXPECT_TRUE(VerifyObservations( 257 EXPECT_TRUE(VerifyObservations(
242 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 258 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
243 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 259 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
260 kEthernetTransportRtt, kEthernetThroughputMbps));
244 EXPECT_EQ(observer.CallbackCount(), 4); 261 EXPECT_EQ(observer.CallbackCount(), 4);
245 262
246 // Only change the transport RTT. 263 // Only change the transport RTT.
247 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 264 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
248 kEthernetHttpRtt, kEthernetTransportRtt.value() * 2, 265 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
249 kEthernetThroughputMbps); 266 kEthernetTransportRtt.value() * 2, kEthernetThroughputMbps);
250 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, 267 EXPECT_TRUE(VerifyObservations(
251 kEthernetMaxBandwidthMbps, kEthernetHttpRtt, 268 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
252 kEthernetTransportRtt.value() * 2, 269 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
253 kEthernetThroughputMbps)); 270 kEthernetTransportRtt.value() * 2, kEthernetThroughputMbps));
254 EXPECT_EQ(observer.CallbackCount(), 5); 271 EXPECT_EQ(observer.CallbackCount(), 5);
255 272
273 // Only change the effective connection type.
274 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
275 WebEffectiveConnectionType::kType4G, kEthernetHttpRtt,
276 kEthernetTransportRtt.value() * 2, kEthernetThroughputMbps);
277 EXPECT_TRUE(VerifyObservations(
278 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
279 WebEffectiveConnectionType::kType4G, kEthernetHttpRtt,
280 kEthernetTransportRtt.value() * 2, kEthernetThroughputMbps));
281 EXPECT_EQ(observer.CallbackCount(), 6);
282
256 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 283 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
257 } 284 }
258 285
259 TEST_F(NetworkStateNotifierTest, RemoveObserver) { 286 TEST_F(NetworkStateNotifierTest, RemoveObserver) {
260 StateObserver observer1, observer2; 287 StateObserver observer1, observer2;
261 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 288 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
262 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 289 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
263 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 290 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
264 291
265 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 292 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
266 kEthernetHttpRtt, kEthernetTransportRtt, 293 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
267 kEthernetThroughputMbps); 294 kEthernetTransportRtt, kEthernetThroughputMbps);
268 295
269 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 296 EXPECT_TRUE(VerifyObservations(
270 kNoneMaxBandwidthMbps, kUnknownRtt, 297 observer1, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
271 kUnknownRtt, kUnknownThroughputMbps)); 298 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
299 kUnknownThroughputMbps));
272 EXPECT_TRUE(VerifyObservations( 300 EXPECT_TRUE(VerifyObservations(
273 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 301 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
274 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 302 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
303 kEthernetTransportRtt, kEthernetThroughputMbps));
275 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 304 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
276 } 305 }
277 306
278 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { 307 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) {
279 StateObserver observer1; 308 StateObserver observer1;
280 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 309 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
281 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 310 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
282 311
283 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 312 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
284 kEthernetHttpRtt, kEthernetTransportRtt, 313 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
285 kEthernetThroughputMbps); 314 kEthernetTransportRtt, kEthernetThroughputMbps);
286 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 315 EXPECT_TRUE(VerifyObservations(
287 kNoneMaxBandwidthMbps, kUnknownRtt, 316 observer1, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
288 kUnknownRtt, kUnknownThroughputMbps)); 317 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
318 kUnknownThroughputMbps));
289 } 319 }
290 320
291 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { 321 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) {
292 StateObserver observer1, observer2; 322 StateObserver observer1, observer2;
293 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 323 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
294 AddObserverOnNotification(&observer1, &observer2); 324 AddObserverOnNotification(&observer1, &observer2);
295 325
296 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 326 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
297 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 327 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
298 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 328 kUnknownRtt, kUnknownThroughputMbps);
299 kBluetoothMaxBandwidthMbps, kUnknownRtt, 329 EXPECT_TRUE(VerifyObservations(
300 kUnknownRtt, kUnknownThroughputMbps)); 330 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
301 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 331 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
302 kBluetoothMaxBandwidthMbps, kUnknownRtt, 332 kUnknownThroughputMbps));
303 kUnknownRtt, kUnknownThroughputMbps)); 333 EXPECT_TRUE(VerifyObservations(
334 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
335 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
336 kUnknownThroughputMbps));
304 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 337 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
305 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 338 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
306 } 339 }
307 340
308 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { 341 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) {
309 StateObserver observer1; 342 StateObserver observer1;
310 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 343 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
311 RemoveObserverOnNotification(&observer1, &observer1); 344 RemoveObserverOnNotification(&observer1, &observer1);
312 345
313 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 346 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
314 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 347 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
315 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 348 kUnknownRtt, kUnknownThroughputMbps);
316 kBluetoothMaxBandwidthMbps, kUnknownRtt, 349 EXPECT_TRUE(VerifyObservations(
317 kUnknownRtt, kUnknownThroughputMbps)); 350 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
351 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
352 kUnknownThroughputMbps));
318 353
319 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 354 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
320 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 355 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
321 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 356 kUnknownRtt, kUnknownThroughputMbps);
322 kBluetoothMaxBandwidthMbps, kUnknownRtt, 357 EXPECT_TRUE(VerifyObservations(
323 kUnknownRtt, kUnknownThroughputMbps)); 358 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
359 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
360 kUnknownThroughputMbps));
324 } 361 }
325 362
326 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { 363 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) {
327 StateObserver observer1, observer2; 364 StateObserver observer1, observer2;
328 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 365 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
329 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 366 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
330 RemoveObserverOnNotification(&observer1, &observer1); 367 RemoveObserverOnNotification(&observer1, &observer1);
331 368
332 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 369 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
333 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 370 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
334 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 371 kUnknownRtt, kUnknownThroughputMbps);
335 kBluetoothMaxBandwidthMbps, kUnknownRtt, 372 EXPECT_TRUE(VerifyObservations(
336 kUnknownRtt, kUnknownThroughputMbps)); 373 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
337 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 374 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
338 kBluetoothMaxBandwidthMbps, kUnknownRtt, 375 kUnknownThroughputMbps));
339 kUnknownRtt, kUnknownThroughputMbps)); 376 EXPECT_TRUE(VerifyObservations(
377 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
378 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
379 kUnknownThroughputMbps));
340 380
341 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 381 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
342 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 382 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
343 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 383 kUnknownRtt, kUnknownThroughputMbps);
344 kBluetoothMaxBandwidthMbps, kUnknownRtt, 384 EXPECT_TRUE(VerifyObservations(
345 kUnknownRtt, kUnknownThroughputMbps)); 385 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
346 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, 386 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
347 kEthernetMaxBandwidthMbps, kUnknownRtt, 387 kUnknownThroughputMbps));
348 kUnknownRtt, kUnknownThroughputMbps)); 388 EXPECT_TRUE(VerifyObservations(
389 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
390 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
391 kUnknownThroughputMbps));
349 392
350 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 393 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
351 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 394 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
352 } 395 }
353 396
354 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { 397 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) {
355 StateObserver observer1, observer2; 398 StateObserver observer1, observer2;
356 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 399 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
357 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 400 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
358 RemoveObserverOnNotification(&observer2, &observer1); 401 RemoveObserverOnNotification(&observer2, &observer1);
359 402
360 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 403 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
361 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 404 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
405 kUnknownRtt, kUnknownThroughputMbps);
362 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); 406 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth);
363 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); 407 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth);
364 408
365 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 409 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
366 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 410 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
367 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 411 kUnknownRtt, kUnknownThroughputMbps);
368 kBluetoothMaxBandwidthMbps, kUnknownRtt, 412 EXPECT_TRUE(VerifyObservations(
369 kUnknownRtt, kUnknownThroughputMbps)); 413 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
370 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, 414 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
371 kEthernetMaxBandwidthMbps, kUnknownRtt, 415 kUnknownThroughputMbps));
372 kUnknownRtt, kUnknownThroughputMbps)); 416 EXPECT_TRUE(VerifyObservations(
417 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
418 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
419 kUnknownThroughputMbps));
373 420
374 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 421 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
375 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 422 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
376 } 423 }
377 424
378 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { 425 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) {
379 StateObserver observer1, observer2, observer3; 426 StateObserver observer1, observer2, observer3;
380 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 427 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
381 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 428 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
382 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); 429 notifier_.AddConnectionObserver(&observer3, GetTaskRunner());
383 RemoveObserverOnNotification(&observer1, &observer2); 430 RemoveObserverOnNotification(&observer1, &observer2);
384 431
385 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 432 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
386 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 433 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
387 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 434 kUnknownRtt, kUnknownThroughputMbps);
388 kBluetoothMaxBandwidthMbps, kUnknownRtt, 435 EXPECT_TRUE(VerifyObservations(
389 kUnknownRtt, kUnknownThroughputMbps)); 436 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
390 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 437 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
391 kNoneMaxBandwidthMbps, kUnknownRtt, 438 kUnknownThroughputMbps));
392 kUnknownRtt, kUnknownThroughputMbps)); 439 EXPECT_TRUE(VerifyObservations(
393 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, 440 observer2, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
394 kBluetoothMaxBandwidthMbps, kUnknownRtt, 441 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
395 kUnknownRtt, kUnknownThroughputMbps)); 442 kUnknownThroughputMbps));
443 EXPECT_TRUE(VerifyObservations(
444 observer3, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
445 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
446 kUnknownThroughputMbps));
396 447
397 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 448 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
398 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 449 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
399 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); 450 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner());
400 } 451 }
401 452
402 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { 453 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) {
403 StateObserver observer1, observer2; 454 StateObserver observer1, observer2;
404 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 455 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
405 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 456 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
406 457
407 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 458 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
408 kEthernetHttpRtt, kEthernetTransportRtt, 459 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
409 kEthernetThroughputMbps); 460 kEthernetTransportRtt, kEthernetThroughputMbps);
410 EXPECT_TRUE(VerifyObservations( 461 EXPECT_TRUE(VerifyObservations(
411 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 462 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
412 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 463 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
464 kEthernetTransportRtt, kEthernetThroughputMbps));
413 EXPECT_TRUE(VerifyObservations( 465 EXPECT_TRUE(VerifyObservations(
414 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 466 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
415 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 467 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
468 kEthernetTransportRtt, kEthernetThroughputMbps));
416 469
417 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 470 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
418 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 471 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
419 } 472 }
420 473
421 TEST_F(NetworkStateNotifierTest, RemoveContext) { 474 TEST_F(NetworkStateNotifierTest, RemoveContext) {
422 StateObserver observer1, observer2; 475 StateObserver observer1, observer2;
423 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 476 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
424 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 477 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
425 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 478 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
426 479
427 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 480 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
428 kEthernetHttpRtt, kEthernetTransportRtt, 481 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
429 kEthernetThroughputMbps); 482 kEthernetTransportRtt, kEthernetThroughputMbps);
430 EXPECT_TRUE(VerifyObservations( 483 EXPECT_TRUE(VerifyObservations(
431 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 484 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
432 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 485 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
433 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 486 kEthernetTransportRtt, kEthernetThroughputMbps));
434 kNoneMaxBandwidthMbps, kUnknownRtt, 487 EXPECT_TRUE(VerifyObservations(
435 kUnknownRtt, kUnknownThroughputMbps)); 488 observer2, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
489 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
490 kUnknownThroughputMbps));
436 491
437 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 492 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
438 } 493 }
439 494
440 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { 495 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) {
441 StateObserver observer1, observer2; 496 StateObserver observer1, observer2;
442 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 497 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
443 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 498 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
444 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 499 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
445 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 500 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
446 501
447 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 502 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
448 kEthernetHttpRtt, kEthernetTransportRtt, 503 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
449 kEthernetThroughputMbps); 504 kEthernetTransportRtt, kEthernetThroughputMbps);
450 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 505 EXPECT_TRUE(VerifyObservations(
451 kNoneMaxBandwidthMbps, kUnknownRtt, 506 observer1, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
452 kUnknownRtt, kUnknownThroughputMbps)); 507 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
453 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 508 kUnknownThroughputMbps));
454 kNoneMaxBandwidthMbps, kUnknownRtt, 509 EXPECT_TRUE(VerifyObservations(
455 kUnknownRtt, kUnknownThroughputMbps)); 510 observer2, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
511 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
512 kUnknownThroughputMbps));
456 } 513 }
457 514
458 TEST_F(NetworkStateNotifierTest, SetOverride) { 515 TEST_F(NetworkStateNotifierTest, SetOverride) {
459 StateObserver observer; 516 StateObserver observer;
460 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 517 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
461 518
462 notifier_.SetOnLine(true); 519 notifier_.SetOnLine(true);
463 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 520 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
464 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); 521 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
465 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, 522 kUnknownRtt, kUnknownThroughputMbps);
466 kBluetoothMaxBandwidthMbps, kUnknownRtt, 523 EXPECT_TRUE(VerifyObservations(
467 kUnknownRtt, kUnknownThroughputMbps)); 524 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
525 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
526 kUnknownThroughputMbps));
468 EXPECT_TRUE(notifier_.OnLine()); 527 EXPECT_TRUE(notifier_.OnLine());
469 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); 528 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType());
470 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); 529 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth());
471 530
472 notifier_.SetOverride(true, kWebConnectionTypeEthernet, 531 notifier_.SetOverride(true, kWebConnectionTypeEthernet,
473 kEthernetMaxBandwidthMbps); 532 kEthernetMaxBandwidthMbps);
474 RunPendingTasks(); 533 RunPendingTasks();
475 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, 534 EXPECT_TRUE(VerifyObservations(
476 kEthernetMaxBandwidthMbps, kUnknownRtt, 535 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
477 kUnknownRtt, kUnknownThroughputMbps)); 536 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
537 kUnknownThroughputMbps));
478 EXPECT_TRUE(notifier_.OnLine()); 538 EXPECT_TRUE(notifier_.OnLine());
479 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); 539 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
480 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); 540 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
481 541
482 // When override is active, calls to setOnLine and setConnection are temporary 542 // When override is active, calls to setOnLine and setConnection are temporary
483 // ignored. 543 // ignored.
484 notifier_.SetOnLine(false); 544 notifier_.SetOnLine(false);
485 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps, kUnknownRtt, 545 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
546 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
486 kUnknownRtt, kUnknownThroughputMbps); 547 kUnknownRtt, kUnknownThroughputMbps);
487 RunPendingTasks(); 548 RunPendingTasks();
488 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, 549 EXPECT_TRUE(VerifyObservations(
489 kEthernetMaxBandwidthMbps, kUnknownRtt, 550 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
490 kUnknownRtt, kUnknownThroughputMbps)); 551 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
552 kUnknownThroughputMbps));
491 EXPECT_TRUE(notifier_.OnLine()); 553 EXPECT_TRUE(notifier_.OnLine());
492 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); 554 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
493 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); 555 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
494 556
495 notifier_.ClearOverride(); 557 notifier_.ClearOverride();
496 RunPendingTasks(); 558 RunPendingTasks();
497 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, 559 EXPECT_TRUE(VerifyObservations(
498 kNoneMaxBandwidthMbps, kUnknownRtt, 560 observer, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
499 kUnknownRtt, kUnknownThroughputMbps)); 561 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
562 kUnknownThroughputMbps));
500 EXPECT_FALSE(notifier_.OnLine()); 563 EXPECT_FALSE(notifier_.OnLine());
501 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); 564 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType());
502 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); 565 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth());
503 566
504 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 567 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
505 } 568 }
506 569
507 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { 570 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) {
508 StateObserver observer; 571 StateObserver observer;
509 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 572 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
510 573
511 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 574 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
512 kEthernetHttpRtt, kEthernetTransportRtt, 575 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
513 kEthernetThroughputMbps); 576 kEthernetTransportRtt, kEthernetThroughputMbps);
514 EXPECT_TRUE(VerifyObservations( 577 EXPECT_TRUE(VerifyObservations(
515 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 578 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
516 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 579 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
580 kEthernetTransportRtt, kEthernetThroughputMbps));
517 EXPECT_EQ(observer.CallbackCount(), 2); 581 EXPECT_EQ(observer.CallbackCount(), 2);
518 582
519 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 583 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
520 kEthernetHttpRtt, kEthernetTransportRtt, 584 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
521 kEthernetThroughputMbps); 585 kEthernetTransportRtt, kEthernetThroughputMbps);
522 EXPECT_EQ(observer.CallbackCount(), 2); 586 EXPECT_EQ(observer.CallbackCount(), 2);
523 587
524 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 588 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
589 WebEffectiveConnectionType::kType4G,
525 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, 590 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2,
526 kEthernetThroughputMbps.value() * 2); 591 kEthernetThroughputMbps.value() * 2);
527 EXPECT_TRUE(VerifyObservations( 592 EXPECT_TRUE(VerifyObservations(
528 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 593 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
529 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, 594 WebEffectiveConnectionType::kType4G, kEthernetHttpRtt.value() * 2,
530 kEthernetThroughputMbps.value() * 2)); 595 kEthernetTransportRtt.value() * 2, kEthernetThroughputMbps.value() * 2));
531 EXPECT_EQ(observer.CallbackCount(), 4); 596 EXPECT_EQ(observer.CallbackCount(), 4);
532 597
533 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 598 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
599 WebEffectiveConnectionType::kType4G,
534 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, 600 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2,
535 kEthernetThroughputMbps.value() * 2); 601 kEthernetThroughputMbps.value() * 2);
536 EXPECT_EQ(observer.CallbackCount(), 4); 602 EXPECT_EQ(observer.CallbackCount(), 4);
537 603
538 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 604 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
539 kEthernetHttpRtt, kEthernetTransportRtt, 605 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
540 kEthernetThroughputMbps); 606 kEthernetTransportRtt, kEthernetThroughputMbps);
541 EXPECT_TRUE(VerifyObservations( 607 EXPECT_TRUE(VerifyObservations(
542 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 608 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
543 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 609 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
610 kEthernetTransportRtt, kEthernetThroughputMbps));
544 EXPECT_EQ(observer.CallbackCount(), 6); 611 EXPECT_EQ(observer.CallbackCount(), 6);
545 612
546 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 613 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
547 } 614 }
548 615
549 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { 616 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) {
550 NetworkStateNotifier notifier; 617 NetworkStateNotifier notifier;
551 StateObserver observer; 618 StateObserver observer;
552 619
553 notifier.AddConnectionObserver(&observer, GetTaskRunner()); 620 notifier.AddConnectionObserver(&observer, GetTaskRunner());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 685
619 notifier_.SetOnLine(false); 686 notifier_.SetOnLine(false);
620 RunPendingTasks(); 687 RunPendingTasks();
621 EXPECT_FALSE(observer1.ObservedOnLineState()); 688 EXPECT_FALSE(observer1.ObservedOnLineState());
622 EXPECT_FALSE(observer2.ObservedOnLineState()); 689 EXPECT_FALSE(observer2.ObservedOnLineState());
623 EXPECT_EQ(observer1.CallbackCount(), 2); 690 EXPECT_EQ(observer1.CallbackCount(), 2);
624 EXPECT_EQ(observer2.CallbackCount(), 2); 691 EXPECT_EQ(observer2.CallbackCount(), 2);
625 692
626 notifier_.SetOnLine(true); 693 notifier_.SetOnLine(true);
627 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 694 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
628 kEthernetHttpRtt, kEthernetTransportRtt, 695 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
629 kEthernetThroughputMbps); 696 kEthernetTransportRtt, kEthernetThroughputMbps);
630 697
631 EXPECT_TRUE(observer1.ObservedOnLineState()); 698 EXPECT_TRUE(observer1.ObservedOnLineState());
632 EXPECT_TRUE(observer2.ObservedOnLineState()); 699 EXPECT_TRUE(observer2.ObservedOnLineState());
633 EXPECT_TRUE(VerifyObservations( 700 EXPECT_TRUE(VerifyObservations(
634 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 701 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
635 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); 702 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
703 kEthernetTransportRtt, kEthernetThroughputMbps));
636 EXPECT_EQ(observer1.CallbackCount(), 3); 704 EXPECT_EQ(observer1.CallbackCount(), 3);
637 EXPECT_EQ(observer2.CallbackCount(), 5); 705 EXPECT_EQ(observer2.CallbackCount(), 5);
638 706
639 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 707 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
640 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 708 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
641 } 709 }
642 710
643 } // namespace blink 711 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698