OLD | NEW |
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 #include "chromeos/network/network_connection_handler.h" | 5 #include "chromeos/network/network_connection_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 virtual ~NetworkConnectionHandlerTest() { | 31 virtual ~NetworkConnectionHandlerTest() { |
32 } | 32 } |
33 | 33 |
34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
35 // Initialize DBusThreadManager with a stub implementation. | 35 // Initialize DBusThreadManager with a stub implementation. |
36 DBusThreadManager::InitializeWithStub(); | 36 DBusThreadManager::InitializeWithStub(); |
37 message_loop_.RunUntilIdle(); | 37 message_loop_.RunUntilIdle(); |
38 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() | 38 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() |
39 ->ClearServices(); | 39 ->ClearServices(); |
40 message_loop_.RunUntilIdle(); | 40 message_loop_.RunUntilIdle(); |
41 NetworkStateHandler::Initialize(); | 41 network_state_handler_.reset(NetworkStateHandler::InitializeForTest()); |
42 NetworkConfigurationHandler::Initialize(); | 42 network_configuration_handler_.reset( |
43 NetworkConnectionHandler::Initialize(); | 43 NetworkConfigurationHandler::InitializeForTest()); |
| 44 network_connection_handler_.reset(new NetworkConnectionHandler); |
| 45 network_connection_handler_->Init(network_state_handler_.get(), |
| 46 network_configuration_handler_.get()); |
44 } | 47 } |
45 | 48 |
46 virtual void TearDown() OVERRIDE { | 49 virtual void TearDown() OVERRIDE { |
47 NetworkConnectionHandler::Shutdown(); | 50 network_connection_handler_.reset(); |
48 NetworkConfigurationHandler::Shutdown(); | 51 network_configuration_handler_.reset(); |
49 NetworkStateHandler::Shutdown(); | 52 network_state_handler_.reset(); |
50 DBusThreadManager::Shutdown(); | 53 DBusThreadManager::Shutdown(); |
51 } | 54 } |
52 | 55 |
53 protected: | 56 protected: |
54 bool Configure(const std::string& json_string) { | 57 bool Configure(const std::string& json_string) { |
55 scoped_ptr<base::DictionaryValue> json_dict = | 58 scoped_ptr<base::DictionaryValue> json_dict = |
56 onc::ReadDictionaryFromJson(json_string); | 59 onc::ReadDictionaryFromJson(json_string); |
57 if (!json_dict) { | 60 if (!json_dict) { |
58 LOG(ERROR) << "Error parsing json: " << json_string; | 61 LOG(ERROR) << "Error parsing json: " << json_string; |
59 return false; | 62 return false; |
60 } | 63 } |
61 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( | 64 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( |
62 *json_dict, | 65 *json_dict, |
63 ObjectPathCallback(), ShillManagerClient::ErrorCallback()); | 66 ObjectPathCallback(), ShillManagerClient::ErrorCallback()); |
64 message_loop_.RunUntilIdle(); | 67 message_loop_.RunUntilIdle(); |
65 return true; | 68 return true; |
66 } | 69 } |
67 | 70 |
68 void Connect(const std::string& service_path) { | 71 void Connect(const std::string& service_path) { |
69 NetworkConnectionHandler::Get()->ConnectToNetwork( | 72 network_connection_handler_->ConnectToNetwork( |
70 service_path, | 73 service_path, |
71 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 74 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
72 base::Unretained(this)), | 75 base::Unretained(this)), |
73 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 76 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
74 base::Unretained(this))); | 77 base::Unretained(this))); |
75 message_loop_.RunUntilIdle(); | 78 message_loop_.RunUntilIdle(); |
76 } | 79 } |
77 | 80 |
78 void Disconnect(const std::string& service_path) { | 81 void Disconnect(const std::string& service_path) { |
79 NetworkConnectionHandler::Get()->DisconnectNetwork( | 82 network_connection_handler_->DisconnectNetwork( |
80 service_path, | 83 service_path, |
81 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 84 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
82 base::Unretained(this)), | 85 base::Unretained(this)), |
83 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 86 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
84 base::Unretained(this))); | 87 base::Unretained(this))); |
85 message_loop_.RunUntilIdle(); | 88 message_loop_.RunUntilIdle(); |
86 } | 89 } |
87 | 90 |
88 void SuccessCallback() { | 91 void SuccessCallback() { |
89 result_ = kSuccessResult; | 92 result_ = kSuccessResult; |
(...skipping 14 matching lines...) Expand all Loading... |
104 const std::string& key) { | 107 const std::string& key) { |
105 std::string result; | 108 std::string result; |
106 const base::DictionaryValue* properties = | 109 const base::DictionaryValue* properties = |
107 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> | 110 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> |
108 GetServiceProperties(service_path); | 111 GetServiceProperties(service_path); |
109 if (properties) | 112 if (properties) |
110 properties->GetStringWithoutPathExpansion(key, &result); | 113 properties->GetStringWithoutPathExpansion(key, &result); |
111 return result; | 114 return result; |
112 } | 115 } |
113 | 116 |
| 117 scoped_ptr<NetworkStateHandler> network_state_handler_; |
| 118 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
| 119 scoped_ptr<NetworkConnectionHandler> network_connection_handler_; |
114 MessageLoopForUI message_loop_; | 120 MessageLoopForUI message_loop_; |
115 std::string result_; | 121 std::string result_; |
116 | 122 |
117 private: | 123 private: |
118 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); | 124 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); |
119 }; | 125 }; |
120 | 126 |
121 namespace { | 127 namespace { |
122 | 128 |
123 const char* kConfigConnectable = | 129 const char* kConfigConnectable = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 NetworkConnectionHandlerDisconnectFailure) { | 207 NetworkConnectionHandlerDisconnectFailure) { |
202 Connect("no-network"); | 208 Connect("no-network"); |
203 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); | 209 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); |
204 | 210 |
205 EXPECT_TRUE(Configure(kConfigConnectable)); | 211 EXPECT_TRUE(Configure(kConfigConnectable)); |
206 Disconnect("wifi0"); | 212 Disconnect("wifi0"); |
207 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 213 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
208 } | 214 } |
209 | 215 |
210 } // namespace chromeos | 216 } // namespace chromeos |
OLD | NEW |