OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 "base/bind.h" |
| 6 #include "base/bind_helpers.h" |
| 7 #include "base/logging.h" |
| 8 #include "chrome/utility/wifi/wifi_service.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace wifi { |
| 12 |
| 13 namespace { |
| 14 |
| 15 class WiFiServiceTest : public testing::Test { |
| 16 |
| 17 protected: |
| 18 virtual void SetUp() { wifi_service_.reset(WiFiService::CreateService()); } |
| 19 |
| 20 virtual void TearDown() {} |
| 21 |
| 22 public: |
| 23 |
| 24 void LogError(const std::string& error_name, |
| 25 scoped_ptr<base::DictionaryValue> error_data) { |
| 26 LOG(ERROR) << "WiFi Error: " << error_name; |
| 27 } |
| 28 |
| 29 void TestError(const std::string& error_name, |
| 30 scoped_ptr<base::DictionaryValue> error_data) { |
| 31 LOG(ERROR) << "WiFi Error: " << error_name; |
| 32 EXPECT_TRUE(false); |
| 33 } |
| 34 |
| 35 void OnDictionaryResult(const std::string& network_guid, |
| 36 const base::DictionaryValue& dictionary) {} |
| 37 |
| 38 void OnNetworkProperties(const std::string& network_guid, |
| 39 const WiFiService::NetworkProperties& properties) { |
| 40 LOG(INFO) << "OnNetworkProperties" << *properties.ToValue(false).release(); |
| 41 } |
| 42 |
| 43 void OnNetworkConnected(const std::string& network_guid) { |
| 44 LOG(INFO) << "Connected Network:" << network_guid; |
| 45 wifi_service_->GetProperties( |
| 46 connected_network_guid_, |
| 47 base::Bind(&WiFiServiceTest::CheckNetworkState, |
| 48 base::Unretained(this), |
| 49 WiFiService::kConnectionStateConnected), |
| 50 base::Bind(&WiFiServiceTest::TestError, base::Unretained(this))); |
| 51 } |
| 52 |
| 53 void CheckNetworkState(WiFiService::ConnectionState expected_state, |
| 54 const std::string& network_guid, |
| 55 const WiFiService::NetworkProperties& properties) { |
| 56 LOG(INFO) << "CheckNetworkState" << *properties.ToValue(false).release(); |
| 57 EXPECT_EQ(expected_state, properties.connection_state); |
| 58 } |
| 59 |
| 60 void OnNetworkDisconnected(const std::string& network_guid) { |
| 61 LOG(INFO) << "Disconnected Network:" << network_guid; |
| 62 wifi_service_->GetProperties( |
| 63 connected_network_guid_, |
| 64 base::Bind(&WiFiServiceTest::CheckNetworkState, |
| 65 base::Unretained(this), |
| 66 WiFiService::kConnectionStateNotConnected), |
| 67 base::Bind(&WiFiServiceTest::TestError, base::Unretained(this))); |
| 68 |
| 69 wifi_service_->StartConnect( |
| 70 connected_network_guid_, |
| 71 base::Bind(&WiFiServiceTest::OnNetworkConnected, |
| 72 base::Unretained(this)), |
| 73 base::Bind(&WiFiServiceTest::TestError, base::Unretained(this))); |
| 74 } |
| 75 |
| 76 void OnVisibleNetworks(const WiFiService::NetworkList& network_list) { |
| 77 LOG(INFO) << "Visible WiFi Networks: " << network_list.size(); |
| 78 for (WiFiService::NetworkList::const_iterator net = network_list.begin(); |
| 79 net != network_list.end(); |
| 80 ++net) { |
| 81 if (net->connection_state == WiFiService::kConnectionStateConnected) { |
| 82 connected_network_guid_ = net->guid; |
| 83 LOG(INFO) << "Connected Network:\n" << *(net->ToValue(false).release()); |
| 84 } |
| 85 } |
| 86 |
| 87 if (!connected_network_guid_.empty()) { |
| 88 wifi_service_->StartDisconnect( |
| 89 connected_network_guid_, |
| 90 base::Bind(&WiFiServiceTest::OnNetworkDisconnected, |
| 91 base::Unretained(this)), |
| 92 base::Bind(&WiFiServiceTest::TestError, base::Unretained(this))); |
| 93 } else { |
| 94 LOG(INFO) << "No Connected Networks, skipping disconnect."; |
| 95 } |
| 96 } |
| 97 |
| 98 std::string connected_network_guid_; |
| 99 scoped_ptr<WiFiService> wifi_service_; |
| 100 }; |
| 101 |
| 102 TEST_F(WiFiServiceTest, GetProperties) { |
| 103 wifi_service_.reset(WiFiService::CreateServiceMock()); |
| 104 wifi_service_->GetProperties( |
| 105 "network_guid", |
| 106 base::Bind(&WiFiServiceTest::OnNetworkProperties, base::Unretained(this)), |
| 107 base::Bind(&WiFiServiceTest::LogError, base::Unretained(this))); |
| 108 } |
| 109 |
| 110 TEST_F(WiFiServiceTest, Reconnect) { |
| 111 wifi_service_->GetVisibleNetworks( |
| 112 base::Bind(&WiFiServiceTest::OnVisibleNetworks, base::Unretained(this)), |
| 113 base::Bind(&WiFiServiceTest::LogError, base::Unretained(this))); |
| 114 } |
| 115 |
| 116 } // namespace |
| 117 |
| 118 } // namespace wifi |
OLD | NEW |