| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "chromeos/network/network_state_test.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/shill_device_client.h" |
| 12 #include "chromeos/dbus/shill_profile_client.h" |
| 13 #include "chromeos/dbus/shill_service_client.h" |
| 14 #include "chromeos/network/network_state_handler.h" |
| 15 #include "chromeos/network/onc/onc_utils.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 void ConfigureCallback(const dbus::ObjectPath& result) {} |
| 21 |
| 22 void FailErrorCallback(const std::string& error_name, |
| 23 const std::string& error_message) {} |
| 24 |
| 25 const char NetworkStateTest::kUserHash[] = "user_hash"; |
| 26 |
| 27 NetworkStateTest::NetworkStateTest() : test_manager_client_(nullptr) {} |
| 28 |
| 29 NetworkStateTest::~NetworkStateTest() {} |
| 30 |
| 31 void NetworkStateTest::SetUp() { |
| 32 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
| 33 CHECK(dbus_manager) |
| 34 << "NetworkStateTest requires DBusThreadManager::Initialize()"; |
| 35 |
| 36 test_manager_client_ = |
| 37 dbus_manager->GetShillManagerClient()->GetTestInterface(); |
| 38 |
| 39 dbus_manager->GetShillProfileClient()->GetTestInterface()->AddProfile( |
| 40 "shared_profile_path", std::string() /* shared profile */); |
| 41 dbus_manager->GetShillProfileClient()->GetTestInterface()->AddProfile( |
| 42 "user_profile_path", kUserHash); |
| 43 test_manager_client_->AddTechnology(shill::kTypeWifi, true /* enabled */); |
| 44 dbus_manager->GetShillDeviceClient()->GetTestInterface()->AddDevice( |
| 45 "/device/wifi1", shill::kTypeWifi, "wifi_device1"); |
| 46 |
| 47 base::RunLoop().RunUntilIdle(); |
| 48 |
| 49 network_state_handler_ = NetworkStateHandler::InitializeForTest(); |
| 50 } |
| 51 |
| 52 void NetworkStateTest::TearDown() { |
| 53 network_state_handler_.reset(); |
| 54 } |
| 55 |
| 56 void NetworkStateTest::ShutdownNetworkState() { |
| 57 network_state_handler_->Shutdown(); |
| 58 } |
| 59 |
| 60 bool NetworkStateTest::ConfigureService(const std::string& shill_json_string) { |
| 61 std::unique_ptr<base::DictionaryValue> shill_json_dict = |
| 62 onc::ReadDictionaryFromJson(shill_json_string); |
| 63 if (!shill_json_dict) { |
| 64 LOG(ERROR) << "Error parsing json: " << shill_json_string; |
| 65 return false; |
| 66 } |
| 67 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( |
| 68 *shill_json_dict, base::Bind(&ConfigureCallback), |
| 69 base::Bind(&FailErrorCallback)); |
| 70 base::RunLoop().RunUntilIdle(); |
| 71 return true; |
| 72 } |
| 73 |
| 74 std::string NetworkStateTest::GetServiceStringProperty( |
| 75 const std::string& service_path, |
| 76 const std::string& key) { |
| 77 const base::DictionaryValue* properties = |
| 78 DBusThreadManager::Get() |
| 79 ->GetShillServiceClient() |
| 80 ->GetTestInterface() |
| 81 ->GetServiceProperties(service_path); |
| 82 std::string result; |
| 83 if (properties) |
| 84 properties->GetStringWithoutPathExpansion(key, &result); |
| 85 return result; |
| 86 } |
| 87 |
| 88 } // namespace chromeos |
| OLD | NEW |