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

Side by Side Diff: net/android/network_change_notifier_android_unittest.cc

Issue 897423002: Update {virtual,override,final} to follow C++11 style in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // See network_change_notifier_android.h for design explanations. 5 // See network_change_notifier_android.h for design explanations.
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "net/android/network_change_notifier_android.h" 12 #include "net/android/network_change_notifier_android.h"
13 #include "net/android/network_change_notifier_delegate_android.h" 13 #include "net/android/network_change_notifier_delegate_android.h"
14 #include "net/base/network_change_notifier.h" 14 #include "net/base/network_change_notifier.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace { 19 namespace {
20 20
21 class NetworkChangeNotifierDelegateAndroidObserver 21 class NetworkChangeNotifierDelegateAndroidObserver
22 : public NetworkChangeNotifierDelegateAndroid::Observer { 22 : public NetworkChangeNotifierDelegateAndroid::Observer {
23 public: 23 public:
24 NetworkChangeNotifierDelegateAndroidObserver() 24 NetworkChangeNotifierDelegateAndroidObserver()
25 : type_notifications_count_(0), max_bandwidth_notifications_count_(0) {} 25 : type_notifications_count_(0), max_bandwidth_notifications_count_(0) {}
26 26
27 // NetworkChangeNotifierDelegateAndroid::Observer: 27 // NetworkChangeNotifierDelegateAndroid::Observer:
28 virtual void OnConnectionTypeChanged() override { 28 void OnConnectionTypeChanged() override { type_notifications_count_++; }
29 type_notifications_count_++;
30 }
31 29
32 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) override { 30 void OnMaxBandwidthChanged(double max_bandwidth_mbps) override {
33 max_bandwidth_notifications_count_++; 31 max_bandwidth_notifications_count_++;
34 } 32 }
35 33
36 int type_notifications_count() const { return type_notifications_count_; } 34 int type_notifications_count() const { return type_notifications_count_; }
37 int bandwidth_notifications_count() const { 35 int bandwidth_notifications_count() const {
38 return max_bandwidth_notifications_count_; 36 return max_bandwidth_notifications_count_;
39 } 37 }
40 38
41 private: 39 private:
42 int type_notifications_count_; 40 int type_notifications_count_;
43 int max_bandwidth_notifications_count_; 41 int max_bandwidth_notifications_count_;
44 }; 42 };
45 43
46 class NetworkChangeNotifierObserver 44 class NetworkChangeNotifierObserver
47 : public NetworkChangeNotifier::ConnectionTypeObserver { 45 : public NetworkChangeNotifier::ConnectionTypeObserver {
48 public: 46 public:
49 NetworkChangeNotifierObserver() : notifications_count_(0) {} 47 NetworkChangeNotifierObserver() : notifications_count_(0) {}
50 48
51 // NetworkChangeNotifier::Observer: 49 // NetworkChangeNotifier::Observer:
52 virtual void OnConnectionTypeChanged( 50 void OnConnectionTypeChanged(
53 NetworkChangeNotifier::ConnectionType connection_type) override { 51 NetworkChangeNotifier::ConnectionType connection_type) override {
54 notifications_count_++; 52 notifications_count_++;
55 } 53 }
56 54
57 int notifications_count() const { 55 int notifications_count() const {
58 return notifications_count_; 56 return notifications_count_;
59 } 57 }
60 58
61 private: 59 private:
62 int notifications_count_; 60 int notifications_count_;
63 }; 61 };
64 62
65 } // namespace 63 } // namespace
66 64
67 class BaseNetworkChangeNotifierAndroidTest : public testing::Test { 65 class BaseNetworkChangeNotifierAndroidTest : public testing::Test {
68 protected: 66 protected:
69 typedef NetworkChangeNotifier::ConnectionType ConnectionType; 67 typedef NetworkChangeNotifier::ConnectionType ConnectionType;
70 68
71 virtual ~BaseNetworkChangeNotifierAndroidTest() {} 69 ~BaseNetworkChangeNotifierAndroidTest() override {}
72 70
73 void RunTest( 71 void RunTest(
74 const base::Callback<int(void)>& notifications_count_getter, 72 const base::Callback<int(void)>& notifications_count_getter,
75 const base::Callback<ConnectionType(void)>& connection_type_getter) { 73 const base::Callback<ConnectionType(void)>& connection_type_getter) {
76 EXPECT_EQ(0, notifications_count_getter.Run()); 74 EXPECT_EQ(0, notifications_count_getter.Run());
77 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, 75 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN,
78 connection_type_getter.Run()); 76 connection_type_getter.Run());
79 77
80 // Changing from online to offline should trigger a notification. 78 // Changing from online to offline should trigger a notification.
81 SetOffline(); 79 SetOffline();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 139 }
142 140
143 class NetworkChangeNotifierDelegateAndroidTest 141 class NetworkChangeNotifierDelegateAndroidTest
144 : public BaseNetworkChangeNotifierAndroidTest { 142 : public BaseNetworkChangeNotifierAndroidTest {
145 protected: 143 protected:
146 NetworkChangeNotifierDelegateAndroidTest() { 144 NetworkChangeNotifierDelegateAndroidTest() {
147 delegate_.AddObserver(&delegate_observer_); 145 delegate_.AddObserver(&delegate_observer_);
148 delegate_.AddObserver(&other_delegate_observer_); 146 delegate_.AddObserver(&other_delegate_observer_);
149 } 147 }
150 148
151 virtual ~NetworkChangeNotifierDelegateAndroidTest() { 149 ~NetworkChangeNotifierDelegateAndroidTest() override {
152 delegate_.RemoveObserver(&delegate_observer_); 150 delegate_.RemoveObserver(&delegate_observer_);
153 delegate_.RemoveObserver(&other_delegate_observer_); 151 delegate_.RemoveObserver(&other_delegate_observer_);
154 } 152 }
155 153
156 NetworkChangeNotifierDelegateAndroidObserver delegate_observer_; 154 NetworkChangeNotifierDelegateAndroidObserver delegate_observer_;
157 NetworkChangeNotifierDelegateAndroidObserver other_delegate_observer_; 155 NetworkChangeNotifierDelegateAndroidObserver other_delegate_observer_;
158 }; 156 };
159 157
160 // Tests that the NetworkChangeNotifierDelegateAndroid's observers are notified. 158 // Tests that the NetworkChangeNotifierDelegateAndroid's observers are notified.
161 // A testing-only observer is used here for testing. In production the 159 // A testing-only observer is used here for testing. In production the
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); 234 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count());
237 SetOffline(); 235 SetOffline();
238 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); 236 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count());
239 SetOnline(); 237 SetOnline();
240 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); 238 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count());
241 SetOnline(); 239 SetOnline();
242 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); 240 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count());
243 } 241 }
244 242
245 } // namespace net 243 } // namespace net
OLDNEW
« no previous file with comments | « net/android/network_change_notifier_android.cc ('k') | net/android/network_change_notifier_factory_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698