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

Side by Side Diff: chrome/browser/chromeos/extensions/networking_private_apitest.cc

Issue 12676017: Adding policy support to the new network configuration stack. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed remaining comments of Steven. Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/dbus/shill_device_client.h" 12 #include "chromeos/dbus/shill_device_client.h"
13 #include "chromeos/dbus/shill_profile_client.h"
13 #include "chromeos/dbus/shill_service_client.h" 14 #include "chromeos/dbus/shill_service_client.h"
15 #include "chromeos/network/managed_network_configuration_handler.h"
16 #include "chromeos/network/onc/onc_constants.h"
17 #include "chromeos/network/onc/onc_utils.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h"
15 19
16 namespace chromeos { 20 namespace chromeos {
17 21
22 const char kSharedProfilePath[] = "/profile/default";
23 const char kUserProfilePath[] = "/profile/chronos/shill";
24
18 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest { 25 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest {
19 public: 26 public:
20 // Whitelist the extension ID of the test extension. 27 // Whitelist the extension ID of the test extension.
21 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 28 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
22 ExtensionApiTest::SetUpCommandLine(command_line); 29 ExtensionApiTest::SetUpCommandLine(command_line);
23 command_line->AppendSwitchASCII( 30 command_line->AppendSwitchASCII(
24 switches::kWhitelistedExtensionID, "epcifkihnkjgphfkloaaleeakhpmgdmn"); 31 switches::kWhitelistedExtensionID, "epcifkihnkjgphfkloaaleeakhpmgdmn");
25 } 32 }
26 33
27 bool RunNetworkingSubtest(const std::string& subtest) { 34 bool RunNetworkingSubtest(const std::string& subtest) {
(...skipping 26 matching lines...) Expand all
54 flimflam::kTypeWifi, flimflam::kStateOnline, 61 flimflam::kTypeWifi, flimflam::kStateOnline,
55 add_to_watchlist); 62 add_to_watchlist);
56 service_test->SetServiceProperty("stub_wifi1", 63 service_test->SetServiceProperty("stub_wifi1",
57 flimflam::kSecurityProperty, 64 flimflam::kSecurityProperty,
58 base::StringValue(flimflam::kSecurityWep)); 65 base::StringValue(flimflam::kSecurityWep));
59 66
60 service_test->AddService("stub_wifi2", "wifi2_PSK", 67 service_test->AddService("stub_wifi2", "wifi2_PSK",
61 flimflam::kTypeWifi, flimflam::kStateIdle, 68 flimflam::kTypeWifi, flimflam::kStateIdle,
62 add_to_watchlist); 69 add_to_watchlist);
63 service_test->SetServiceProperty("stub_wifi2", 70 service_test->SetServiceProperty("stub_wifi2",
71 flimflam::kGuidProperty,
72 base::StringValue("stub_wifi2"));
73 service_test->SetServiceProperty("stub_wifi2",
64 flimflam::kSecurityProperty, 74 flimflam::kSecurityProperty,
65 base::StringValue(flimflam::kSecurityPsk)); 75 base::StringValue(flimflam::kSecurityPsk));
66 service_test->SetServiceProperty("stub_wifi2", 76 service_test->SetServiceProperty("stub_wifi2",
67 flimflam::kSignalStrengthProperty, 77 flimflam::kSignalStrengthProperty,
68 base::FundamentalValue(80)); 78 base::FundamentalValue(80));
69 79
70 service_test->AddService("stub_cellular1", "cellular1", 80 service_test->AddService("stub_cellular1", "cellular1",
71 flimflam::kTypeCellular, flimflam::kStateIdle, 81 flimflam::kTypeCellular, flimflam::kStateIdle,
72 add_to_watchlist); 82 add_to_watchlist);
73 service_test->SetServiceProperty( 83 service_test->SetServiceProperty(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 145
136 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetState) { 146 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetState) {
137 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; 147 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_;
138 } 148 }
139 149
140 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, SetProperties) { 150 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, SetProperties) {
141 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; 151 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_;
142 } 152 }
143 153
144 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, 154 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
155 GetManagedProperties) {
156 ShillServiceClient::TestInterface* service_test =
157 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
158 const std::string uidata_blob =
159 "{ \"user_settings\": {"
160 " \"WiFi\": {"
161 " \"Passphrase\": \"top secret\","
162 " }"
163 " }"
164 "}";
165 service_test->SetServiceProperty("stub_wifi2",
166 flimflam::kGuidProperty,
167 base::StringValue("stub_wifi2"));
168 service_test->SetServiceProperty("stub_wifi2",
169 flimflam::kUIDataProperty,
170 base::StringValue(uidata_blob));
171 service_test->SetServiceProperty("stub_wifi2",
172 flimflam::kProfileProperty,
173 base::StringValue(kUserProfilePath));
174 service_test->SetServiceProperty("stub_wifi2",
175 flimflam::kAutoConnectProperty,
176 base::FundamentalValue(false));
177
178 ShillProfileClient::TestInterface* profile_test =
179 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
180
181 profile_test->AddService("stub_wifi2");
182
183 content::RunAllPendingInMessageLoop();
184
185 const std::string user_policy_blob =
186 "{ \"NetworkConfigurations\": ["
187 " { \"GUID\": \"stub_wifi2\","
188 " \"Type\": \"WiFi\","
189 " \"Name\": \"My WiFi Network\","
190 " \"WiFi\": {"
191 " \"Passphrase\": \"passphrase\","
192 " \"Recommended\": [ \"AutoConnect\", \"Passphrase\" ],"
193 " \"SSID\": \"stub_wifi2\","
194 " \"Security\": \"WPA-PSK\""
195 " }"
196 " }"
197 " ],"
198 " \"Certificates\": [],"
199 " \"Type\": \"UnencryptedConfiguration\""
200 "}";
201 scoped_ptr<base::DictionaryValue> user_policy =
202 onc::ReadDictionaryFromJson(user_policy_blob);
203 ManagedNetworkConfigurationHandler::Get()->SetPolicy(
204 onc::ONC_SOURCE_USER_POLICY,
205 *user_policy);
206
207 scoped_ptr<base::DictionaryValue> device_policy =
208 onc::ReadDictionaryFromJson(onc::kEmptyUnencryptedConfiguration);
209 ManagedNetworkConfigurationHandler::Get()->SetPolicy(
210 onc::ONC_SOURCE_DEVICE_POLICY,
211 *device_policy);
212
213 content::RunAllPendingInMessageLoop();
214
215 EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_;
216 }
217
218 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
145 OnNetworksChangedEventConnect) { 219 OnNetworksChangedEventConnect) {
146 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect")) 220 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect"))
147 << message_; 221 << message_;
148 } 222 }
149 223
150 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, 224 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
151 OnNetworksChangedEventDisconnect) { 225 OnNetworksChangedEventDisconnect) {
152 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect")) 226 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect"))
153 << message_; 227 << message_;
154 } 228 }
(...skipping 13 matching lines...) Expand all
168 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; 242 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_;
169 } 243 }
170 244
171 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, 245 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
172 VerifyAndEncryptData) { 246 VerifyAndEncryptData) {
173 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; 247 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_;
174 } 248 }
175 249
176 250
177 } // namespace chromeos 251 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698