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

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc

Issue 450533003: Added function to get list of networks with prefetched passwords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" 9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/local_discovery/gcd_api_flow.h" 12 #include "chrome/browser/local_discovery/gcd_api_flow.h"
13 #include "chrome/browser/local_discovery/wifi/mock_wifi_manager.h"
13 #include "chrome/common/extensions/api/mdns.h" 14 #include "chrome/common/extensions/api/mdns.h"
14 #include "extensions/common/switches.h" 15 #include "extensions/common/switches.h"
15 #include "net/url_request/test_url_fetcher_factory.h" 16 #include "net/url_request/test_url_fetcher_factory.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 18
18 #if defined(ENABLE_MDNS) 19 #if defined(ENABLE_MDNS)
19 #include "chrome/browser/local_discovery/test_service_discovery_client.h" 20 #include "chrome/browser/local_discovery/test_service_discovery_client.h"
20 #endif // ENABLE_MDNS 21 #endif // ENABLE_MDNS
21 22
22 namespace api = extensions::api; 23 namespace api = extensions::api;
23 24
25 using testing::Invoke;
26
24 namespace { 27 namespace {
25 28
26 const char kCloudPrintResponse[] = 29 const char kCloudPrintResponse[] =
27 "{" 30 "{"
28 " \"success\": true," 31 " \"success\": true,"
29 " \"printers\": [" 32 " \"printers\": ["
30 " {\"id\" : \"someCloudPrintID\"," 33 " {\"id\" : \"someCloudPrintID\","
31 " \"displayName\": \"someCloudPrintDisplayName\"," 34 " \"displayName\": \"someCloudPrintDisplayName\","
32 " \"description\": \"someCloudPrintDescription\"}" 35 " \"description\": \"someCloudPrintDescription\"}"
33 " ]" 36 " ]"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 #endif // ENABLE_MDNS 228 #endif // ENABLE_MDNS
226 } 229 }
227 230
228 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 231 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
229 ExtensionApiTest::SetUpCommandLine(command_line); 232 ExtensionApiTest::SetUpCommandLine(command_line);
230 command_line->AppendSwitchASCII( 233 command_line->AppendSwitchASCII(
231 extensions::switches::kWhitelistedExtensionID, 234 extensions::switches::kWhitelistedExtensionID,
232 "ddchlicdkolnonkihahngkmmmjnjlkkf"); 235 "ddchlicdkolnonkihahngkmmmjnjlkkf");
233 } 236 }
234 237
238 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
239 virtual void OnCreateWifiManager() {
240 wifi_manager_ = wifi_manager_factory_.GetLastCreatedWifiManager();
241
242 EXPECT_CALL(*wifi_manager_, Start());
243
244 EXPECT_CALL(*wifi_manager_,
245 RequestNetworkCredentialsInternal("SuccessNetwork"))
246 .WillOnce(Invoke(this, &GcdPrivateAPITest::RespondToNetwork));
247
248 EXPECT_CALL(*wifi_manager_,
249 RequestNetworkCredentialsInternal("FailureNetwork"))
250 .WillOnce(Invoke(this, &GcdPrivateAPITest::RespondToNetwork));
251 }
252
253 void RespondToNetwork(const std::string& network) {
254 bool success = (network == "SuccessNetwork");
255
256 wifi_manager_->CallRequestNetworkCredentialsCallback(
257 success, network, success ? "SuccessPass" : "");
258 }
259 #endif
260
235 protected: 261 protected:
236 FakeGCDApiFlowFactory api_flow_factory_; 262 FakeGCDApiFlowFactory api_flow_factory_;
237 net::URLFetcherImplFactory url_fetcher_impl_factory_; 263 net::URLFetcherImplFactory url_fetcher_impl_factory_;
238 net::FakeURLFetcherFactory url_fetcher_factory_; 264 net::FakeURLFetcherFactory url_fetcher_factory_;
239 265
240 #if defined(ENABLE_MDNS) 266 #if defined(ENABLE_MDNS)
241 scoped_refptr<local_discovery::TestServiceDiscoveryClient> 267 scoped_refptr<local_discovery::TestServiceDiscoveryClient>
242 test_service_discovery_client_; 268 test_service_discovery_client_;
243 #endif // ENABLE_MDNS 269 #endif // ENABLE_MDNS
270
271 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
272 local_discovery::wifi::MockWifiManagerFactory wifi_manager_factory_;
273 local_discovery::wifi::MockWifiManager* wifi_manager_;
274 #endif
244 }; 275 };
245 276
246 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { 277 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) {
247 api_flow_factory_.SetResponse( 278 api_flow_factory_.SetResponse(
248 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse); 279 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse);
249 280
250 api_flow_factory_.SetResponse( 281 api_flow_factory_.SetResponse(
251 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse); 282 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse);
252 283
253 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html")); 284 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html"));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 #if !defined(OS_WIN) || defined(NDEBUG) 343 #if !defined(OS_WIN) || defined(NDEBUG)
313 EXPECT_CALL(*test_service_discovery_client_, 344 EXPECT_CALL(*test_service_discovery_client_,
314 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), 345 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket),
315 sizeof(kQueryPacket)))).Times(2); 346 sizeof(kQueryPacket)))).Times(2);
316 #endif 347 #endif
317 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); 348 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html"));
318 } 349 }
319 350
320 #endif // ENABLE_MDNS 351 #endif // ENABLE_MDNS
321 352
353 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
354
355 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiMessage) {
356 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_message.html"));
357 }
358
359 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiPasswords) {
360 // TODO(noamsml): Win Dbg has a workaround that makes RunExtensionSubtest
361 // always return true without actually running the test. Remove when fixed.
362 // See http://crbug.com/177163 for details.
363 #if !defined(OS_WIN) || defined(NDEBUG)
364 EXPECT_CALL(wifi_manager_factory_, WifiManagerCreated())
365 .WillOnce(Invoke(this, &GcdPrivateAPITest::OnCreateWifiManager));
366 #endif
367
368 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_password.html"));
369 }
370
371 #endif // ENABLE_WIFI_BOOTSTRAPPING
372
322 } // namespace 373 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/gcd_private/gcd_private_api.cc ('k') | chrome/browser/local_discovery/wifi/mock_wifi_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698