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(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
150 EXPECT_TRUE(verifyObservations(observer, ConnectionTypeBluetooth, kBluetooth
MaxBandwidthMbps)); | 150 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBlueto
othMaxBandwidthMbps)); |
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(WebConnectionTypeBluetooth, 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, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
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(WebConnectionTypeBluetooth, 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(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
183 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 183 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
184 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 184 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
185 } | 185 } |
186 | 186 |
187 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) | 187 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) |
188 { | 188 { |
189 StateObserver observer1; | 189 StateObserver observer1; |
190 m_notifier.addObserver(&observer1, executionContext()); | 190 m_notifier.addObserver(&observer1, executionContext()); |
191 removeObserverOnNotification(&observer1, &observer1); | 191 removeObserverOnNotification(&observer1, &observer1); |
192 | 192 |
193 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 193 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
194 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 194 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
195 | 195 |
196 setConnection(ConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 196 setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
197 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 197 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
198 } | 198 } |
199 | 199 |
200 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) | 200 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) |
201 { | 201 { |
202 StateObserver observer1, observer2; | 202 StateObserver observer1, observer2; |
203 m_notifier.addObserver(&observer1, executionContext()); | 203 m_notifier.addObserver(&observer1, executionContext()); |
204 m_notifier.addObserver(&observer2, executionContext()); | 204 m_notifier.addObserver(&observer2, executionContext()); |
205 removeObserverOnNotification(&observer1, &observer1); | 205 removeObserverOnNotification(&observer1, &observer1); |
206 | 206 |
207 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 207 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
208 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 208 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
209 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 209 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
210 | 210 |
211 setConnection(ConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 211 setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
212 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 212 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
213 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeEthernet, kEthernetM
axBandwidthMbps)); | 213 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeEthernet, kEthern
etMaxBandwidthMbps)); |
214 } | 214 } |
215 | 215 |
216 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) | 216 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) |
217 { | 217 { |
218 StateObserver observer1, observer2; | 218 StateObserver observer1, observer2; |
219 m_notifier.addObserver(&observer1, executionContext()); | 219 m_notifier.addObserver(&observer1, executionContext()); |
220 m_notifier.addObserver(&observer2, executionContext()); | 220 m_notifier.addObserver(&observer2, executionContext()); |
221 removeObserverOnNotification(&observer2, &observer1); | 221 removeObserverOnNotification(&observer2, &observer1); |
222 | 222 |
223 setConnection(ConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 223 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
224 EXPECT_EQ(observer1.observedType(), ConnectionTypeBluetooth); | 224 EXPECT_EQ(observer1.observedType(), WebConnectionTypeBluetooth); |
225 EXPECT_EQ(observer2.observedType(), ConnectionTypeBluetooth); | 225 EXPECT_EQ(observer2.observedType(), WebConnectionTypeBluetooth); |
226 | 226 |
227 setConnection(ConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 227 setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); |
228 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 228 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
229 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeEthernet, kEthernetM
axBandwidthMbps)); | 229 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeEthernet, kEthern
etMaxBandwidthMbps)); |
230 } | 230 } |
231 | 231 |
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(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
241 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 241 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
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, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
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(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
253 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 253 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
254 EXPECT_TRUE(verifyObservations(observer2, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 254 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
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(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); |
265 EXPECT_TRUE(verifyObservations(observer1, ConnectionTypeBluetooth, kBluetoot
hMaxBandwidthMbps)); | 265 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeBluetooth, kBluet
oothMaxBandwidthMbps)); |
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(WebConnectionTypeBluetooth, 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 |