| 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_state_handler_.get())); |
| 45 network_connection_handler_.reset(new NetworkConnectionHandler); |
| 46 network_connection_handler_->Init(network_state_handler_.get(), |
| 47 network_configuration_handler_.get()); |
| 44 } | 48 } |
| 45 | 49 |
| 46 virtual void TearDown() OVERRIDE { | 50 virtual void TearDown() OVERRIDE { |
| 47 NetworkConnectionHandler::Shutdown(); | 51 network_connection_handler_.reset(); |
| 48 NetworkConfigurationHandler::Shutdown(); | 52 network_configuration_handler_.reset(); |
| 49 NetworkStateHandler::Shutdown(); | 53 network_state_handler_.reset(); |
| 50 DBusThreadManager::Shutdown(); | 54 DBusThreadManager::Shutdown(); |
| 51 } | 55 } |
| 52 | 56 |
| 53 protected: | 57 protected: |
| 54 bool Configure(const std::string& json_string) { | 58 bool Configure(const std::string& json_string) { |
| 55 scoped_ptr<base::DictionaryValue> json_dict = | 59 scoped_ptr<base::DictionaryValue> json_dict = |
| 56 onc::ReadDictionaryFromJson(json_string); | 60 onc::ReadDictionaryFromJson(json_string); |
| 57 if (!json_dict) { | 61 if (!json_dict) { |
| 58 LOG(ERROR) << "Error parsing json: " << json_string; | 62 LOG(ERROR) << "Error parsing json: " << json_string; |
| 59 return false; | 63 return false; |
| 60 } | 64 } |
| 61 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( | 65 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( |
| 62 *json_dict, | 66 *json_dict, |
| 63 ObjectPathCallback(), ShillManagerClient::ErrorCallback()); | 67 ObjectPathCallback(), ShillManagerClient::ErrorCallback()); |
| 64 message_loop_.RunUntilIdle(); | 68 message_loop_.RunUntilIdle(); |
| 65 return true; | 69 return true; |
| 66 } | 70 } |
| 67 | 71 |
| 68 void Connect(const std::string& service_path) { | 72 void Connect(const std::string& service_path) { |
| 69 const bool ignore_error_state = false; | 73 const bool ignore_error_state = false; |
| 70 NetworkConnectionHandler::Get()->ConnectToNetwork( | 74 network_connection_handler_->ConnectToNetwork( |
| 71 service_path, | 75 service_path, |
| 72 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 76 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
| 73 base::Unretained(this)), | 77 base::Unretained(this)), |
| 74 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 78 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
| 75 base::Unretained(this)), | 79 base::Unretained(this)), |
| 76 ignore_error_state); | 80 ignore_error_state); |
| 77 message_loop_.RunUntilIdle(); | 81 message_loop_.RunUntilIdle(); |
| 78 } | 82 } |
| 79 | 83 |
| 80 void Disconnect(const std::string& service_path) { | 84 void Disconnect(const std::string& service_path) { |
| 81 NetworkConnectionHandler::Get()->DisconnectNetwork( | 85 network_connection_handler_->DisconnectNetwork( |
| 82 service_path, | 86 service_path, |
| 83 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, | 87 base::Bind(&NetworkConnectionHandlerTest::SuccessCallback, |
| 84 base::Unretained(this)), | 88 base::Unretained(this)), |
| 85 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, | 89 base::Bind(&NetworkConnectionHandlerTest::ErrorCallback, |
| 86 base::Unretained(this))); | 90 base::Unretained(this))); |
| 87 message_loop_.RunUntilIdle(); | 91 message_loop_.RunUntilIdle(); |
| 88 } | 92 } |
| 89 | 93 |
| 90 void SuccessCallback() { | 94 void SuccessCallback() { |
| 91 result_ = kSuccessResult; | 95 result_ = kSuccessResult; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 const std::string& key) { | 110 const std::string& key) { |
| 107 std::string result; | 111 std::string result; |
| 108 const base::DictionaryValue* properties = | 112 const base::DictionaryValue* properties = |
| 109 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> | 113 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface()-> |
| 110 GetServiceProperties(service_path); | 114 GetServiceProperties(service_path); |
| 111 if (properties) | 115 if (properties) |
| 112 properties->GetStringWithoutPathExpansion(key, &result); | 116 properties->GetStringWithoutPathExpansion(key, &result); |
| 113 return result; | 117 return result; |
| 114 } | 118 } |
| 115 | 119 |
| 120 scoped_ptr<NetworkStateHandler> network_state_handler_; |
| 121 scoped_ptr<NetworkConfigurationHandler> network_configuration_handler_; |
| 122 scoped_ptr<NetworkConnectionHandler> network_connection_handler_; |
| 116 MessageLoopForUI message_loop_; | 123 MessageLoopForUI message_loop_; |
| 117 std::string result_; | 124 std::string result_; |
| 118 | 125 |
| 119 private: | 126 private: |
| 120 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); | 127 DISALLOW_COPY_AND_ASSIGN(NetworkConnectionHandlerTest); |
| 121 }; | 128 }; |
| 122 | 129 |
| 123 namespace { | 130 namespace { |
| 124 | 131 |
| 125 const char* kConfigConnectable = | 132 const char* kConfigConnectable = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 NetworkConnectionHandlerDisconnectFailure) { | 210 NetworkConnectionHandlerDisconnectFailure) { |
| 204 Connect("no-network"); | 211 Connect("no-network"); |
| 205 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); | 212 EXPECT_EQ(NetworkConnectionHandler::kErrorNotFound, GetResultAndReset()); |
| 206 | 213 |
| 207 EXPECT_TRUE(Configure(kConfigConnectable)); | 214 EXPECT_TRUE(Configure(kConfigConnectable)); |
| 208 Disconnect("wifi0"); | 215 Disconnect("wifi0"); |
| 209 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); | 216 EXPECT_EQ(NetworkConnectionHandler::kErrorNotConnected, GetResultAndReset()); |
| 210 } | 217 } |
| 211 | 218 |
| 212 } // namespace chromeos | 219 } // namespace chromeos |
| OLD | NEW |