diff options
author | jkarlin <jkarlin@chromium.org> | 2014-12-16 11:59:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-16 20:00:23 +0000 |
commit | 7b25e6c3b62270e30e92ff19a5fa915d5b6213f9 (patch) | |
tree | e2209a52feccf54df6b48e5d46a8de1078fb1c81 /net/android/network_change_notifier_android_unittest.cc | |
parent | 2c719d3954743e3baa47ca02624dc43391f0bec5 (diff) | |
download | chromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.zip chromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.tar.gz chromium_src-7b25e6c3b62270e30e92ff19a5fa915d5b6213f9.tar.bz2 |
[NetInfo] Add a MaxBandwidthChangeObserver and Android implementation
* Add a MaxBandwidthChangeObserver to NetworkChangeNotifier
* Android notifies of max bandwidth changes at two points:
1. On connection type change (if the bandwidth changes)
2. On wifi signal strength change
BUG=433370
Review URL: https://codereview.chromium.org/780293003
Cr-Commit-Position: refs/heads/master@{#308647}
Diffstat (limited to 'net/android/network_change_notifier_android_unittest.cc')
-rw-r--r-- | net/android/network_change_notifier_android_unittest.cc | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/net/android/network_change_notifier_android_unittest.cc b/net/android/network_change_notifier_android_unittest.cc index 0818d5a..54e5583 100644 --- a/net/android/network_change_notifier_android_unittest.cc +++ b/net/android/network_change_notifier_android_unittest.cc @@ -21,19 +21,26 @@ namespace { class NetworkChangeNotifierDelegateAndroidObserver : public NetworkChangeNotifierDelegateAndroid::Observer { public: - NetworkChangeNotifierDelegateAndroidObserver() : notifications_count_(0) {} + NetworkChangeNotifierDelegateAndroidObserver() + : type_notifications_count_(0), max_bandwidth_notifications_count_(0) {} // NetworkChangeNotifierDelegateAndroid::Observer: virtual void OnConnectionTypeChanged() override { - notifications_count_++; + type_notifications_count_++; } - int notifications_count() const { - return notifications_count_; + virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) override { + max_bandwidth_notifications_count_++; + } + + int type_notifications_count() const { return type_notifications_count_; } + int bandwidth_notifications_count() const { + return max_bandwidth_notifications_count_; } private: - int notifications_count_; + int type_notifications_count_; + int max_bandwidth_notifications_count_; }; class NetworkChangeNotifierObserver @@ -155,17 +162,16 @@ class NetworkChangeNotifierDelegateAndroidTest // delegate's observers are instances of NetworkChangeNotifierAndroid. TEST_F(NetworkChangeNotifierDelegateAndroidTest, DelegateObserverNotified) { // Test the logic with a single observer. - RunTest( - base::Bind( - &NetworkChangeNotifierDelegateAndroidObserver::notifications_count, - base::Unretained(&delegate_observer_)), - base::Bind( - &NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType, - base::Unretained(&delegate_))); + RunTest(base::Bind(&NetworkChangeNotifierDelegateAndroidObserver:: + type_notifications_count, + base::Unretained(&delegate_observer_)), + base::Bind( + &NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType, + base::Unretained(&delegate_))); // Check that *all* the observers are notified. Both observers should have the // same state. - EXPECT_EQ(delegate_observer_.notifications_count(), - other_delegate_observer_.notifications_count()); + EXPECT_EQ(delegate_observer_.type_notifications_count(), + other_delegate_observer_.type_notifications_count()); } class NetworkChangeNotifierAndroidTest @@ -219,11 +225,21 @@ TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { notifier_.GetConnectionType()); EXPECT_EQ(std::numeric_limits<double>::infinity(), notifier_.GetMaxBandwidth()); - SetOffline(); EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, notifier_.GetConnectionType()); EXPECT_EQ(0.0, notifier_.GetMaxBandwidth()); } +TEST_F(NetworkChangeNotifierDelegateAndroidTest, + MaxBandwidthNotifiedOnConnectionChange) { + EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); + SetOffline(); + EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); + SetOnline(); + EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); + SetOnline(); + EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); +} + } // namespace net |