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

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

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: kinuko comments Created 3 years, 7 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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
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"
37 #include "platform/wtf/Time.h"
36 #include "public/platform/Platform.h" 38 #include "public/platform/Platform.h"
37 #include "public/platform/WebConnectionType.h" 39 #include "public/platform/WebConnectionType.h"
38 #include "public/platform/WebThread.h" 40 #include "public/platform/WebThread.h"
39 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
40 42
41 namespace blink { 43 namespace blink {
42 44
43 using scheduler::FakeWebTaskRunner; 45 using scheduler::FakeWebTaskRunner;
44 46
45 namespace { 47 namespace {
46 const double kNoneMaxBandwidthMbps = 0.0; 48 const double kNoneMaxBandwidthMbps = 0.0;
47 const double kBluetoothMaxBandwidthMbps = 1.0; 49 const double kBluetoothMaxBandwidthMbps = 1.0;
48 const double kEthernetMaxBandwidthMbps = 2.0; 50 const double kEthernetMaxBandwidthMbps = 2.0;
51 const Optional<TimeDelta> kEthernetHttpRtt(TimeDelta::FromMilliseconds(50));
52 const Optional<TimeDelta> kEthernetTransportRtt(
53 TimeDelta::FromMilliseconds(25));
54 const Optional<double> kEthernetThroughputMbps(75.0);
55 const Optional<TimeDelta> kUnknownRtt;
56 const Optional<double> kUnknownThroughputMbps;
49 } 57 }
50 58
51 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { 59 class StateObserver : public NetworkStateNotifier::NetworkStateObserver {
52 public: 60 public:
53 StateObserver() 61 StateObserver()
54 : observed_type_(kWebConnectionTypeNone), 62 : observed_type_(kWebConnectionTypeNone),
55 observed_max_bandwidth_mbps_(0.0), 63 observed_max_bandwidth_mbps_(0.0),
64 observed_http_rtt_(kUnknownRtt),
65 observed_transport_rtt_(kUnknownRtt),
66 observed_downlink_throughput_mbps_(kUnknownThroughputMbps),
56 observed_on_line_state_(false), 67 observed_on_line_state_(false),
57 callback_count_(0) {} 68 callback_count_(0) {}
58 69
59 virtual void ConnectionChange(WebConnectionType type, 70 virtual void ConnectionChange(
60 double max_bandwidth_mbps) { 71 WebConnectionType type,
72 double max_bandwidth_mbps,
73 const Optional<TimeDelta>& http_rtt,
74 const Optional<TimeDelta>& transport_rtt,
75 const Optional<double>& downlink_throughput_mbps) {
61 observed_type_ = type; 76 observed_type_ = type;
62 observed_max_bandwidth_mbps_ = max_bandwidth_mbps; 77 observed_max_bandwidth_mbps_ = max_bandwidth_mbps;
78 observed_http_rtt_ = http_rtt;
79 observed_transport_rtt_ = transport_rtt;
80 observed_downlink_throughput_mbps_ = downlink_throughput_mbps;
63 callback_count_ += 1; 81 callback_count_ += 1;
64 82
65 if (closure_) 83 if (closure_)
66 (*closure_)(); 84 (*closure_)();
67 } 85 }
68 86
69 virtual void OnLineStateChange(bool on_line) { 87 virtual void OnLineStateChange(bool on_line) {
70 observed_on_line_state_ = on_line; 88 observed_on_line_state_ = on_line;
71 callback_count_ += 1; 89 callback_count_ += 1;
72 90
73 if (closure_) 91 if (closure_)
74 (*closure_)(); 92 (*closure_)();
75 } 93 }
76 94
77 WebConnectionType ObservedType() const { return observed_type_; } 95 WebConnectionType ObservedType() const { return observed_type_; }
78 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; } 96 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; }
97 Optional<TimeDelta> ObservedHttpRtt() const { return observed_http_rtt_; }
98 Optional<TimeDelta> ObservedTransportRtt() const {
99 return observed_transport_rtt_;
100 }
101 Optional<double> ObservedDownlinkThroughputMbps() const {
102 return observed_downlink_throughput_mbps_;
103 }
79 bool ObservedOnLineState() const { return observed_on_line_state_; } 104 bool ObservedOnLineState() const { return observed_on_line_state_; }
80 int CallbackCount() const { return callback_count_; } 105 int CallbackCount() const { return callback_count_; }
81 106
82 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) { 107 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) {
83 closure_ = std::move(closure); 108 closure_ = std::move(closure);
84 } 109 }
85 110
86 private: 111 private:
87 std::unique_ptr<WTF::Closure> closure_; 112 std::unique_ptr<WTF::Closure> closure_;
88 WebConnectionType observed_type_; 113 WebConnectionType observed_type_;
89 double observed_max_bandwidth_mbps_; 114 double observed_max_bandwidth_mbps_;
115 Optional<TimeDelta> observed_http_rtt_;
116 Optional<TimeDelta> observed_transport_rtt_;
117 Optional<double> observed_downlink_throughput_mbps_;
90 bool observed_on_line_state_; 118 bool observed_on_line_state_;
91 int callback_count_; 119 int callback_count_;
92 }; 120 };
93 121
94 class NetworkStateNotifierTest : public ::testing::Test { 122 class NetworkStateNotifierTest : public ::testing::Test {
95 public: 123 public:
96 NetworkStateNotifierTest() 124 NetworkStateNotifierTest()
97 : task_runner_(AdoptRef(new FakeWebTaskRunner())), 125 : task_runner_(AdoptRef(new FakeWebTaskRunner())),
98 task_runner2_(AdoptRef(new FakeWebTaskRunner())) { 126 task_runner2_(AdoptRef(new FakeWebTaskRunner())) {
99 // Initialize connection, so that future calls to setWebConnection issue 127 // Initialize connection, so that future calls to setWebConnection issue
(...skipping 10 matching lines...) Expand all
110 task_runner_ = nullptr; 138 task_runner_ = nullptr;
111 task_runner2_ = nullptr; 139 task_runner2_ = nullptr;
112 } 140 }
113 141
114 protected: 142 protected:
115 void RunPendingTasks() { 143 void RunPendingTasks() {
116 task_runner_->RunUntilIdle(); 144 task_runner_->RunUntilIdle();
117 task_runner2_->RunUntilIdle(); 145 task_runner2_->RunUntilIdle();
118 } 146 }
119 147
120 void SetConnection(WebConnectionType type, double max_bandwidth_mbps) { 148 void SetConnection(WebConnectionType type,
149 double max_bandwidth_mbps,
150 const Optional<TimeDelta>& http_rtt,
151 const Optional<TimeDelta>& transport_rtt,
152 const Optional<double>& downlink_throughput_mbps) {
121 notifier_.SetWebConnection(type, max_bandwidth_mbps); 153 notifier_.SetWebConnection(type, max_bandwidth_mbps);
154 notifier_.SetNetworkQuality(
155 http_rtt.has_value() ? http_rtt.value()
156 : base::TimeDelta::FromMilliseconds(-1),
157 transport_rtt.has_value() ? transport_rtt.value()
158 : base::TimeDelta::FromMilliseconds(-1),
159 downlink_throughput_mbps.has_value()
160 ? downlink_throughput_mbps.value() * 1000
161 : -1);
122 RunPendingTasks(); 162 RunPendingTasks();
123 } 163 }
124 void SetOnLine(bool on_line) { 164 void SetOnLine(bool on_line) {
125 notifier_.SetOnLine(on_line); 165 notifier_.SetOnLine(on_line);
126 RunPendingTasks(); 166 RunPendingTasks();
127 } 167 }
128 168
129 void AddObserverOnNotification(StateObserver* observer, 169 void AddObserverOnNotification(StateObserver* observer,
130 StateObserver* observer_to_add) { 170 StateObserver* observer_to_add) {
131 observer->SetNotificationCallback( 171 observer->SetNotificationCallback(
132 Bind(&NetworkStateNotifier::AddConnectionObserver, 172 Bind(&NetworkStateNotifier::AddConnectionObserver,
133 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_add), 173 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_add),
134 WTF::Unretained(GetTaskRunner()))); 174 WTF::Unretained(GetTaskRunner())));
135 } 175 }
136 176
137 void RemoveObserverOnNotification(StateObserver* observer, 177 void RemoveObserverOnNotification(StateObserver* observer,
138 StateObserver* observer_to_remove) { 178 StateObserver* observer_to_remove) {
139 observer->SetNotificationCallback( 179 observer->SetNotificationCallback(
140 Bind(&NetworkStateNotifier::RemoveConnectionObserver, 180 Bind(&NetworkStateNotifier::RemoveConnectionObserver,
141 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_remove), 181 WTF::Unretained(&notifier_), WTF::Unretained(observer_to_remove),
142 WTF::Unretained(GetTaskRunner()))); 182 WTF::Unretained(GetTaskRunner())));
143 } 183 }
144 184
145 bool VerifyObservations(const StateObserver& observer, 185 bool VerifyObservations(
146 WebConnectionType type, 186 const StateObserver& observer,
147 double max_bandwidth_mbps) { 187 WebConnectionType type,
148 EXPECT_EQ(observer.ObservedType(), type); 188 double max_bandwidth_mbps,
149 EXPECT_EQ(observer.ObservedMaxBandwidth(), max_bandwidth_mbps); 189 const Optional<TimeDelta>& http_rtt,
190 const Optional<TimeDelta>& transport_rtt,
191 const Optional<double>& downlink_throughput_mbps) const {
192 EXPECT_EQ(type, observer.ObservedType());
193 EXPECT_EQ(max_bandwidth_mbps, observer.ObservedMaxBandwidth());
194 EXPECT_EQ(http_rtt, observer.ObservedHttpRtt());
195 EXPECT_EQ(transport_rtt, observer.ObservedTransportRtt());
196 EXPECT_EQ(downlink_throughput_mbps,
197 observer.ObservedDownlinkThroughputMbps());
198
150 return observer.ObservedType() == type && 199 return observer.ObservedType() == type &&
151 observer.ObservedMaxBandwidth() == max_bandwidth_mbps; 200 observer.ObservedMaxBandwidth() == max_bandwidth_mbps &&
201 observer.ObservedHttpRtt() == http_rtt &&
202 observer.ObservedTransportRtt() == transport_rtt &&
203 observer.ObservedDownlinkThroughputMbps() ==
204 downlink_throughput_mbps;
152 } 205 }
153 206
154 RefPtr<FakeWebTaskRunner> task_runner_; 207 RefPtr<FakeWebTaskRunner> task_runner_;
155 RefPtr<FakeWebTaskRunner> task_runner2_; 208 RefPtr<FakeWebTaskRunner> task_runner2_;
156 NetworkStateNotifier notifier_; 209 NetworkStateNotifier notifier_;
157 }; 210 };
158 211
159 TEST_F(NetworkStateNotifierTest, AddObserver) { 212 TEST_F(NetworkStateNotifierTest, AddObserver) {
160 StateObserver observer; 213 StateObserver observer;
161 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 214 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
162 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, 215 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone,
163 kNoneMaxBandwidthMbps)); 216 kNoneMaxBandwidthMbps, kUnknownRtt,
217 kUnknownRtt, kUnknownThroughputMbps));
164 218
165 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 219 // Change max. bandwidth and the network quality estimates.
166 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, 220 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
167 kBluetoothMaxBandwidthMbps)); 221 kEthernetHttpRtt, kEthernetTransportRtt,
168 EXPECT_EQ(observer.CallbackCount(), 1); 222 kEthernetThroughputMbps);
223 EXPECT_TRUE(VerifyObservations(
224 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
225 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
226 EXPECT_EQ(observer.CallbackCount(), 2);
227
228 // Only change the connection type.
229 SetConnection(kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps,
230 kEthernetHttpRtt, kEthernetTransportRtt,
231 kEthernetThroughputMbps);
232 EXPECT_TRUE(VerifyObservations(
233 observer, kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps,
234 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
235 EXPECT_EQ(observer.CallbackCount(), 3);
236
237 // Only change the max. bandwidth.
238 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
239 kEthernetHttpRtt, kEthernetTransportRtt,
240 kEthernetThroughputMbps);
241 EXPECT_TRUE(VerifyObservations(
242 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
243 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
244 EXPECT_EQ(observer.CallbackCount(), 4);
245
246 // Only change the transport RTT.
247 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
248 kEthernetHttpRtt, kEthernetTransportRtt.value() * 2,
249 kEthernetThroughputMbps);
250 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet,
251 kEthernetMaxBandwidthMbps, kEthernetHttpRtt,
252 kEthernetTransportRtt.value() * 2,
253 kEthernetThroughputMbps));
254 EXPECT_EQ(observer.CallbackCount(), 5);
255
169 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 256 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
170 } 257 }
171 258
172 TEST_F(NetworkStateNotifierTest, RemoveObserver) { 259 TEST_F(NetworkStateNotifierTest, RemoveObserver) {
173 StateObserver observer1, observer2; 260 StateObserver observer1, observer2;
174 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 261 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
175 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 262 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
176 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 263 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
177 264
178 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 265 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
266 kEthernetHttpRtt, kEthernetTransportRtt,
267 kEthernetThroughputMbps);
268
179 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 269 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone,
180 kNoneMaxBandwidthMbps)); 270 kNoneMaxBandwidthMbps, kUnknownRtt,
181 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 271 kUnknownRtt, kUnknownThroughputMbps));
182 kBluetoothMaxBandwidthMbps)); 272 EXPECT_TRUE(VerifyObservations(
273 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
274 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
183 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 275 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
184 } 276 }
185 277
186 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { 278 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) {
187 StateObserver observer1; 279 StateObserver observer1;
188 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 280 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
189 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 281 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
190 282
191 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 283 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
284 kEthernetHttpRtt, kEthernetTransportRtt,
285 kEthernetThroughputMbps);
192 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 286 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone,
193 kNoneMaxBandwidthMbps)); 287 kNoneMaxBandwidthMbps, kUnknownRtt,
288 kUnknownRtt, kUnknownThroughputMbps));
194 } 289 }
195 290
196 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { 291 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) {
197 StateObserver observer1, observer2; 292 StateObserver observer1, observer2;
198 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 293 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
199 AddObserverOnNotification(&observer1, &observer2); 294 AddObserverOnNotification(&observer1, &observer2);
200 295
201 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 296 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
297 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
202 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 298 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
203 kBluetoothMaxBandwidthMbps)); 299 kBluetoothMaxBandwidthMbps, kUnknownRtt,
300 kUnknownRtt, kUnknownThroughputMbps));
204 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 301 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth,
205 kBluetoothMaxBandwidthMbps)); 302 kBluetoothMaxBandwidthMbps, kUnknownRtt,
303 kUnknownRtt, kUnknownThroughputMbps));
206 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 304 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
207 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 305 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
208 } 306 }
209 307
210 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { 308 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) {
211 StateObserver observer1; 309 StateObserver observer1;
212 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 310 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
213 RemoveObserverOnNotification(&observer1, &observer1); 311 RemoveObserverOnNotification(&observer1, &observer1);
214 312
215 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 313 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
314 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
216 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 315 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
217 kBluetoothMaxBandwidthMbps)); 316 kBluetoothMaxBandwidthMbps, kUnknownRtt,
317 kUnknownRtt, kUnknownThroughputMbps));
218 318
219 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); 319 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
320 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
220 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 321 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
221 kBluetoothMaxBandwidthMbps)); 322 kBluetoothMaxBandwidthMbps, kUnknownRtt,
323 kUnknownRtt, kUnknownThroughputMbps));
222 } 324 }
223 325
224 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { 326 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) {
225 StateObserver observer1, observer2; 327 StateObserver observer1, observer2;
226 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 328 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
227 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 329 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
228 RemoveObserverOnNotification(&observer1, &observer1); 330 RemoveObserverOnNotification(&observer1, &observer1);
229 331
230 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 332 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
333 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
231 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 334 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
232 kBluetoothMaxBandwidthMbps)); 335 kBluetoothMaxBandwidthMbps, kUnknownRtt,
336 kUnknownRtt, kUnknownThroughputMbps));
233 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 337 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth,
234 kBluetoothMaxBandwidthMbps)); 338 kBluetoothMaxBandwidthMbps, kUnknownRtt,
339 kUnknownRtt, kUnknownThroughputMbps));
235 340
236 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); 341 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
342 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
237 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 343 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
238 kBluetoothMaxBandwidthMbps)); 344 kBluetoothMaxBandwidthMbps, kUnknownRtt,
345 kUnknownRtt, kUnknownThroughputMbps));
239 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, 346 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet,
240 kEthernetMaxBandwidthMbps)); 347 kEthernetMaxBandwidthMbps, kUnknownRtt,
348 kUnknownRtt, kUnknownThroughputMbps));
241 349
242 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 350 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
243 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 351 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
244 } 352 }
245 353
246 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { 354 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) {
247 StateObserver observer1, observer2; 355 StateObserver observer1, observer2;
248 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 356 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
249 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 357 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
250 RemoveObserverOnNotification(&observer2, &observer1); 358 RemoveObserverOnNotification(&observer2, &observer1);
251 359
252 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 360 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
361 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
253 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); 362 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth);
254 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); 363 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth);
255 364
256 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); 365 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
366 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
257 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 367 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
258 kBluetoothMaxBandwidthMbps)); 368 kBluetoothMaxBandwidthMbps, kUnknownRtt,
369 kUnknownRtt, kUnknownThroughputMbps));
259 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, 370 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet,
260 kEthernetMaxBandwidthMbps)); 371 kEthernetMaxBandwidthMbps, kUnknownRtt,
372 kUnknownRtt, kUnknownThroughputMbps));
261 373
262 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 374 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
263 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 375 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
264 } 376 }
265 377
266 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { 378 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) {
267 StateObserver observer1, observer2, observer3; 379 StateObserver observer1, observer2, observer3;
268 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 380 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
269 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); 381 notifier_.AddConnectionObserver(&observer2, GetTaskRunner());
270 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); 382 notifier_.AddConnectionObserver(&observer3, GetTaskRunner());
271 RemoveObserverOnNotification(&observer1, &observer2); 383 RemoveObserverOnNotification(&observer1, &observer2);
272 384
273 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 385 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
386 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
274 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 387 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth,
275 kBluetoothMaxBandwidthMbps)); 388 kBluetoothMaxBandwidthMbps, kUnknownRtt,
389 kUnknownRtt, kUnknownThroughputMbps));
276 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 390 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone,
277 kNoneMaxBandwidthMbps)); 391 kNoneMaxBandwidthMbps, kUnknownRtt,
392 kUnknownRtt, kUnknownThroughputMbps));
278 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, 393 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth,
279 kBluetoothMaxBandwidthMbps)); 394 kBluetoothMaxBandwidthMbps, kUnknownRtt,
395 kUnknownRtt, kUnknownThroughputMbps));
280 396
281 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 397 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
282 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 398 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
283 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); 399 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner());
284 } 400 }
285 401
286 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { 402 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) {
287 StateObserver observer1, observer2; 403 StateObserver observer1, observer2;
288 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 404 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
289 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 405 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
290 406
291 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 407 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
292 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 408 kEthernetHttpRtt, kEthernetTransportRtt,
293 kBluetoothMaxBandwidthMbps)); 409 kEthernetThroughputMbps);
294 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, 410 EXPECT_TRUE(VerifyObservations(
295 kBluetoothMaxBandwidthMbps)); 411 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
412 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
413 EXPECT_TRUE(VerifyObservations(
414 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
415 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
296 416
297 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 417 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
298 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 418 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
299 } 419 }
300 420
301 TEST_F(NetworkStateNotifierTest, RemoveContext) { 421 TEST_F(NetworkStateNotifierTest, RemoveContext) {
302 StateObserver observer1, observer2; 422 StateObserver observer1, observer2;
303 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 423 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
304 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 424 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
305 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 425 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
306 426
307 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 427 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
308 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, 428 kEthernetHttpRtt, kEthernetTransportRtt,
309 kBluetoothMaxBandwidthMbps)); 429 kEthernetThroughputMbps);
430 EXPECT_TRUE(VerifyObservations(
431 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
432 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
310 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 433 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone,
311 kNoneMaxBandwidthMbps)); 434 kNoneMaxBandwidthMbps, kUnknownRtt,
435 kUnknownRtt, kUnknownThroughputMbps));
312 436
313 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 437 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
314 } 438 }
315 439
316 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { 440 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) {
317 StateObserver observer1, observer2; 441 StateObserver observer1, observer2;
318 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); 442 notifier_.AddConnectionObserver(&observer1, GetTaskRunner());
319 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); 443 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2());
320 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 444 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
321 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); 445 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2());
322 446
323 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 447 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
448 kEthernetHttpRtt, kEthernetTransportRtt,
449 kEthernetThroughputMbps);
324 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, 450 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone,
325 kNoneMaxBandwidthMbps)); 451 kNoneMaxBandwidthMbps, kUnknownRtt,
452 kUnknownRtt, kUnknownThroughputMbps));
326 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, 453 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone,
327 kNoneMaxBandwidthMbps)); 454 kNoneMaxBandwidthMbps, kUnknownRtt,
455 kUnknownRtt, kUnknownThroughputMbps));
328 } 456 }
329 457
330 TEST_F(NetworkStateNotifierTest, SetOverride) { 458 TEST_F(NetworkStateNotifierTest, SetOverride) {
331 StateObserver observer; 459 StateObserver observer;
332 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 460 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
333 461
334 notifier_.SetOnLine(true); 462 notifier_.SetOnLine(true);
335 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 463 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
464 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps);
336 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, 465 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth,
337 kBluetoothMaxBandwidthMbps)); 466 kBluetoothMaxBandwidthMbps, kUnknownRtt,
467 kUnknownRtt, kUnknownThroughputMbps));
338 EXPECT_TRUE(notifier_.OnLine()); 468 EXPECT_TRUE(notifier_.OnLine());
339 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); 469 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType());
340 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); 470 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth());
341 471
342 notifier_.SetOverride(true, kWebConnectionTypeEthernet, 472 notifier_.SetOverride(true, kWebConnectionTypeEthernet,
343 kEthernetMaxBandwidthMbps); 473 kEthernetMaxBandwidthMbps);
344 RunPendingTasks(); 474 RunPendingTasks();
345 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, 475 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet,
346 kEthernetMaxBandwidthMbps)); 476 kEthernetMaxBandwidthMbps, kUnknownRtt,
477 kUnknownRtt, kUnknownThroughputMbps));
347 EXPECT_TRUE(notifier_.OnLine()); 478 EXPECT_TRUE(notifier_.OnLine());
348 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); 479 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
349 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); 480 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
350 481
351 // When override is active, calls to setOnLine and setConnection are temporary 482 // When override is active, calls to setOnLine and setConnection are temporary
352 // ignored. 483 // ignored.
353 notifier_.SetOnLine(false); 484 notifier_.SetOnLine(false);
354 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps); 485 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps, kUnknownRtt,
486 kUnknownRtt, kUnknownThroughputMbps);
355 RunPendingTasks(); 487 RunPendingTasks();
356 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, 488 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet,
357 kEthernetMaxBandwidthMbps)); 489 kEthernetMaxBandwidthMbps, kUnknownRtt,
490 kUnknownRtt, kUnknownThroughputMbps));
358 EXPECT_TRUE(notifier_.OnLine()); 491 EXPECT_TRUE(notifier_.OnLine());
359 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); 492 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
360 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); 493 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
361 494
362 notifier_.ClearOverride(); 495 notifier_.ClearOverride();
363 RunPendingTasks(); 496 RunPendingTasks();
364 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, 497 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone,
365 kNoneMaxBandwidthMbps)); 498 kNoneMaxBandwidthMbps, kUnknownRtt,
499 kUnknownRtt, kUnknownThroughputMbps));
366 EXPECT_FALSE(notifier_.OnLine()); 500 EXPECT_FALSE(notifier_.OnLine());
367 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); 501 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType());
368 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); 502 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth());
369 503
370 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 504 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
371 } 505 }
372 506
373 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { 507 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) {
374 StateObserver observer; 508 StateObserver observer;
375 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 509 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
376 510
377 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 511 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
378 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, 512 kEthernetHttpRtt, kEthernetTransportRtt,
379 kBluetoothMaxBandwidthMbps)); 513 kEthernetThroughputMbps);
380 EXPECT_EQ(observer.CallbackCount(), 1); 514 EXPECT_TRUE(VerifyObservations(
381 515 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
382 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 516 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
383 EXPECT_EQ(observer.CallbackCount(), 1);
384
385 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps);
386 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet,
387 kEthernetMaxBandwidthMbps));
388 EXPECT_EQ(observer.CallbackCount(), 2); 517 EXPECT_EQ(observer.CallbackCount(), 2);
389 518
390 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); 519 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
520 kEthernetHttpRtt, kEthernetTransportRtt,
521 kEthernetThroughputMbps);
391 EXPECT_EQ(observer.CallbackCount(), 2); 522 EXPECT_EQ(observer.CallbackCount(), 2);
392 523
393 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 524 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
394 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, 525 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2,
395 kBluetoothMaxBandwidthMbps)); 526 kEthernetThroughputMbps.value() * 2);
396 EXPECT_EQ(observer.CallbackCount(), 3); 527 EXPECT_TRUE(VerifyObservations(
528 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
529 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2,
530 kEthernetThroughputMbps.value() * 2));
531 EXPECT_EQ(observer.CallbackCount(), 4);
532
533 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
534 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2,
535 kEthernetThroughputMbps.value() * 2);
536 EXPECT_EQ(observer.CallbackCount(), 4);
537
538 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
539 kEthernetHttpRtt, kEthernetTransportRtt,
540 kEthernetThroughputMbps);
541 EXPECT_TRUE(VerifyObservations(
542 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
543 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
544 EXPECT_EQ(observer.CallbackCount(), 6);
397 545
398 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 546 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
399 } 547 }
400 548
401 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { 549 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) {
402 NetworkStateNotifier notifier; 550 NetworkStateNotifier notifier;
403 StateObserver observer; 551 StateObserver observer;
404 552
405 notifier.AddConnectionObserver(&observer, GetTaskRunner()); 553 notifier.AddConnectionObserver(&observer, GetTaskRunner());
406 notifier.AddOnLineObserver(&observer, GetTaskRunner()); 554 notifier.AddOnLineObserver(&observer, GetTaskRunner());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 EXPECT_EQ(observer2.CallbackCount(), 1); 617 EXPECT_EQ(observer2.CallbackCount(), 1);
470 618
471 notifier_.SetOnLine(false); 619 notifier_.SetOnLine(false);
472 RunPendingTasks(); 620 RunPendingTasks();
473 EXPECT_FALSE(observer1.ObservedOnLineState()); 621 EXPECT_FALSE(observer1.ObservedOnLineState());
474 EXPECT_FALSE(observer2.ObservedOnLineState()); 622 EXPECT_FALSE(observer2.ObservedOnLineState());
475 EXPECT_EQ(observer1.CallbackCount(), 2); 623 EXPECT_EQ(observer1.CallbackCount(), 2);
476 EXPECT_EQ(observer2.CallbackCount(), 2); 624 EXPECT_EQ(observer2.CallbackCount(), 2);
477 625
478 notifier_.SetOnLine(true); 626 notifier_.SetOnLine(true);
479 notifier_.SetWebConnection(kWebConnectionTypeEthernet, 627 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
480 kEthernetMaxBandwidthMbps); 628 kEthernetHttpRtt, kEthernetTransportRtt,
481 RunPendingTasks(); 629 kEthernetThroughputMbps);
630
482 EXPECT_TRUE(observer1.ObservedOnLineState()); 631 EXPECT_TRUE(observer1.ObservedOnLineState());
483 EXPECT_TRUE(observer2.ObservedOnLineState()); 632 EXPECT_TRUE(observer2.ObservedOnLineState());
484 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, 633 EXPECT_TRUE(VerifyObservations(
485 kEthernetMaxBandwidthMbps)); 634 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
635 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps));
486 EXPECT_EQ(observer1.CallbackCount(), 3); 636 EXPECT_EQ(observer1.CallbackCount(), 3);
487 EXPECT_EQ(observer2.CallbackCount(), 4); 637 EXPECT_EQ(observer2.CallbackCount(), 5);
488 638
489 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 639 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
490 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 640 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
491 } 641 }
492 642
493 } // namespace blink 643 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698