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/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 public: | 81 public: |
82 TestListener(const std::string& message, const base::Closure& callback) | 82 TestListener(const std::string& message, const base::Closure& callback) |
83 : message_(message), callback_(callback) { | 83 : message_(message), callback_(callback) { |
84 registrar_.Add(this, | 84 registrar_.Add(this, |
85 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE, | 85 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
86 content::NotificationService::AllSources()); | 86 content::NotificationService::AllSources()); |
87 } | 87 } |
88 | 88 |
89 virtual void Observe(int type, | 89 virtual void Observe(int type, |
90 const content::NotificationSource& /* source */, | 90 const content::NotificationSource& /* source */, |
91 const content::NotificationDetails& details) OVERRIDE { | 91 const content::NotificationDetails& details) override { |
92 const std::string& message = *content::Details<std::string>(details).ptr(); | 92 const std::string& message = *content::Details<std::string>(details).ptr(); |
93 if (message == message_) | 93 if (message == message_) |
94 callback_.Run(); | 94 callback_.Run(); |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 std::string message_; | 98 std::string message_; |
99 base::Closure callback_; | 99 base::Closure callback_; |
100 | 100 |
101 content::NotificationRegistrar registrar_; | 101 content::NotificationRegistrar registrar_; |
102 | 102 |
103 DISALLOW_COPY_AND_ASSIGN(TestListener); | 103 DISALLOW_COPY_AND_ASSIGN(TestListener); |
104 }; | 104 }; |
105 #else // !defined(OS_CHROMEOS) | 105 #else // !defined(OS_CHROMEOS) |
106 | 106 |
107 // Stub Verify* methods implementation to satisfy expectations of | 107 // Stub Verify* methods implementation to satisfy expectations of |
108 // networking_private_apitest. | 108 // networking_private_apitest. |
109 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, | 109 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, |
110 // and update networking_private_apitest to use and expect valid data. | 110 // and update networking_private_apitest to use and expect valid data. |
111 // That will eliminate the need for mock implementation. | 111 // That will eliminate the need for mock implementation. |
112 class CryptoVerifyStub | 112 class CryptoVerifyStub |
113 : public extensions::NetworkingPrivateServiceClient::CryptoVerify { | 113 : public extensions::NetworkingPrivateServiceClient::CryptoVerify { |
114 virtual void VerifyDestination(const Credentials& verification_properties, | 114 virtual void VerifyDestination(const Credentials& verification_properties, |
115 bool* verified, | 115 bool* verified, |
116 std::string* error) OVERRIDE { | 116 std::string* error) override { |
117 *verified = true; | 117 *verified = true; |
118 } | 118 } |
119 | 119 |
120 virtual void VerifyAndEncryptCredentials( | 120 virtual void VerifyAndEncryptCredentials( |
121 const std::string& network_guid, | 121 const std::string& network_guid, |
122 const Credentials& credentials, | 122 const Credentials& credentials, |
123 const VerifyAndEncryptCredentialsCallback& callback) OVERRIDE { | 123 const VerifyAndEncryptCredentialsCallback& callback) override { |
124 callback.Run("encrypted_credentials", ""); | 124 callback.Run("encrypted_credentials", ""); |
125 } | 125 } |
126 | 126 |
127 virtual void VerifyAndEncryptData(const Credentials& verification_properties, | 127 virtual void VerifyAndEncryptData(const Credentials& verification_properties, |
128 const std::string& data, | 128 const std::string& data, |
129 std::string* base64_encoded_ciphertext, | 129 std::string* base64_encoded_ciphertext, |
130 std::string* error) OVERRIDE { | 130 std::string* error) override { |
131 *base64_encoded_ciphertext = "encrypted_data"; | 131 *base64_encoded_ciphertext = "encrypted_data"; |
132 } | 132 } |
133 }; | 133 }; |
134 #endif // defined(OS_CHROMEOS) | 134 #endif // defined(OS_CHROMEOS) |
135 | 135 |
136 class ExtensionNetworkingPrivateApiTest | 136 class ExtensionNetworkingPrivateApiTest |
137 : public ExtensionApiTest { | 137 : public ExtensionApiTest { |
138 public: | 138 public: |
139 ExtensionNetworkingPrivateApiTest() | 139 ExtensionNetworkingPrivateApiTest() |
140 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
141 : detector_(NULL), | 141 : detector_(NULL), |
142 service_test_(NULL), | 142 service_test_(NULL), |
143 manager_test_(NULL), | 143 manager_test_(NULL), |
144 device_test_(NULL) | 144 device_test_(NULL) |
145 #endif | 145 #endif |
146 { | 146 { |
147 } | 147 } |
148 | 148 |
149 bool RunNetworkingSubtest(const std::string& subtest) { | 149 bool RunNetworkingSubtest(const std::string& subtest) { |
150 return RunExtensionSubtest( | 150 return RunExtensionSubtest( |
151 "networking", "main.html?" + subtest, | 151 "networking", "main.html?" + subtest, |
152 kFlagEnableFileAccess | kFlagLoadAsComponent); | 152 kFlagEnableFileAccess | kFlagLoadAsComponent); |
153 } | 153 } |
154 | 154 |
155 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 155 virtual void SetUpInProcessBrowserTestFixture() override { |
156 #if defined(OS_CHROMEOS) | 156 #if defined(OS_CHROMEOS) |
157 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 157 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
158 .WillRepeatedly(Return(true)); | 158 .WillRepeatedly(Return(true)); |
159 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 159 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
160 #endif | 160 #endif |
161 | 161 |
162 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 162 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
163 } | 163 } |
164 | 164 |
165 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
166 static void AssignString(std::string* out, | 166 static void AssignString(std::string* out, |
167 DBusMethodCallStatus call_status, | 167 DBusMethodCallStatus call_status, |
168 const std::string& result) { | 168 const std::string& result) { |
169 CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS); | 169 CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS); |
170 *out = result; | 170 *out = result; |
171 } | 171 } |
172 | 172 |
173 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 173 virtual void SetUpCommandLine(CommandLine* command_line) override { |
174 ExtensionApiTest::SetUpCommandLine(command_line); | 174 ExtensionApiTest::SetUpCommandLine(command_line); |
175 // Whitelist the extension ID of the test extension. | 175 // Whitelist the extension ID of the test extension. |
176 command_line->AppendSwitchASCII( | 176 command_line->AppendSwitchASCII( |
177 extensions::switches::kWhitelistedExtensionID, | 177 extensions::switches::kWhitelistedExtensionID, |
178 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 178 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
179 | 179 |
180 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI | 180 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI |
181 // uses the ProfileHelper to obtain the userhash crbug/238623. | 181 // uses the ProfileHelper to obtain the userhash crbug/238623. |
182 const std::string login_user = chromeos::login::CanonicalizeUserID( | 182 const std::string login_user = chromeos::login::CanonicalizeUserID( |
183 command_line->GetSwitchValueNative(chromeos::switches::kLoginUser)); | 183 command_line->GetSwitchValueNative(chromeos::switches::kLoginUser)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 236 |
237 void AddService(const std::string& service_path, | 237 void AddService(const std::string& service_path, |
238 const std::string& name, | 238 const std::string& name, |
239 const std::string& type, | 239 const std::string& type, |
240 const std::string& state) { | 240 const std::string& state) { |
241 service_test_->AddService( | 241 service_test_->AddService( |
242 service_path, service_path + "_guid", name, | 242 service_path, service_path + "_guid", name, |
243 type, state, true /* add_to_visible */); | 243 type, state, true /* add_to_visible */); |
244 } | 244 } |
245 | 245 |
246 virtual void SetUpOnMainThread() OVERRIDE { | 246 virtual void SetUpOnMainThread() override { |
247 detector_ = new NetworkPortalDetectorTestImpl(); | 247 detector_ = new NetworkPortalDetectorTestImpl(); |
248 NetworkPortalDetector::InitializeForTesting(detector_); | 248 NetworkPortalDetector::InitializeForTesting(detector_); |
249 | 249 |
250 ExtensionApiTest::SetUpOnMainThread(); | 250 ExtensionApiTest::SetUpOnMainThread(); |
251 content::RunAllPendingInMessageLoop(); | 251 content::RunAllPendingInMessageLoop(); |
252 | 252 |
253 InitializeSanitizedUsername(); | 253 InitializeSanitizedUsername(); |
254 | 254 |
255 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 255 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
256 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); | 256 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 service_test_->SetServiceProperty("stub_wifi2", | 362 service_test_->SetServiceProperty("stub_wifi2", |
363 shill::kProfileProperty, | 363 shill::kProfileProperty, |
364 base::StringValue(kUser1ProfilePath)); | 364 base::StringValue(kUser1ProfilePath)); |
365 profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); | 365 profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); |
366 | 366 |
367 AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline); | 367 AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline); |
368 | 368 |
369 content::RunAllPendingInMessageLoop(); | 369 content::RunAllPendingInMessageLoop(); |
370 } | 370 } |
371 #else // !defined(OS_CHROMEOS) | 371 #else // !defined(OS_CHROMEOS) |
372 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 372 virtual void SetUpCommandLine(CommandLine* command_line) override { |
373 ExtensionApiTest::SetUpCommandLine(command_line); | 373 ExtensionApiTest::SetUpCommandLine(command_line); |
374 // Whitelist the extension ID of the test extension. | 374 // Whitelist the extension ID of the test extension. |
375 command_line->AppendSwitchASCII( | 375 command_line->AppendSwitchASCII( |
376 extensions::switches::kWhitelistedExtensionID, | 376 extensions::switches::kWhitelistedExtensionID, |
377 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 377 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
378 } | 378 } |
379 | 379 |
380 static KeyedService* CreateNetworkingPrivateServiceClient( | 380 static KeyedService* CreateNetworkingPrivateServiceClient( |
381 content::BrowserContext* profile) { | 381 content::BrowserContext* profile) { |
382 return new extensions::NetworkingPrivateServiceClient( | 382 return new extensions::NetworkingPrivateServiceClient( |
383 new wifi::FakeWiFiService(), new CryptoVerifyStub()); | 383 new wifi::FakeWiFiService(), new CryptoVerifyStub()); |
384 } | 384 } |
385 | 385 |
386 virtual void SetUpOnMainThread() OVERRIDE { | 386 virtual void SetUpOnMainThread() override { |
387 ExtensionApiTest::SetUpOnMainThread(); | 387 ExtensionApiTest::SetUpOnMainThread(); |
388 content::RunAllPendingInMessageLoop(); | 388 content::RunAllPendingInMessageLoop(); |
389 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( | 389 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( |
390 profile(), | 390 profile(), |
391 &CreateNetworkingPrivateServiceClient); | 391 &CreateNetworkingPrivateServiceClient); |
392 } | 392 } |
393 | 393 |
394 #endif // OS_CHROMEOS | 394 #endif // OS_CHROMEOS |
395 | 395 |
396 protected: | 396 protected: |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 630 |
631 TestListener listener( | 631 TestListener listener( |
632 "notifyPortalDetectorObservers", | 632 "notifyPortalDetectorObservers", |
633 base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting, | 633 base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting, |
634 base::Unretained(detector()))); | 634 base::Unretained(detector()))); |
635 EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_; | 635 EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_; |
636 } | 636 } |
637 #endif // defined(OS_CHROMEOS) | 637 #endif // defined(OS_CHROMEOS) |
638 | 638 |
639 } // namespace | 639 } // namespace |
OLD | NEW |