| 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)); |
| 207 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 208 kEthernetHttpRtt, kEthernetTransportRtt, |
| 209 kEthernetThroughputMbps); |
| 210 EXPECT_TRUE(VerifyObservations( |
| 211 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 212 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 213 EXPECT_EQ(observer.CallbackCount(), 2); |
| 164 | 214 |
| 165 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | |
| 166 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | |
| 167 kBluetoothMaxBandwidthMbps)); | |
| 168 EXPECT_EQ(observer.CallbackCount(), 1); | |
| 169 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 215 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
| 170 } | 216 } |
| 171 | 217 |
| 172 TEST_F(NetworkStateNotifierTest, RemoveObserver) { | 218 TEST_F(NetworkStateNotifierTest, RemoveObserver) { |
| 173 StateObserver observer1, observer2; | 219 StateObserver observer1, observer2; |
| 174 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 220 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 175 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 221 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 176 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 222 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
| 177 | 223 |
| 178 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 224 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 225 kEthernetHttpRtt, kEthernetTransportRtt, |
| 226 kEthernetThroughputMbps); |
| 227 |
| 179 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 228 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
| 180 kNoneMaxBandwidthMbps)); | 229 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 181 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 230 kUnknownRtt, kUnknownThroughputMbps)); |
| 182 kBluetoothMaxBandwidthMbps)); | 231 EXPECT_TRUE(VerifyObservations( |
| 232 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 233 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 183 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 234 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 184 } | 235 } |
| 185 | 236 |
| 186 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { | 237 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { |
| 187 StateObserver observer1; | 238 StateObserver observer1; |
| 188 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 239 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 189 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 240 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 190 | 241 |
| 191 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 242 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 243 kEthernetHttpRtt, kEthernetTransportRtt, |
| 244 kEthernetThroughputMbps); |
| 192 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 245 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
| 193 kNoneMaxBandwidthMbps)); | 246 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 247 kUnknownRtt, kUnknownThroughputMbps)); |
| 194 } | 248 } |
| 195 | 249 |
| 196 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { | 250 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { |
| 197 StateObserver observer1, observer2; | 251 StateObserver observer1, observer2; |
| 198 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 252 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 199 AddObserverOnNotification(&observer1, &observer2); | 253 AddObserverOnNotification(&observer1, &observer2); |
| 200 | 254 |
| 201 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 255 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 256 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 202 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 257 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 203 kBluetoothMaxBandwidthMbps)); | 258 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 259 kUnknownRtt, kUnknownThroughputMbps)); |
| 204 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 260 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, |
| 205 kBluetoothMaxBandwidthMbps)); | 261 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 262 kUnknownRtt, kUnknownThroughputMbps)); |
| 206 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 263 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 207 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 264 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 208 } | 265 } |
| 209 | 266 |
| 210 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { | 267 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { |
| 211 StateObserver observer1; | 268 StateObserver observer1; |
| 212 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 269 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 213 RemoveObserverOnNotification(&observer1, &observer1); | 270 RemoveObserverOnNotification(&observer1, &observer1); |
| 214 | 271 |
| 215 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 272 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 273 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 216 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 274 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 217 kBluetoothMaxBandwidthMbps)); | 275 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 276 kUnknownRtt, kUnknownRtt)); |
| 218 | 277 |
| 219 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 278 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 279 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 220 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 280 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 221 kBluetoothMaxBandwidthMbps)); | 281 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 282 kUnknownRtt, kUnknownThroughputMbps)); |
| 222 } | 283 } |
| 223 | 284 |
| 224 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { | 285 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { |
| 225 StateObserver observer1, observer2; | 286 StateObserver observer1, observer2; |
| 226 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 287 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 227 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 288 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
| 228 RemoveObserverOnNotification(&observer1, &observer1); | 289 RemoveObserverOnNotification(&observer1, &observer1); |
| 229 | 290 |
| 230 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 291 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 292 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 231 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 293 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 232 kBluetoothMaxBandwidthMbps)); | 294 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 295 kUnknownRtt, kUnknownThroughputMbps)); |
| 233 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 296 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, |
| 234 kBluetoothMaxBandwidthMbps)); | 297 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 298 kUnknownRtt, kUnknownThroughputMbps)); |
| 235 | 299 |
| 236 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 300 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 301 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 237 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 302 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 238 kBluetoothMaxBandwidthMbps)); | 303 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 304 kUnknownRtt, kUnknownThroughputMbps)); |
| 239 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 305 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, |
| 240 kEthernetMaxBandwidthMbps)); | 306 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 307 kUnknownRtt, kUnknownThroughputMbps)); |
| 241 | 308 |
| 242 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 309 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 243 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 310 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 244 } | 311 } |
| 245 | 312 |
| 246 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { | 313 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { |
| 247 StateObserver observer1, observer2; | 314 StateObserver observer1, observer2; |
| 248 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 315 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 249 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 316 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
| 250 RemoveObserverOnNotification(&observer2, &observer1); | 317 RemoveObserverOnNotification(&observer2, &observer1); |
| 251 | 318 |
| 252 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 319 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 320 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 253 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); | 321 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); |
| 254 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); | 322 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); |
| 255 | 323 |
| 256 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 324 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 325 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 257 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 326 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 258 kBluetoothMaxBandwidthMbps)); | 327 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 328 kUnknownRtt, kUnknownThroughputMbps)); |
| 259 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 329 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, |
| 260 kEthernetMaxBandwidthMbps)); | 330 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 331 kUnknownRtt, kUnknownThroughputMbps)); |
| 261 | 332 |
| 262 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 333 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 263 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 334 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 264 } | 335 } |
| 265 | 336 |
| 266 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { | 337 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { |
| 267 StateObserver observer1, observer2, observer3; | 338 StateObserver observer1, observer2, observer3; |
| 268 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 339 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 269 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 340 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
| 270 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); | 341 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); |
| 271 RemoveObserverOnNotification(&observer1, &observer2); | 342 RemoveObserverOnNotification(&observer1, &observer2); |
| 272 | 343 |
| 273 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 344 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 345 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 274 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 346 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
| 275 kBluetoothMaxBandwidthMbps)); | 347 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 348 kUnknownRtt, kUnknownThroughputMbps)); |
| 276 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 349 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
| 277 kNoneMaxBandwidthMbps)); | 350 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 351 kUnknownRtt, kUnknownThroughputMbps)); |
| 278 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, | 352 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, |
| 279 kBluetoothMaxBandwidthMbps)); | 353 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 354 kUnknownRtt, kUnknownThroughputMbps)); |
| 280 | 355 |
| 281 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 356 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 282 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 357 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 283 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); | 358 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); |
| 284 } | 359 } |
| 285 | 360 |
| 286 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { | 361 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { |
| 287 StateObserver observer1, observer2; | 362 StateObserver observer1, observer2; |
| 288 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 363 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 289 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 364 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
| 290 | 365 |
| 291 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 366 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 292 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 367 kEthernetHttpRtt, kEthernetTransportRtt, |
| 293 kBluetoothMaxBandwidthMbps)); | 368 kEthernetThroughputMbps); |
| 294 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 369 EXPECT_TRUE(VerifyObservations( |
| 295 kBluetoothMaxBandwidthMbps)); | 370 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 371 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 372 EXPECT_TRUE(VerifyObservations( |
| 373 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 374 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 296 | 375 |
| 297 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 376 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 298 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 377 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
| 299 } | 378 } |
| 300 | 379 |
| 301 TEST_F(NetworkStateNotifierTest, RemoveContext) { | 380 TEST_F(NetworkStateNotifierTest, RemoveContext) { |
| 302 StateObserver observer1, observer2; | 381 StateObserver observer1, observer2; |
| 303 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 382 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 304 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 383 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
| 305 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 384 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
| 306 | 385 |
| 307 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 386 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 308 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 387 kEthernetHttpRtt, kEthernetTransportRtt, |
| 309 kBluetoothMaxBandwidthMbps)); | 388 kEthernetThroughputMbps); |
| 389 EXPECT_TRUE(VerifyObservations( |
| 390 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 391 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 310 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 392 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
| 311 kNoneMaxBandwidthMbps)); | 393 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 394 kUnknownRtt, kUnknownThroughputMbps)); |
| 312 | 395 |
| 313 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 396 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 314 } | 397 } |
| 315 | 398 |
| 316 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { | 399 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { |
| 317 StateObserver observer1, observer2; | 400 StateObserver observer1, observer2; |
| 318 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 401 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
| 319 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 402 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
| 320 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 403 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 321 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 404 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
| 322 | 405 |
| 323 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 406 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 407 kEthernetHttpRtt, kEthernetTransportRtt, |
| 408 kEthernetThroughputMbps); |
| 324 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 409 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
| 325 kNoneMaxBandwidthMbps)); | 410 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 411 kUnknownRtt, kUnknownThroughputMbps)); |
| 326 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 412 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
| 327 kNoneMaxBandwidthMbps)); | 413 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 414 kUnknownRtt, kUnknownThroughputMbps)); |
| 328 } | 415 } |
| 329 | 416 |
| 330 TEST_F(NetworkStateNotifierTest, SetOverride) { | 417 TEST_F(NetworkStateNotifierTest, SetOverride) { |
| 331 StateObserver observer; | 418 StateObserver observer; |
| 332 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); | 419 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); |
| 333 | 420 |
| 334 notifier_.SetOnLine(true); | 421 notifier_.SetOnLine(true); |
| 335 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 422 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 423 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
| 336 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 424 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, |
| 337 kBluetoothMaxBandwidthMbps)); | 425 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 426 kUnknownRtt, kUnknownThroughputMbps)); |
| 338 EXPECT_TRUE(notifier_.OnLine()); | 427 EXPECT_TRUE(notifier_.OnLine()); |
| 339 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); | 428 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); |
| 340 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); | 429 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); |
| 341 | 430 |
| 342 notifier_.SetOverride(true, kWebConnectionTypeEthernet, | 431 notifier_.SetOverride(true, kWebConnectionTypeEthernet, |
| 343 kEthernetMaxBandwidthMbps); | 432 kEthernetMaxBandwidthMbps); |
| 344 RunPendingTasks(); | 433 RunPendingTasks(); |
| 345 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, | 434 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, |
| 346 kEthernetMaxBandwidthMbps)); | 435 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 436 kUnknownRtt, kUnknownThroughputMbps)); |
| 347 EXPECT_TRUE(notifier_.OnLine()); | 437 EXPECT_TRUE(notifier_.OnLine()); |
| 348 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); | 438 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); |
| 349 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); | 439 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); |
| 350 | 440 |
| 351 // When override is active, calls to setOnLine and setConnection are temporary | 441 // When override is active, calls to setOnLine and setConnection are temporary |
| 352 // ignored. | 442 // ignored. |
| 353 notifier_.SetOnLine(false); | 443 notifier_.SetOnLine(false); |
| 354 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps); | 444 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps, kUnknownRtt, |
| 445 kUnknownRtt, kUnknownThroughputMbps); |
| 355 RunPendingTasks(); | 446 RunPendingTasks(); |
| 356 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, | 447 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, |
| 357 kEthernetMaxBandwidthMbps)); | 448 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 449 kUnknownRtt, kUnknownThroughputMbps)); |
| 358 EXPECT_TRUE(notifier_.OnLine()); | 450 EXPECT_TRUE(notifier_.OnLine()); |
| 359 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); | 451 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); |
| 360 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); | 452 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); |
| 361 | 453 |
| 362 notifier_.ClearOverride(); | 454 notifier_.ClearOverride(); |
| 363 RunPendingTasks(); | 455 RunPendingTasks(); |
| 364 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, | 456 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, |
| 365 kNoneMaxBandwidthMbps)); | 457 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 458 kUnknownRtt, kUnknownThroughputMbps)); |
| 366 EXPECT_FALSE(notifier_.OnLine()); | 459 EXPECT_FALSE(notifier_.OnLine()); |
| 367 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); | 460 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); |
| 368 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); | 461 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); |
| 369 | 462 |
| 370 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 463 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
| 371 } | 464 } |
| 372 | 465 |
| 373 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { | 466 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { |
| 374 StateObserver observer; | 467 StateObserver observer; |
| 375 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); | 468 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); |
| 376 | 469 |
| 377 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 470 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 378 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 471 kEthernetHttpRtt, kEthernetTransportRtt, |
| 379 kBluetoothMaxBandwidthMbps)); | 472 kEthernetThroughputMbps); |
| 380 EXPECT_EQ(observer.CallbackCount(), 1); | 473 EXPECT_TRUE(VerifyObservations( |
| 381 | 474 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 382 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 475 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); | 476 EXPECT_EQ(observer.CallbackCount(), 2); |
| 389 | 477 |
| 390 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 478 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 479 kEthernetHttpRtt, kEthernetTransportRtt, |
| 480 kEthernetThroughputMbps); |
| 391 EXPECT_EQ(observer.CallbackCount(), 2); | 481 EXPECT_EQ(observer.CallbackCount(), 2); |
| 392 | 482 |
| 393 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 483 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 394 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 484 kEthernetHttpRtt * 2, kEthernetTransportRtt * 2, |
| 395 kBluetoothMaxBandwidthMbps)); | 485 kEthernetThroughputMbps * 2); |
| 396 EXPECT_EQ(observer.CallbackCount(), 3); | 486 EXPECT_TRUE(VerifyObservations( |
| 487 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 488 kEthernetHttpRtt * 2, kEthernetTransportRtt * 2, |
| 489 kEthernetThroughputMbps * 2)); |
| 490 EXPECT_EQ(observer.CallbackCount(), 4); |
| 491 |
| 492 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 493 kEthernetHttpRtt * 2, kEthernetTransportRtt * 2, |
| 494 kEthernetThroughputMbps * 2); |
| 495 EXPECT_EQ(observer.CallbackCount(), 4); |
| 496 |
| 497 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 498 kEthernetHttpRtt, kEthernetTransportRtt, |
| 499 kEthernetThroughputMbps); |
| 500 EXPECT_TRUE(VerifyObservations( |
| 501 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 502 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 503 EXPECT_EQ(observer.CallbackCount(), 6); |
| 397 | 504 |
| 398 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 505 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
| 399 } | 506 } |
| 400 | 507 |
| 401 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { | 508 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { |
| 402 NetworkStateNotifier notifier; | 509 NetworkStateNotifier notifier; |
| 403 StateObserver observer; | 510 StateObserver observer; |
| 404 | 511 |
| 405 notifier.AddConnectionObserver(&observer, GetTaskRunner()); | 512 notifier.AddConnectionObserver(&observer, GetTaskRunner()); |
| 406 notifier.AddOnLineObserver(&observer, GetTaskRunner()); | 513 notifier.AddOnLineObserver(&observer, GetTaskRunner()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 EXPECT_EQ(observer2.CallbackCount(), 1); | 576 EXPECT_EQ(observer2.CallbackCount(), 1); |
| 470 | 577 |
| 471 notifier_.SetOnLine(false); | 578 notifier_.SetOnLine(false); |
| 472 RunPendingTasks(); | 579 RunPendingTasks(); |
| 473 EXPECT_FALSE(observer1.ObservedOnLineState()); | 580 EXPECT_FALSE(observer1.ObservedOnLineState()); |
| 474 EXPECT_FALSE(observer2.ObservedOnLineState()); | 581 EXPECT_FALSE(observer2.ObservedOnLineState()); |
| 475 EXPECT_EQ(observer1.CallbackCount(), 2); | 582 EXPECT_EQ(observer1.CallbackCount(), 2); |
| 476 EXPECT_EQ(observer2.CallbackCount(), 2); | 583 EXPECT_EQ(observer2.CallbackCount(), 2); |
| 477 | 584 |
| 478 notifier_.SetOnLine(true); | 585 notifier_.SetOnLine(true); |
| 479 notifier_.SetWebConnection(kWebConnectionTypeEthernet, | 586 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 480 kEthernetMaxBandwidthMbps); | 587 kEthernetHttpRtt, kEthernetTransportRtt, |
| 481 RunPendingTasks(); | 588 kEthernetThroughputMbps); |
| 589 |
| 482 EXPECT_TRUE(observer1.ObservedOnLineState()); | 590 EXPECT_TRUE(observer1.ObservedOnLineState()); |
| 483 EXPECT_TRUE(observer2.ObservedOnLineState()); | 591 EXPECT_TRUE(observer2.ObservedOnLineState()); |
| 484 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 592 EXPECT_TRUE(VerifyObservations( |
| 485 kEthernetMaxBandwidthMbps)); | 593 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 594 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 486 EXPECT_EQ(observer1.CallbackCount(), 3); | 595 EXPECT_EQ(observer1.CallbackCount(), 3); |
| 487 EXPECT_EQ(observer2.CallbackCount(), 4); | 596 EXPECT_EQ(observer2.CallbackCount(), 5); |
| 488 | 597 |
| 489 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 598 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
| 490 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 599 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
| 491 } | 600 } |
| 492 | 601 |
| 493 } // namespace blink | 602 } // namespace blink |
| OLD | NEW |