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 const bool ignore_error_state = false; | 72 const bool ignore_error_state = false; |
70 NetworkConnectionHandler::Get()->ConnectToNetwork( | 73 network_connection_handler_->ConnectToNetwork( |
71 service_path, | 74 service_path, |
72 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 75 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
73 base::Unretained(this)), | 76 base::Unretained(this)), |
74 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 77 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
75 base::Unretained(this)), | 78 base::Unretained(this)), |
76 ignore_error_state); | 79 ignore_error_state); |
77 message_loop_.RunUntilIdle(); | 80 message_loop_.RunUntilIdle(); |
78 } | 81 } |
79 | 82 |
80 void Disconnect(const std::string& service_path) { | 83 void Disconnect(const std::string& service_path) { |
81 NetworkConnectionHandler::Get()->DisconnectNetwork( | 84 network_connection_handler_->DisconnectNetwork( |
82 service_path, | 85 service_path, |
83 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 86 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
84 base::Unretained(this)), | 87 base::Unretained(this)), |
85 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 88 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
86 base::Unretained(this))); | 89 base::Unretained(this))); |
87 message_loop_.RunUntilIdle(); | 90 message_loop_.RunUntilIdle(); |
88 } | 91 } |
89 | 92 |
90 void SuccessCallback() { | 93 void SuccessCallback() { |
91 result_ = kSuccessResult; | 94 result_ = kSuccessResult; |
(...skipping 14 matching lines...) Expand all Loading... |
106 const std::string& key) { | 109 const std::string& key) { |
107 std::string result; | 110 std::string result; |
108 const base::DictionaryValue* properties = | 111 const base::DictionaryValue* properties = |
109 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> | 112 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> |
110 GetServiceProperties(service_path); | 113 GetServiceProperties(service_path); |
111 if (properties) | 114 if (properties) |
112 properties->GetStringWithoutPathExpansion(key, &result); | 115 properties->GetStringWithoutPathExpansion(key, &result); |
113 return result; | 116 return result; |
114 } | 117 } |
115 | 118 |
| 119 scoped_ptr<NetworkStateHandler> network_state_handler_; |
| 120 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
| 121 scoped_ptr<NetworkConnectionHandler> network_connection_handler_; |
116 MessageLoopForUI message_loop_; | 122 MessageLoopForUI message_loop_; |
117 std::string result_; | 123 std::string result_; |
118 | 124 |
119 private: | 125 private: |
120 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); | 126 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); |
121 }; | 127 }; |
122 | 128 |
123 namespace { | 129 namespace { |
124 | 130 |
125 const char* kConfigConnectable = | 131 const char* kConfigConnectable = |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 NetworkConnectionHandlerDisconnectFailure) { | 209 NetworkConnectionHandlerDisconnectFailure) { |
204 Connect("no-network"); | 210 Connect("no-network"); |
205 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); | 211 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); |
206 | 212 |
207 EXPECT_TRUE(Configure(kConfigConnectable)); | 213 EXPECT_TRUE(Configure(kConfigConnectable)); |
208 Disconnect("wifi0"); | 214 Disconnect("wifi0"); |
209 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 215 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
210 } | 216 } |
211 | 217 |
212 } // namespace chromeos | 218 } // namespace chromeos |
OLD | NEW |