OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "net/android/network_change_notifier_android.h" | |
6 | |
7 #include "base/message_loop.h" | |
8 #include "net/android/network_change_notifier_factory.h" | |
9 #include "net/base/network_change_notifier.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace net { | |
13 namespace android { | |
14 | |
15 namespace { | |
16 | |
17 class TestConnectionTypeObserver : | |
18 public net::NetworkChangeNotifier::ConnectionTypeObserver { | |
19 public: | |
20 TestConnectionTypeObserver() : | |
21 connection_type_has_been_changed_(false), | |
22 current_connection_(net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { | |
23 } | |
24 | |
25 void OnConnectionTypeChanged( | |
26 net::NetworkChangeNotifier::ConnectionType type) { | |
27 connection_type_has_been_changed_ = true; | |
28 current_connection_ = type; | |
29 } | |
30 | |
31 bool connection_type_has_been_changed() const { | |
32 return connection_type_has_been_changed_; | |
33 } | |
34 | |
35 net::NetworkChangeNotifier::ConnectionType current_connection() const { | |
36 return current_connection_; | |
37 } | |
38 | |
39 private: | |
40 bool connection_type_has_been_changed_; | |
41 net::NetworkChangeNotifier::ConnectionType current_connection_; | |
szym
2012/09/14 19:07:29
nit: DISALLOW_COPY_AND_ASSIGN(TestConnectionTypeOb
gone
2012/09/15 01:01:55
Done.
| |
42 }; | |
43 | |
44 } // namespace | |
45 | |
46 class NetworkChangeNotifierAndroidTest : public testing::Test { | |
47 public: | |
48 NetworkChangeNotifierAndroidTest() : connection_type_observer_(NULL) { | |
49 } | |
50 | |
51 virtual void SetUp() { | |
szym
2012/09/14 19:07:29
Everything from here down can be protected:
gone
2012/09/15 01:01:55
Done.
| |
52 notifier_.reset(new net::android::NetworkChangeNotifier()); | |
szym
2012/09/14 19:07:29
You don't really need "net::android::" here. I und
gone
2012/09/15 01:01:55
Renamed.
| |
53 connection_type_observer_.reset(new TestConnectionTypeObserver()); | |
54 net::NetworkChangeNotifier::AddConnectionTypeObserver( | |
55 connection_type_observer_.get()); | |
56 } | |
57 | |
58 net::android::NetworkChangeNotifier* notifier() { | |
szym
2012/09/14 19:07:29
Rather than the getter I suggest a forwarding Forc
gone
2012/09/15 01:01:55
Done.
| |
59 return notifier_.get(); | |
60 } | |
61 | |
62 TestConnectionTypeObserver* observer() { | |
szym
2012/09/14 19:07:29
nit: const ... const?
gone
2012/09/15 01:01:55
Done.
| |
63 return connection_type_observer_.get(); | |
64 } | |
65 | |
66 private: | |
67 NetworkChangeNotifier::DisableForTest disable_for_test_; | |
68 scoped_ptr<net::android::NetworkChangeNotifier> notifier_; | |
69 scoped_ptr<TestConnectionTypeObserver> connection_type_observer_; | |
70 }; | |
71 | |
72 | |
73 TEST_F(NetworkChangeNotifierAndroidTest, ObserverNotified) { | |
74 EXPECT_FALSE(observer()->connection_type_has_been_changed()); | |
75 EXPECT_EQ(net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | |
76 observer()->current_connection()); | |
77 | |
78 notifier()->ForceConnectivityState(false); | |
79 MessageLoop::current()->RunAllPending(); | |
80 | |
81 EXPECT_TRUE(observer()->connection_type_has_been_changed()); | |
82 EXPECT_EQ(net::NetworkChangeNotifier::CONNECTION_NONE, | |
83 observer()->current_connection()); | |
84 } | |
85 | |
86 } // namespace anrdoid | |
87 } // namespace net | |
OLD | NEW |