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

Side by Side Diff: third_party/WebKit/Source/core/page/NetworkStateNotifierTest.cpp

Issue 2087293003: [DevTools] Network.emulateNetworkConditions now affects NetworkStateNotifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheck Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 double m_observedMaxBandwidthMbps; 91 double m_observedMaxBandwidthMbps;
92 int m_callbackCount; 92 int m_callbackCount;
93 }; 93 };
94 94
95 class NetworkStateNotifierTest : public ::testing::Test { 95 class NetworkStateNotifierTest : public ::testing::Test {
96 public: 96 public:
97 NetworkStateNotifierTest() 97 NetworkStateNotifierTest()
98 : m_document(Document::create()) 98 : m_document(Document::create())
99 , m_document2(Document::create()) 99 , m_document2(Document::create())
100 { 100 {
101 // Initialize connection, so that future calls to setWebConnection issue notifications.
102 m_notifier.setWebConnection(WebConnectionTypeUnknown, 0.0);
101 } 103 }
102 104
103 ExecutionContext* getExecutionContext() 105 ExecutionContext* getExecutionContext()
104 { 106 {
105 return m_document.get(); 107 return m_document.get();
106 } 108 }
107 109
108 ExecutionContext* executionContext2() 110 ExecutionContext* executionContext2()
109 { 111 {
110 return m_document2.get(); 112 return m_document2.get();
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 m_notifier.addObserver(&observer1, getExecutionContext()); 273 m_notifier.addObserver(&observer1, getExecutionContext());
272 m_notifier.addObserver(&observer2, executionContext2()); 274 m_notifier.addObserver(&observer2, executionContext2());
273 m_notifier.removeObserver(&observer1, getExecutionContext()); 275 m_notifier.removeObserver(&observer1, getExecutionContext());
274 m_notifier.removeObserver(&observer2, executionContext2()); 276 m_notifier.removeObserver(&observer2, executionContext2());
275 277
276 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); 278 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps);
277 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeNone, kNoneMaxBan dwidthMbps)); 279 EXPECT_TRUE(verifyObservations(observer1, WebConnectionTypeNone, kNoneMaxBan dwidthMbps));
278 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBan dwidthMbps)); 280 EXPECT_TRUE(verifyObservations(observer2, WebConnectionTypeNone, kNoneMaxBan dwidthMbps));
279 } 281 }
280 282
283 TEST_F(NetworkStateNotifierTest, SetOverride)
284 {
285 StateObserver observer;
286 m_notifier.addObserver(&observer, getExecutionContext());
287
288 m_notifier.setOnLine(true);
289 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps);
290 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBlueto othMaxBandwidthMbps));
291 EXPECT_TRUE(m_notifier.onLine());
292 EXPECT_EQ(WebConnectionTypeBluetooth, m_notifier.connectionType());
293 EXPECT_EQ(kBluetoothMaxBandwidthMbps, m_notifier.maxBandwidth());
294
295 m_notifier.setOverride(true, WebConnectionTypeEthernet, kEthernetMaxBandwidt hMbps);
296 testing::runPendingTasks();
297 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEtherne tMaxBandwidthMbps));
298 EXPECT_TRUE(m_notifier.onLine());
299 EXPECT_EQ(WebConnectionTypeEthernet, m_notifier.connectionType());
300 EXPECT_EQ(kEthernetMaxBandwidthMbps, m_notifier.maxBandwidth());
301
302 // When override is active, calls to setOnLine and setConnection are tempora ry ignored.
303 m_notifier.setOnLine(false);
304 setConnection(WebConnectionTypeNone, kNoneMaxBandwidthMbps);
305 testing::runPendingTasks();
306 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEtherne tMaxBandwidthMbps));
307 EXPECT_TRUE(m_notifier.onLine());
308 EXPECT_EQ(WebConnectionTypeEthernet, m_notifier.connectionType());
309 EXPECT_EQ(kEthernetMaxBandwidthMbps, m_notifier.maxBandwidth());
310
311 m_notifier.clearOverride();
312 testing::runPendingTasks();
313 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeNone, kNoneMaxBand widthMbps));
314 EXPECT_FALSE(m_notifier.onLine());
315 EXPECT_EQ(WebConnectionTypeNone, m_notifier.connectionType());
316 EXPECT_EQ(kNoneMaxBandwidthMbps, m_notifier.maxBandwidth());
317
318 m_notifier.removeObserver(&observer, getExecutionContext());
319 }
320
321 TEST_F(NetworkStateNotifierTest, NoExtraNotifications)
322 {
323 StateObserver observer;
324 m_notifier.addObserver(&observer, getExecutionContext());
325
326 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps);
327 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBlueto othMaxBandwidthMbps));
328 EXPECT_EQ(observer.callbackCount(), 1);
329
330 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps);
331 EXPECT_EQ(observer.callbackCount(), 1);
332
333 setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps);
334 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeEthernet, kEtherne tMaxBandwidthMbps));
335 EXPECT_EQ(observer.callbackCount(), 2);
336
337 setConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMbps);
338 EXPECT_EQ(observer.callbackCount(), 2);
339
340 setConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps);
341 EXPECT_TRUE(verifyObservations(observer, WebConnectionTypeBluetooth, kBlueto othMaxBandwidthMbps));
342 EXPECT_EQ(observer.callbackCount(), 3);
343
344 m_notifier.removeObserver(&observer, getExecutionContext());
345 }
346
347 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization)
348 {
349 NetworkStateNotifier notifier;
350 Persistent<Document> document(Document::create());
351 StateObserver observer;
352
353 notifier.addObserver(&observer, document.get());
354 testing::runPendingTasks();
355 EXPECT_EQ(observer.callbackCount(), 0);
356
357 notifier.setWebConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidth Mbps);
358 testing::runPendingTasks();
359 EXPECT_EQ(observer.callbackCount(), 0);
360
361 notifier.setWebConnection(WebConnectionTypeBluetooth, kBluetoothMaxBandwidth Mbps);
362 testing::runPendingTasks();
363 EXPECT_EQ(observer.callbackCount(), 0);
364
365 notifier.setWebConnection(WebConnectionTypeEthernet, kEthernetMaxBandwidthMb ps);
366 testing::runPendingTasks();
367 EXPECT_EQ(observer.callbackCount(), 1);
368 EXPECT_EQ(observer.observedType(), WebConnectionTypeEthernet);
369 EXPECT_EQ(observer.observedMaxBandwidth(), kEthernetMaxBandwidthMbps);
370 }
371
281 } // namespace blink 372 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/NetworkStateNotifier.cpp ('k') | third_party/WebKit/Source/core/testing/Internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698