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

Side by Side Diff: third_party/WebKit/Source/platform/network/NetworkStateNotifierTest.cpp

Issue 2903493002: NetInfo network quality extension: Add callbacks and Layout tests (Closed)
Patch Set: haraken comments Created 3 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 EXPECT_TRUE(VerifyObservations( 505 EXPECT_TRUE(VerifyObservations(
506 observer1, kWebConnectionTypeNone, kNoneMaxBandwidthMbps, 506 observer1, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
507 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, 507 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
508 kUnknownThroughputMbps)); 508 kUnknownThroughputMbps));
509 EXPECT_TRUE(VerifyObservations( 509 EXPECT_TRUE(VerifyObservations(
510 observer2, kWebConnectionTypeNone, kNoneMaxBandwidthMbps, 510 observer2, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
511 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, 511 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
512 kUnknownThroughputMbps)); 512 kUnknownThroughputMbps));
513 } 513 }
514 514
515 TEST_F(NetworkStateNotifierTest, SetOverride) { 515 TEST_F(NetworkStateNotifierTest, SetNetworkConnectionInfoOverride) {
516 StateObserver observer; 516 StateObserver observer;
517 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 517 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
518 518
519 notifier_.SetOnLine(true); 519 notifier_.SetOnLine(true);
520 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 520 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
521 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, 521 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
522 kUnknownRtt, kUnknownThroughputMbps); 522 kUnknownRtt, kUnknownThroughputMbps);
523 EXPECT_TRUE(VerifyObservations( 523 EXPECT_TRUE(VerifyObservations(
524 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 524 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
525 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, 525 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
526 kUnknownThroughputMbps)); 526 kUnknownThroughputMbps));
527 EXPECT_TRUE(notifier_.OnLine()); 527 EXPECT_TRUE(notifier_.OnLine());
528 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); 528 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType());
529 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); 529 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth());
530 530
531 notifier_.SetOverride(true, kWebConnectionTypeEthernet, 531 notifier_.SetNetworkConnectionInfoOverride(true, kWebConnectionTypeEthernet,
532 kEthernetMaxBandwidthMbps); 532 kEthernetMaxBandwidthMbps);
533 RunPendingTasks(); 533 RunPendingTasks();
534 EXPECT_TRUE(VerifyObservations( 534 EXPECT_TRUE(VerifyObservations(
535 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, 535 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
536 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, 536 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
537 kUnknownThroughputMbps)); 537 kUnknownThroughputMbps));
538 EXPECT_TRUE(notifier_.OnLine()); 538 EXPECT_TRUE(notifier_.OnLine());
539 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); 539 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
540 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); 540 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
541 541
542 // When override is active, calls to setOnLine and setConnection are temporary 542 // When override is active, calls to setOnLine and setConnection are temporary
(...skipping 17 matching lines...) Expand all
560 observer, kWebConnectionTypeNone, kNoneMaxBandwidthMbps, 560 observer, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
561 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt, 561 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
562 kUnknownThroughputMbps)); 562 kUnknownThroughputMbps));
563 EXPECT_FALSE(notifier_.OnLine()); 563 EXPECT_FALSE(notifier_.OnLine());
564 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); 564 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType());
565 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); 565 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth());
566 566
567 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); 567 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
568 } 568 }
569 569
570 TEST_F(NetworkStateNotifierTest, SetNetworkQualityInfoOverride) {
571 StateObserver observer;
572 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
573
574 notifier_.SetOnLine(true);
575 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
576 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
577 kUnknownRtt, kUnknownThroughputMbps);
578 EXPECT_TRUE(VerifyObservations(
579 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
580 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
581 kUnknownThroughputMbps));
582 EXPECT_TRUE(notifier_.OnLine());
583 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType());
584 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth());
585
586 notifier_.SetNetworkQualityInfoOverride(
587 WebEffectiveConnectionType::kType3G,
588 kEthernetTransportRtt.value().InMilliseconds(),
589 kEthernetThroughputMbps.value());
590 RunPendingTasks();
591 EXPECT_TRUE(VerifyObservations(
592 observer, kWebConnectionTypeOther,
593 NetworkStateNotifier::NetworkState::kInvalidMaxBandwidth,
594 WebEffectiveConnectionType::kType3G, kUnknownRtt, kEthernetTransportRtt,
595 kEthernetThroughputMbps));
596 EXPECT_TRUE(notifier_.OnLine());
597 EXPECT_EQ(kWebConnectionTypeOther, notifier_.ConnectionType());
598 EXPECT_EQ(-1, notifier_.MaxBandwidth());
599 EXPECT_EQ(WebEffectiveConnectionType::kType3G, notifier_.EffectiveType());
600 EXPECT_EQ(kEthernetTransportRtt, notifier_.TransportRtt());
601 EXPECT_EQ(kEthernetThroughputMbps, notifier_.DownlinkThroughputMbps());
602
603 // When override is active, calls to SetConnection are temporary ignored.
604 notifier_.SetOnLine(false);
605 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
606 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt,
607 kUnknownRtt, kUnknownThroughputMbps);
608 RunPendingTasks();
609 EXPECT_TRUE(VerifyObservations(
610 observer, kWebConnectionTypeOther,
611 NetworkStateNotifier::NetworkState::kInvalidMaxBandwidth,
612 WebEffectiveConnectionType::kType3G, kUnknownRtt, kEthernetTransportRtt,
613 kEthernetThroughputMbps));
614 EXPECT_TRUE(notifier_.OnLine());
615 EXPECT_EQ(kWebConnectionTypeOther, notifier_.ConnectionType());
616 EXPECT_EQ(-1, notifier_.MaxBandwidth());
617 EXPECT_EQ(WebEffectiveConnectionType::kType3G, notifier_.EffectiveType());
618 EXPECT_EQ(kEthernetTransportRtt, notifier_.TransportRtt());
619 EXPECT_EQ(kEthernetThroughputMbps, notifier_.DownlinkThroughputMbps());
620
621 // Override the network connection info as well.
622 notifier_.SetNetworkConnectionInfoOverride(true, kWebConnectionTypeEthernet,
623 kEthernetMaxBandwidthMbps);
624 RunPendingTasks();
625 EXPECT_TRUE(VerifyObservations(
626 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps,
627 WebEffectiveConnectionType::kType3G, kUnknownRtt, kEthernetTransportRtt,
628 kEthernetThroughputMbps));
629 EXPECT_TRUE(notifier_.OnLine());
630 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType());
631 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth());
632 EXPECT_EQ(WebEffectiveConnectionType::kType3G, notifier_.EffectiveType());
633 EXPECT_EQ(kEthernetTransportRtt, notifier_.TransportRtt());
634 EXPECT_EQ(kEthernetThroughputMbps, notifier_.DownlinkThroughputMbps());
635
636 // CLearing the override should cause the network state to be changed and
637 // notified to observers.
638 notifier_.ClearOverride();
639 RunPendingTasks();
640 EXPECT_TRUE(VerifyObservations(
641 observer, kWebConnectionTypeNone, kNoneMaxBandwidthMbps,
642 WebEffectiveConnectionType::kTypeUnknown, kUnknownRtt, kUnknownRtt,
643 kUnknownThroughputMbps));
644 EXPECT_FALSE(notifier_.OnLine());
645 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType());
646 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth());
647 EXPECT_EQ(WebEffectiveConnectionType::kTypeUnknown,
648 notifier_.EffectiveType());
649 EXPECT_EQ(kUnknownRtt, notifier_.TransportRtt());
650 EXPECT_EQ(kUnknownThroughputMbps, notifier_.DownlinkThroughputMbps());
651
652 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner());
653 }
654
570 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { 655 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) {
571 StateObserver observer; 656 StateObserver observer;
572 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); 657 notifier_.AddConnectionObserver(&observer, GetTaskRunner());
573 658
574 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 659 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
575 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, 660 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
576 kEthernetTransportRtt, kEthernetThroughputMbps); 661 kEthernetTransportRtt, kEthernetThroughputMbps);
577 EXPECT_TRUE(VerifyObservations( 662 EXPECT_TRUE(VerifyObservations(
578 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, 663 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps,
579 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, 664 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt, 787 WebEffectiveConnectionType::kType3G, kEthernetHttpRtt,
703 kEthernetTransportRtt, kEthernetThroughputMbps)); 788 kEthernetTransportRtt, kEthernetThroughputMbps));
704 EXPECT_EQ(observer1.CallbackCount(), 3); 789 EXPECT_EQ(observer1.CallbackCount(), 3);
705 EXPECT_EQ(observer2.CallbackCount(), 5); 790 EXPECT_EQ(observer2.CallbackCount(), 5);
706 791
707 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); 792 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner());
708 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); 793 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner());
709 } 794 }
710 795
711 } // namespace blink 796 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/network/NetworkStateNotifier.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698