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