| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 const double kNoneMaxBandwidthMbps = 0.0; | 45 const double kNoneMaxBandwidthMbps = 0.0; |
| 46 const double kBluetoothMaxBandwidthMbps = 1.0; | 46 const double kBluetoothMaxBandwidthMbps = 1.0; |
| 47 const double kEthernetMaxBandwidthMbps = 2.0; | 47 const double kEthernetMaxBandwidthMbps = 2.0; |
| 48 } | 48 } |
| 49 | 49 |
| 50 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { | 50 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { |
| 51 public: | 51 public: |
| 52 StateObserver() | 52 StateObserver() |
| 53 : m_observedType(ConnectionTypeNone) | 53 : m_observedType(WebConnectionTypeNone) |
| 54 , m_observedMaxBandwidthMbps(0.0) | 54 , m_observedMaxBandwidthMbps(0.0) |
| 55 , m_callbackCount(0) | 55 , m_callbackCount(0) |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void connectionChange(WebConnectionType type, double maxBandwidthMbp
s) | 59 virtual void connectionChange(WebConnectionType type, double maxBandwidthMbp
s) |
| 60 { | 60 { |
| 61 m_observedType = type; | 61 m_observedType = type; |
| 62 m_observedMaxBandwidthMbps = maxBandwidthMbps; | 62 m_observedMaxBandwidthMbps = maxBandwidthMbps; |
| 63 m_callbackCount += 1; | 63 m_callbackCount += 1; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 RefPtrWillBePersistent<Document> m_document; | 138 RefPtrWillBePersistent<Document> m_document; |
| 139 RefPtrWillBePersistent<Document> m_document2; | 139 RefPtrWillBePersistent<Document> m_document2; |
| 140 NetworkStateNotifier m_notifier; | 140 NetworkStateNotifier m_notifier; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 TEST_F(NetworkStateNotifierTest, AddObserver) | 143 TEST_F(NetworkStateNotifierTest, AddObserver) |
| 144 { | 144 { |
| 145 StateObserver observer; | 145 StateObserver observer; |
| 146 m_notifier.addObserver(&observer, executionContext()); | 146 m_notifier.addObserver(&observer, executionContext()); |
| 147 EXPECT_TRUE(verifyObservations(observer, ConnectionTypeNone, kNoneMaxBandwid
thMbps)); | 147 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeNone, kNoneMaxBand
widthMbps)); |
| 148 | 148 |
| 149 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 149 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 150 EXPECT_TRUE(verifyObservations(observer, ConnectionTypeBluetooth, kBluetooth
MaxBandwidthMbps)); | 150 EXPECT_TRUE(verifyObservations(observer, ConnectionTypeBluetooth, kBluetooth
MaxBandwidthMbps)); |
| 151 EXPECT_EQ(observer.callbackCount(), 1); | 151 EXPECT_EQ(observer.callbackCount(), 1); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(NetworkStateNotifierTest, RemoveObserver) | 154 TEST_F(NetworkStateNotifierTest, RemoveObserver) |
| 155 { | 155 { |
| 156 StateObserver observer1, observer2; | 156 StateObserver observer1, observer2; |
| 157 m_notifier.addObserver(&observer1, executionContext()); | 157 m_notifier.addObserver(&observer1, executionContext()); |
| 158 m_notifier.removeObserver(&observer1, executionContext()); | 158 m_notifier.removeObserver(&observer1, executionContext()); |
| 159 m_notifier.addObserver(&observer2, executionContext()); | 159 m_notifier.addObserver(&observer2, executionContext()); |
| 160 | 160 |
| 161 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 161 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 162 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 162 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 163 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 163 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) | 166 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) |
| 167 { | 167 { |
| 168 StateObserver observer1; | 168 StateObserver observer1; |
| 169 m_notifier.addObserver(&observer1, executionContext()); | 169 m_notifier.addObserver(&observer1, executionContext()); |
| 170 m_notifier.removeObserver(&observer1, executionContext()); | 170 m_notifier.removeObserver(&observer1, executionContext()); |
| 171 | 171 |
| 172 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 172 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 173 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 173 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) | 176 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) |
| 177 { | 177 { |
| 178 StateObserver observer1, observer2; | 178 StateObserver observer1, observer2; |
| 179 m_notifier.addObserver(&observer1, executionContext()); | 179 m_notifier.addObserver(&observer1, executionContext()); |
| 180 addObserverOnNotification(&observer1, &observer2); | 180 addObserverOnNotification(&observer1, &observer2); |
| 181 | 181 |
| 182 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 182 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 183 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 183 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) | 232 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) |
| 233 { | 233 { |
| 234 StateObserver observer1, observer2, observer3; | 234 StateObserver observer1, observer2, observer3; |
| 235 m_notifier.addObserver(&observer1, executionContext()); | 235 m_notifier.addObserver(&observer1, executionContext()); |
| 236 m_notifier.addObserver(&observer2, executionContext()); | 236 m_notifier.addObserver(&observer2, executionContext()); |
| 237 m_notifier.addObserver(&observer3, executionContext()); | 237 m_notifier.addObserver(&observer3, executionContext()); |
| 238 removeObserverOnNotification(&observer1, &observer2); | 238 removeObserverOnNotification(&observer1, &observer2); |
| 239 | 239 |
| 240 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 240 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 241 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 241 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 242 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 242 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 243 EXPECT_TRUE(verifyObservations(observer3, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 243 EXPECT_TRUE(verifyObservations(observer3, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) | 246 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) |
| 247 { | 247 { |
| 248 StateObserver observer1, observer2; | 248 StateObserver observer1, observer2; |
| 249 m_notifier.addObserver(&observer1, executionContext()); | 249 m_notifier.addObserver(&observer1, executionContext()); |
| 250 m_notifier.addObserver(&observer2, executionContext2()); | 250 m_notifier.addObserver(&observer2, executionContext2()); |
| 251 | 251 |
| 252 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 252 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 253 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 253 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 254 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 254 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(NetworkStateNotifierTest, RemoveContext) | 257 TEST_F(NetworkStateNotifierTest, RemoveContext) |
| 258 { | 258 { |
| 259 StateObserver observer1, observer2; | 259 StateObserver observer1, observer2; |
| 260 m_notifier.addObserver(&observer1, executionContext()); | 260 m_notifier.addObserver(&observer1, executionContext()); |
| 261 m_notifier.addObserver(&observer2, executionContext2()); | 261 m_notifier.addObserver(&observer2, executionContext2()); |
| 262 m_notifier.removeObserver(&observer2, executionContext2()); | 262 m_notifier.removeObserver(&observer2, executionContext2()); |
| 263 | 263 |
| 264 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 264 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 265 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 265 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); |
| 266 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 266 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) | 269 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) |
| 270 { | 270 { |
| 271 StateObserver observer1, observer2; | 271 StateObserver observer1, observer2; |
| 272 m_notifier.addObserver(&observer1, executionContext()); | 272 m_notifier.addObserver(&observer1, executionContext()); |
| 273 m_notifier.addObserver(&observer2, executionContext2()); | 273 m_notifier.addObserver(&observer2, executionContext2()); |
| 274 m_notifier.removeObserver(&observer1, executionContext()); | 274 m_notifier.removeObserver(&observer1, executionContext()); |
| 275 m_notifier.removeObserver(&observer2, executionContext2()); | 275 m_notifier.removeObserver(&observer2, executionContext2()); |
| 276 | 276 |
| 277 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 277 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
| 278 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 278 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 279 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeNone, kNoneMaxBandwi
dthMbps)); | 279 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBan
dwidthMbps)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 } // namespace blink | 282 } // namespace blink |
| OLD | NEW |