OLD | NEW |
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/bind.h" |
5 #include "base/callback.h" | 6 #include "base/callback.h" |
6 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" |
7 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/chromeos/login/user.h" | 10 #include "chrome/browser/chromeos/login/user.h" |
9 #include "chrome/browser/chromeos/login/user_manager.h" | 11 #include "chrome/browser/chromeos/login/user_manager.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
13 #include "extensions/common/switches.h" | 15 #include "extensions/common/switches.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 | 17 |
16 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 19 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/chromeos/net/network_portal_detector.h" | 20 #include "chrome/browser/chromeos/net/network_portal_detector.h" |
18 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | 21 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
19 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
20 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "chromeos/dbus/shill_device_client.h" | 25 #include "chromeos/dbus/shill_device_client.h" |
23 #include "chromeos/dbus/shill_manager_client.h" | 26 #include "chromeos/dbus/shill_manager_client.h" |
24 #include "chromeos/dbus/shill_profile_client.h" | 27 #include "chromeos/dbus/shill_profile_client.h" |
25 #include "chromeos/dbus/shill_service_client.h" | 28 #include "chromeos/dbus/shill_service_client.h" |
26 #include "chromeos/network/onc/onc_utils.h" | 29 #include "chromeos/network/onc/onc_utils.h" |
27 #include "components/onc/onc_constants.h" | 30 #include "components/onc/onc_constants.h" |
28 #include "components/policy/core/browser/browser_policy_connector.h" | 31 #include "components/policy/core/browser/browser_policy_connector.h" |
29 #include "components/policy/core/common/external_data_fetcher.h" | 32 #include "components/policy/core/common/external_data_fetcher.h" |
30 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 33 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
31 #include "components/policy/core/common/policy_map.h" | 34 #include "components/policy/core/common/policy_map.h" |
32 #include "components/policy/core/common/policy_types.h" | 35 #include "components/policy/core/common/policy_types.h" |
| 36 #include "content/public/browser/notification_observer.h" |
| 37 #include "content/public/browser/notification_registrar.h" |
| 38 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/notification_source.h" |
33 #include "policy/policy_constants.h" | 40 #include "policy/policy_constants.h" |
34 #include "third_party/cros_system_api/dbus/service_constants.h" | 41 #include "third_party/cros_system_api/dbus/service_constants.h" |
35 #else // !defined(OS_CHROMEOS) | 42 #else // !defined(OS_CHROMEOS) |
36 #include "chrome/browser/extensions/api/networking_private/networking_private_cr
edentials_getter.h" | 43 #include "chrome/browser/extensions/api/networking_private/networking_private_cr
edentials_getter.h" |
37 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client.h" | 44 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client.h" |
38 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client_factory.h" | 45 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client_factory.h" |
39 #include "components/wifi/wifi_service.h" | 46 #include "components/wifi/wifi_service.h" |
40 #endif // defined(OS_CHROMEOS) | 47 #endif // defined(OS_CHROMEOS) |
41 | 48 |
42 using testing::Return; | 49 using testing::Return; |
(...skipping 11 matching lines...) Expand all Loading... |
54 using chromeos::ShillProfileClient; | 61 using chromeos::ShillProfileClient; |
55 using chromeos::ShillServiceClient; | 62 using chromeos::ShillServiceClient; |
56 #else // !defined(OS_CHROMEOS) | 63 #else // !defined(OS_CHROMEOS) |
57 using extensions::NetworkingPrivateServiceClientFactory; | 64 using extensions::NetworkingPrivateServiceClientFactory; |
58 #endif // defined(OS_CHROMEOS) | 65 #endif // defined(OS_CHROMEOS) |
59 | 66 |
60 namespace { | 67 namespace { |
61 | 68 |
62 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
63 const char kUser1ProfilePath[] = "/profile/user1/shill"; | 70 const char kUser1ProfilePath[] = "/profile/user1/shill"; |
| 71 |
| 72 class TestListener : public content::NotificationObserver { |
| 73 public: |
| 74 TestListener(const std::string& message, const base::Closure& callback) |
| 75 : message_(message), callback_(callback) { |
| 76 registrar_.Add(this, |
| 77 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
| 78 content::NotificationService::AllSources()); |
| 79 } |
| 80 |
| 81 virtual void Observe(int type, |
| 82 const content::NotificationSource& /* source */, |
| 83 const content::NotificationDetails& details) OVERRIDE { |
| 84 const std::string& message = *content::Details<std::string>(details).ptr(); |
| 85 if (message == message_) |
| 86 callback_.Run(); |
| 87 } |
| 88 |
| 89 private: |
| 90 std::string message_; |
| 91 base::Closure callback_; |
| 92 |
| 93 content::NotificationRegistrar registrar_; |
| 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(TestListener); |
| 96 }; |
64 #else // !defined(OS_CHROMEOS) | 97 #else // !defined(OS_CHROMEOS) |
65 | 98 |
66 // Stub Verify* methods implementation to satisfy expectations of | 99 // Stub Verify* methods implementation to satisfy expectations of |
67 // networking_private_apitest. | 100 // networking_private_apitest. |
68 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, | 101 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, |
69 // and update networking_private_apitest to use and expect valid data. | 102 // and update networking_private_apitest to use and expect valid data. |
70 // That will eliminate the need for mock implementation. | 103 // That will eliminate the need for mock implementation. |
71 class CryptoVerifyStub | 104 class CryptoVerifyStub |
72 : public extensions::NetworkingPrivateServiceClient::CryptoVerify { | 105 : public extensions::NetworkingPrivateServiceClient::CryptoVerify { |
73 virtual void VerifyDestination(scoped_ptr<base::ListValue> args, | 106 virtual void VerifyDestination(scoped_ptr<base::ListValue> args, |
(...skipping 10 matching lines...) Expand all Loading... |
84 } | 117 } |
85 | 118 |
86 virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args, | 119 virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args, |
87 std::string* encoded_data, | 120 std::string* encoded_data, |
88 std::string* error) OVERRIDE { | 121 std::string* error) OVERRIDE { |
89 *encoded_data = "encrypted_data"; | 122 *encoded_data = "encrypted_data"; |
90 } | 123 } |
91 }; | 124 }; |
92 #endif // defined(OS_CHROMEOS) | 125 #endif // defined(OS_CHROMEOS) |
93 | 126 |
94 class ExtensionNetworkingPrivateApiTest : | 127 class ExtensionNetworkingPrivateApiTest |
95 public ExtensionApiTest, | 128 : public ExtensionApiTest, |
96 public testing::WithParamInterface<bool> { | 129 public testing::WithParamInterface<bool> { |
97 public: | 130 public: |
| 131 ExtensionNetworkingPrivateApiTest() |
| 132 #if defined(OS_CHROMEOS) |
| 133 : detector_(NULL) |
| 134 #endif |
| 135 { |
| 136 } |
| 137 |
98 bool RunNetworkingSubtest(const std::string& subtest) { | 138 bool RunNetworkingSubtest(const std::string& subtest) { |
99 return RunExtensionSubtest( | 139 return RunExtensionSubtest( |
100 "networking", "main.html?" + subtest, | 140 "networking", "main.html?" + subtest, |
101 kFlagEnableFileAccess | kFlagLoadAsComponent); | 141 kFlagEnableFileAccess | kFlagLoadAsComponent); |
102 } | 142 } |
103 | 143 |
104 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 144 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
105 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
106 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 146 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
107 .WillRepeatedly(Return(true)); | 147 .WillRepeatedly(Return(true)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 CHECK(user); | 184 CHECK(user); |
145 std::string userhash; | 185 std::string userhash; |
146 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( | 186 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( |
147 user->email(), | 187 user->email(), |
148 base::Bind(&AssignString, &userhash_)); | 188 base::Bind(&AssignString, &userhash_)); |
149 content::RunAllPendingInMessageLoop(); | 189 content::RunAllPendingInMessageLoop(); |
150 CHECK(!userhash_.empty()); | 190 CHECK(!userhash_.empty()); |
151 } | 191 } |
152 | 192 |
153 virtual void SetUpOnMainThread() OVERRIDE { | 193 virtual void SetUpOnMainThread() OVERRIDE { |
| 194 detector_ = new NetworkPortalDetectorTestImpl(); |
| 195 NetworkPortalDetector::InitializeForTesting(detector_); |
| 196 |
154 ExtensionApiTest::SetUpOnMainThread(); | 197 ExtensionApiTest::SetUpOnMainThread(); |
155 content::RunAllPendingInMessageLoop(); | 198 content::RunAllPendingInMessageLoop(); |
156 | 199 |
157 InitializeSanitizedUsername(); | 200 InitializeSanitizedUsername(); |
158 | 201 |
159 ShillManagerClient::TestInterface* manager_test = | 202 ShillManagerClient::TestInterface* manager_test = |
160 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | 203 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); |
161 ShillDeviceClient::TestInterface* device_test = | 204 ShillDeviceClient::TestInterface* device_test = |
162 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 205 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
163 ShillProfileClient::TestInterface* profile_test = | 206 ShillProfileClient::TestInterface* profile_test = |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 content::RunAllPendingInMessageLoop(); | 326 content::RunAllPendingInMessageLoop(); |
284 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( | 327 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( |
285 profile(), | 328 profile(), |
286 &CreateNetworkingPrivateServiceClient); | 329 &CreateNetworkingPrivateServiceClient); |
287 } | 330 } |
288 | 331 |
289 #endif // OS_CHROMEOS | 332 #endif // OS_CHROMEOS |
290 | 333 |
291 protected: | 334 protected: |
292 #if defined(OS_CHROMEOS) | 335 #if defined(OS_CHROMEOS) |
| 336 NetworkPortalDetectorTestImpl* detector() { return detector_; } |
| 337 |
| 338 NetworkPortalDetectorTestImpl* detector_; |
293 policy::MockConfigurationPolicyProvider provider_; | 339 policy::MockConfigurationPolicyProvider provider_; |
294 std::string userhash_; | 340 std::string userhash_; |
295 #endif | 341 #endif |
296 }; | 342 }; |
297 | 343 |
298 // Place each subtest into a separate browser test so that the stub networking | 344 // Place each subtest into a separate browser test so that the stub networking |
299 // library state is reset for each subtest run. This way they won't affect each | 345 // library state is reset for each subtest run. This way they won't affect each |
300 // other. | 346 // other. |
301 | 347 |
302 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, StartConnect) { | 348 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, StartConnect) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 502 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
457 GetWifiTDLSStatus) { | 503 GetWifiTDLSStatus) { |
458 EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_; | 504 EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_; |
459 } | 505 } |
460 #endif | 506 #endif |
461 | 507 |
462 // NetworkPortalDetector is only enabled for Chrome OS. | 508 // NetworkPortalDetector is only enabled for Chrome OS. |
463 #if defined(OS_CHROMEOS) | 509 #if defined(OS_CHROMEOS) |
464 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 510 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
465 GetCaptivePortalStatus) { | 511 GetCaptivePortalStatus) { |
466 NetworkPortalDetectorTestImpl* detector = new NetworkPortalDetectorTestImpl(); | |
467 NetworkPortalDetector::InitializeForTesting(detector); | |
468 NetworkPortalDetector::CaptivePortalState state; | 512 NetworkPortalDetector::CaptivePortalState state; |
469 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 513 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
470 detector->SetDetectionResultsForTesting("stub_ethernet", state); | 514 detector()->SetDetectionResultsForTesting("stub_ethernet", state); |
471 | 515 |
472 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; | 516 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; |
473 detector->SetDetectionResultsForTesting("stub_wifi1", state); | 517 detector()->SetDetectionResultsForTesting("stub_wifi1", state); |
474 | 518 |
475 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | 519 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; |
476 detector->SetDetectionResultsForTesting("stub_wifi2", state); | 520 detector()->SetDetectionResultsForTesting("stub_wifi2", state); |
477 | 521 |
478 state.status = | 522 state.status = |
479 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; | 523 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; |
480 detector->SetDetectionResultsForTesting("stub_cellular1", state); | 524 detector()->SetDetectionResultsForTesting("stub_cellular1", state); |
481 | 525 |
482 EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; | 526 EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; |
483 } | 527 } |
| 528 |
| 529 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 530 CaptivePortalNotification) { |
| 531 detector()->SetDefaultNetworkPathForTesting("wifi"); |
| 532 NetworkPortalDetector::CaptivePortalState state; |
| 533 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
| 534 detector()->SetDetectionResultsForTesting("wifi", state); |
| 535 |
| 536 TestListener listener( |
| 537 "notifyPortalDetectorObservers", |
| 538 base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting, |
| 539 base::Unretained(detector()))); |
| 540 EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_; |
| 541 } |
484 #endif // defined(OS_CHROMEOS) | 542 #endif // defined(OS_CHROMEOS) |
485 | 543 |
486 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, | 544 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, |
487 ExtensionNetworkingPrivateApiTest, | 545 ExtensionNetworkingPrivateApiTest, |
488 testing::Bool()); | 546 testing::Bool()); |
489 | 547 |
490 } // namespace | 548 } // namespace |
OLD | NEW |