Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: components/wifi_sync/wifi_config_delegate_chromeos_unittest.cc

Issue 836363002: wifi_sync: add WifiConfigDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.1-network-state-helper
Patch Set: git checkout submit-4.4.0-add-delegate-factory Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/wifi_sync/wifi_config_delegate_chromeos.h"
6
7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/values.h"
10 #include "chromeos/dbus/dbus_thread_manager.h"
11 #include "chromeos/dbus/shill_profile_client.h"
12 #include "chromeos/network/managed_network_configuration_handler.h"
13 #include "chromeos/network/network_handler.h"
14 #include "components/wifi_sync/network_state_helper_chromeos.h"
15 #include "components/wifi_sync/wifi_credential.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace wifi_sync {
19
20 namespace {
21 const char kProfilePath[] = "/profile/1";
22 const char kSsid[] = "fake-ssid";
23 const char kSsidNonUtf8[] = "\xc0";
24 const char kUserHash[] = "fake-user-hash";
25 }
26
27 class WifiConfigDelegateChromeOsTest : public testing::Test {
28 protected:
29 WifiConfigDelegateChromeOsTest() {
30 chromeos::DBusThreadManager::Initialize();
erikwright (departed) 2015/01/13 19:03:14 This test is visibly highly dependent on a lot of
stevenjb 2015/01/13 23:45:39 While we could create a custom MNCH class and crea
erikwright (departed) 2015/01/14 14:51:26 This test is not the place to verify that calling
mukesh agrawal 2015/01/15 03:01:48 Acknowledged.
mukesh agrawal 2015/01/15 03:01:48 Acknowledged.
mukesh agrawal 2015/01/15 03:01:48 Done.
31 chromeos::NetworkHandler::Initialize();
32 network_handler_ = chromeos::NetworkHandler::Get();
stevenjb 2015/01/13 23:45:39 I would avoid storing global singletons even in a
mukesh agrawal 2015/01/15 03:01:48 Done. (Offending code removed.)
33
34 const base::ListValue policy_network_configs;
35 const base::DictionaryValue policy_global_config;
36 network_handler_
37 ->managed_network_configuration_handler()
38 ->SetPolicy(onc::ONC_SOURCE_USER_POLICY,
39 kUserHash,
40 policy_network_configs,
41 policy_global_config);
42
43 chromeos::DBusThreadManager::Get()
44 ->GetShillProfileClient()
45 ->GetTestInterface()
46 ->AddProfile(kProfilePath, kUserHash);
stevenjb 2015/01/13 23:45:39 We don't really need to do this now since we don't
mukesh agrawal 2015/01/15 03:01:48 Acknowledged.
47
48 config_delegate_.reset(
49 new WifiConfigDelegateChromeOs(
50 kUserHash,
51 network_handler_->managed_network_configuration_handler()));
52
53 message_loop_.RunUntilIdle(); // Process updates queued by Shill clients.
54 }
55
56 ~WifiConfigDelegateChromeOsTest() {
57 // Reset singletons.
58 chromeos::NetworkHandler::Shutdown();
59 chromeos::DBusThreadManager::Shutdown();
60 }
61
62 // Wrapper for WifiConfigDelegateChromeOs::AddToLocalNetworks.
63 void AddToLocalNetworks(const WifiCredential& network_credential) {
64 config_delegate_->AddToLocalNetworks(network_credential);
65 message_loop_.RunUntilIdle(); // Process updates queued by Shill clients.
66 }
stevenjb 2015/01/13 23:45:39 nit: WS
mukesh agrawal 2015/01/15 03:01:48 Done. (Offending code removed.)
67 // Returns true if |credential_to_find| exists in the set of
68 // credentials configured in Shill.
69 bool CredentialIsConfigured(const WifiCredential& credential_to_find) {
70 WifiCredential::CredentialSet credentials(
71 GetWifiCredentialsForShillProfile(
72 network_handler_->network_state_handler(), kProfilePath));
73 for (const auto &credential : credentials) {
74 if (credential.ssid() == credential_to_find.ssid() &&
75 credential.security_class() == credential_to_find.security_class() &&
76 credential.passphrase() == credential_to_find.passphrase()) {
77 return true;
78 }
79 }
80 return false;
81 }
stevenjb 2015/01/13 23:45:39 nit: WS
mukesh agrawal 2015/01/15 03:01:48 Done.
82 // Returns a new WifiCredential constructed from the given parameters.
83 WifiCredential MakeCredential(const std::string& ssid,
84 WifiSecurityClass security_class,
85 const std::string& passphrase) {
86 scoped_ptr<WifiCredential> credential =
87 WifiCredential::Create(
88 WifiCredential::MakeSsidBytesForTest(ssid),
89 security_class,
90 passphrase);
91 CHECK(credential);
92 return *credential;
93 }
94
95 private:
96 base::MessageLoop message_loop_; // For ManagedNetworkConfigurationHandler.
97 scoped_ptr<WifiConfigDelegateChromeOs> config_delegate_;
98 chromeos::NetworkHandler* network_handler_; // Unowned.
99
100 DISALLOW_COPY_AND_ASSIGN(WifiConfigDelegateChromeOsTest);
101 };
102
103 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksOpen) {
104 const WifiCredential credential(
105 MakeCredential(kSsid, SECURITY_CLASS_NONE, ""));
106 EXPECT_FALSE(CredentialIsConfigured(credential));
107 AddToLocalNetworks(credential);
108 EXPECT_TRUE(CredentialIsConfigured(credential));
109 }
110
111 // TODO(quiche): Use a non-empty passphrase, once
112 // GetWifiCredentialsForShillProfile provides passphrases.
113 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksWep) {
114 const WifiCredential credential(
115 MakeCredential(kSsid, SECURITY_CLASS_WEP, ""));
116 EXPECT_FALSE(CredentialIsConfigured(credential));
117 AddToLocalNetworks(credential);
118 EXPECT_TRUE(CredentialIsConfigured(credential));
119 }
120
121 // TODO(quiche): Use a non-empty passphrase, once
122 // GetWifiCredentialsForShillProfile provides passphrases.
123 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksPsk) {
124 const WifiCredential credential(
125 MakeCredential(kSsid, SECURITY_CLASS_PSK, ""));
126 EXPECT_FALSE(CredentialIsConfigured(credential));
127 AddToLocalNetworks(credential);
128 EXPECT_TRUE(CredentialIsConfigured(credential));
129 }
130
131 // TODO(quiche): Use a non-empty passphrase, once
132 // GetWifiCredentialsForShillProfile provides passphrases.
133 TEST_F(WifiConfigDelegateChromeOsTest, AddToLocalNetworksNonUtf8) {
134 const WifiCredential credential(
135 MakeCredential(kSsidNonUtf8, SECURITY_CLASS_PSK, ""));
136 EXPECT_FALSE(CredentialIsConfigured(credential));
137 AddToLocalNetworks(credential);
138 // TODO(quiche): Change to EXPECT_TRUE, once we support non-UTF-8 SSIDs.
139 EXPECT_FALSE(CredentialIsConfigured(credential));
140 }
141
142 } // namespace wifi_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698