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

Side by Side Diff: chrome/browser/extensions/api/networking_private/networking_private_apitest.cc

Issue 54323003: Base infrastructure for Networking Private API on Windows and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Track ToT. Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 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 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/login/user.h" 8 #include "chrome/browser/chromeos/login/user.h"
9 #include "chrome/browser/chromeos/login/user_manager.h" 9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 11 matching lines...) Expand all
22 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/shill_device_client.h" 23 #include "chromeos/dbus/shill_device_client.h"
24 #include "chromeos/dbus/shill_manager_client.h" 24 #include "chromeos/dbus/shill_manager_client.h"
25 #include "chromeos/dbus/shill_profile_client.h" 25 #include "chromeos/dbus/shill_profile_client.h"
26 #include "chromeos/dbus/shill_service_client.h" 26 #include "chromeos/dbus/shill_service_client.h"
27 #include "chromeos/dbus/shill_stub_helper.h" 27 #include "chromeos/dbus/shill_stub_helper.h"
28 #include "chromeos/network/onc/onc_utils.h" 28 #include "chromeos/network/onc/onc_utils.h"
29 #include "components/onc/onc_constants.h" 29 #include "components/onc/onc_constants.h"
30 #include "policy/policy_constants.h" 30 #include "policy/policy_constants.h"
31 #include "third_party/cros_system_api/dbus/service_constants.h" 31 #include "third_party/cros_system_api/dbus/service_constants.h"
32
33 using chromeos::CryptohomeClient;
34 using chromeos::DBUS_METHOD_CALL_SUCCESS;
35 using chromeos::DBusMethodCallStatus;
tbarzic 2013/11/15 22:56:30 group includes and using parts together. i.e. #if
mef 2013/11/17 20:05:18 Done.
36 using chromeos::DBusThreadManager;
37 using chromeos::ShillDeviceClient;
38 using chromeos::ShillManagerClient;
39 using chromeos::ShillProfileClient;
40 using chromeos::ShillServiceClient;
41 #else
42 #include "chrome/browser/extensions/api/networking_private/networking_private_se rvice_client.h"
43 #include "chrome/browser/extensions/api/networking_private/networking_private_se rvice_client_factory.h"
44 #include "components/wifi/wifi_service.h"
45
46 using extensions::NetworkingPrivateServiceClientFactory;
32 #endif // OS_CHROMEOS 47 #endif // OS_CHROMEOS
48
33 using testing::AnyNumber; 49 using testing::AnyNumber;
34 using testing::Return; 50 using testing::Return;
35 using testing::_; 51 using testing::_;
36 52
37 namespace chromeos { 53 namespace {
38 54
39 #if defined(OS_CHROMEOS) 55 #if defined(OS_CHROMEOS)
40 const char kUser1ProfilePath[] = "/profile/user1/shill"; 56 const char kUser1ProfilePath[] = "/profile/user1/shill";
41 #endif // defined(OS_CHROMEOS) 57 #endif // defined(OS_CHROMEOS)
42 58
59 // Mock Verify* methods implementation to satisfy expectations of
60 // networking_private_apitest.
61 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto,
62 // and update networking_private_apitest to use and expect valid data.
63 // That will eliminate the need for mock implementation.
64 class CryptoVerifyMock
tbarzic 2013/11/15 22:56:30 rename to CryptoVerifyStub (as it's a stub, not a
mef 2013/11/17 20:05:18 Done.
65 : public extensions::NetworkingPrivateServiceClient::CryptoVerify {
66 virtual void VerifyDestination(scoped_ptr<base::ListValue> args,
67 bool* verified,
68 std::string* error) OVERRIDE {
69 *verified = true;
70 }
71
72 virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args,
73 std::string* encoded_data,
74 std::string* error) OVERRIDE {
75 *encoded_data = "encrypted_data";
76 }
77 };
43 78
44 class ExtensionNetworkingPrivateApiTest : 79 class ExtensionNetworkingPrivateApiTest :
45 public ExtensionApiTest, 80 public ExtensionApiTest,
46 public testing::WithParamInterface<bool> { 81 public testing::WithParamInterface<bool> {
47 public: 82 public:
48 bool RunNetworkingSubtest(const std::string& subtest) { 83 bool RunNetworkingSubtest(const std::string& subtest) {
49 return RunExtensionSubtest( 84 return RunExtensionSubtest(
50 "networking", "main.html?" + subtest, 85 "networking", "main.html?" + subtest,
51 kFlagEnableFileAccess | kFlagLoadAsComponent); 86 kFlagEnableFileAccess | kFlagLoadAsComponent);
52 } 87 }
(...skipping 17 matching lines...) Expand all
70 105
71 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 106 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
72 ExtensionApiTest::SetUpCommandLine(command_line); 107 ExtensionApiTest::SetUpCommandLine(command_line);
73 // Whitelist the extension ID of the test extension. 108 // Whitelist the extension ID of the test extension.
74 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, 109 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID,
75 "epcifkihnkjgphfkloaaleeakhpmgdmn"); 110 "epcifkihnkjgphfkloaaleeakhpmgdmn");
76 111
77 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI 112 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI
78 // uses the ProfileHelper to obtain the userhash crbug/238623. 113 // uses the ProfileHelper to obtain the userhash crbug/238623.
79 std::string login_user = 114 std::string login_user =
80 command_line->GetSwitchValueNative(switches::kLoginUser); 115 command_line->GetSwitchValueNative(chromeos::switches::kLoginUser);
81 std::string sanitized_user = CryptohomeClient::GetStubSanitizedUsername( 116 std::string sanitized_user = CryptohomeClient::GetStubSanitizedUsername(
82 login_user); 117 login_user);
83 command_line->AppendSwitchASCII(switches::kLoginProfile, sanitized_user); 118 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
119 sanitized_user);
84 if (GetParam()) 120 if (GetParam())
85 command_line->AppendSwitch(::switches::kMultiProfiles); 121 command_line->AppendSwitch(::switches::kMultiProfiles);
86 } 122 }
87 123
88 void InitializeSanitizedUsername() { 124 void InitializeSanitizedUsername() {
89 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); 125 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
90 chromeos::User* user = user_manager->GetActiveUser(); 126 chromeos::User* user = user_manager->GetActiveUser();
91 CHECK(user); 127 CHECK(user);
92 std::string userhash; 128 std::string userhash;
93 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( 129 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername(
(...skipping 30 matching lines...) Expand all
124 shill::kTypeCellular, "stub_cellular_device1"); 160 shill::kTypeCellular, "stub_cellular_device1");
125 161
126 const bool add_to_watchlist = true; 162 const bool add_to_watchlist = true;
127 const bool add_to_visible = true; 163 const bool add_to_visible = true;
128 service_test->AddService("stub_ethernet", "eth0", 164 service_test->AddService("stub_ethernet", "eth0",
129 shill::kTypeEthernet, shill::kStateOnline, 165 shill::kTypeEthernet, shill::kStateOnline,
130 add_to_visible, add_to_watchlist); 166 add_to_visible, add_to_watchlist);
131 service_test->SetServiceProperty( 167 service_test->SetServiceProperty(
132 "stub_ethernet", 168 "stub_ethernet",
133 shill::kProfileProperty, 169 shill::kProfileProperty,
134 base::StringValue(shill_stub_helper::kSharedProfilePath)); 170 base::StringValue(chromeos::shill_stub_helper::kSharedProfilePath));
135 profile_test->AddService(shill_stub_helper::kSharedProfilePath, 171 profile_test->AddService(chromeos::shill_stub_helper::kSharedProfilePath,
136 "stub_ethernet"); 172 "stub_ethernet");
137 173
138 service_test->AddService("stub_wifi1", "wifi1", 174 service_test->AddService("stub_wifi1", "wifi1",
139 shill::kTypeWifi, shill::kStateOnline, 175 shill::kTypeWifi, shill::kStateOnline,
140 add_to_visible, add_to_watchlist); 176 add_to_visible, add_to_watchlist);
141 service_test->SetServiceProperty("stub_wifi1", 177 service_test->SetServiceProperty("stub_wifi1",
142 shill::kSecurityProperty, 178 shill::kSecurityProperty,
143 base::StringValue(shill::kSecurityWep)); 179 base::StringValue(shill::kSecurityWep));
144 service_test->SetServiceProperty("stub_wifi1", 180 service_test->SetServiceProperty("stub_wifi1",
145 shill::kProfileProperty, 181 shill::kProfileProperty,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 content::RunAllPendingInMessageLoop(); 246 content::RunAllPendingInMessageLoop();
211 } 247 }
212 #else // !defined(OS_CHROMEOS) 248 #else // !defined(OS_CHROMEOS)
213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 249 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
214 ExtensionApiTest::SetUpCommandLine(command_line); 250 ExtensionApiTest::SetUpCommandLine(command_line);
215 // Whitelist the extension ID of the test extension. 251 // Whitelist the extension ID of the test extension.
216 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, 252 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID,
217 "epcifkihnkjgphfkloaaleeakhpmgdmn"); 253 "epcifkihnkjgphfkloaaleeakhpmgdmn");
218 } 254 }
219 255
256 static BrowserContextKeyedService*
257 CreateNetworkingPrivateServiceClient(content::BrowserContext* profile) {
258 return new extensions::NetworkingPrivateServiceClient(
259 static_cast<Profile*>(profile),
260 wifi::WiFiService::CreateServiceMock(),
261 new CryptoVerifyMock());
262 }
263
220 virtual void SetUpOnMainThread() OVERRIDE { 264 virtual void SetUpOnMainThread() OVERRIDE {
221 ExtensionApiTest::SetUpOnMainThread(); 265 ExtensionApiTest::SetUpOnMainThread();
222 content::RunAllPendingInMessageLoop(); 266 content::RunAllPendingInMessageLoop();
267 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory(
268 profile(),
269 &CreateNetworkingPrivateServiceClient);
223 } 270 }
271
224 #endif // OS_CHROMEOS 272 #endif // OS_CHROMEOS
225 273
226 protected: 274 protected:
227 policy::MockConfigurationPolicyProvider provider_; 275 policy::MockConfigurationPolicyProvider provider_;
228 std::string userhash_; 276 std::string userhash_;
229 }; 277 };
230 278
231 // Place each subtest into a separate browser test so that the stub networking 279 // Place each subtest into a separate browser test so that the stub networking
232 // library state is reset for each subtest run. This way they won't affect each 280 // library state is reset for each subtest run. This way they won't affect each
233 // other. 281 // other.
(...skipping 15 matching lines...) Expand all
249 StartDisconnectNonexistent) { 297 StartDisconnectNonexistent) {
250 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; 298 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_;
251 } 299 }
252 300
253 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, 301 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
254 StartGetPropertiesNonexistent) { 302 StartGetPropertiesNonexistent) {
255 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) 303 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent"))
256 << message_; 304 << message_;
257 } 305 }
258 306
259 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) {
260 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_;
261 }
262
263 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { 307 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) {
264 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; 308 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_;
265 } 309 }
266 310
267 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, 311 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
268 GetVisibleNetworksWifi) { 312 GetVisibleNetworksWifi) {
269 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; 313 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_;
270 } 314 }
271 315
272 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { 316 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) {
273 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; 317 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_;
274 } 318 }
275 319
276 // Properties are filtered and translated through 320 // Properties are filtered and translated through
277 // ShillToONCTranslator::TranslateWiFiWithState 321 // ShillToONCTranslator::TranslateWiFiWithState
278 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) { 322 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) {
279 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; 323 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_;
280 } 324 }
281 325
282 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) { 326 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) {
283 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; 327 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_;
284 } 328 }
285 329
286 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) { 330 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) {
287 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; 331 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_;
288 } 332 }
289 333
290 #if defined(OS_CHROMEOS) 334 #if defined(OS_CHROMEOS)
335 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) {
336 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_;
337 }
338
291 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { 339 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) {
292 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; 340 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_;
293 } 341 }
294 342
295 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, 343 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
296 GetManagedProperties) { 344 GetManagedProperties) {
297 ShillServiceClient::TestInterface* service_test = 345 ShillServiceClient::TestInterface* service_test =
298 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 346 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
299 const std::string uidata_blob = 347 const std::string uidata_blob =
300 "{ \"user_settings\": {" 348 "{ \"user_settings\": {"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 423
376 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, 424 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
377 VerifyAndEncryptData) { 425 VerifyAndEncryptData) {
378 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; 426 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_;
379 } 427 }
380 428
381 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, 429 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation,
382 ExtensionNetworkingPrivateApiTest, 430 ExtensionNetworkingPrivateApiTest,
383 testing::Bool()); 431 testing::Bool());
384 432
385 } // namespace chromeos 433 } // namespace
434
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698