| OLD | NEW |
| 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/wifi/mock_wifi_manager.h" |
| 12 #include "chrome/common/extensions/api/mdns.h" | 13 #include "chrome/common/extensions/api/mdns.h" |
| 13 #include "extensions/common/switches.h" | 14 #include "extensions/common/switches.h" |
| 14 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 17 |
| 17 #if defined(ENABLE_MDNS) | 18 #if defined(ENABLE_MDNS) |
| 18 #include "chrome/browser/local_discovery/test_service_discovery_client.h" | 19 #include "chrome/browser/local_discovery/test_service_discovery_client.h" |
| 19 #endif // ENABLE_MDNS | 20 #endif // ENABLE_MDNS |
| 20 | 21 |
| 21 namespace api = extensions::api; | 22 namespace api = extensions::api; |
| 22 | 23 |
| 24 using testing::Invoke; |
| 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 const char kCloudPrintResponse[] = | 28 const char kCloudPrintResponse[] = |
| 26 "{" | 29 "{" |
| 27 " \"success\": true," | 30 " \"success\": true," |
| 28 " \"printers\": [" | 31 " \"printers\": [" |
| 29 " {\"id\" : \"someCloudPrintID\"," | 32 " {\"id\" : \"someCloudPrintID\"," |
| 30 " \"displayName\": \"someCloudPrintDisplayName\"," | 33 " \"displayName\": \"someCloudPrintDisplayName\"," |
| 31 " \"description\": \"someCloudPrintDescription\"}" | 34 " \"description\": \"someCloudPrintDescription\"}" |
| 32 " ]" | 35 " ]" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 #endif // ENABLE_MDNS | 227 #endif // ENABLE_MDNS |
| 225 } | 228 } |
| 226 | 229 |
| 227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 230 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 228 ExtensionApiTest::SetUpCommandLine(command_line); | 231 ExtensionApiTest::SetUpCommandLine(command_line); |
| 229 command_line->AppendSwitchASCII( | 232 command_line->AppendSwitchASCII( |
| 230 extensions::switches::kWhitelistedExtensionID, | 233 extensions::switches::kWhitelistedExtensionID, |
| 231 "ddchlicdkolnonkihahngkmmmjnjlkkf"); | 234 "ddchlicdkolnonkihahngkmmmjnjlkkf"); |
| 232 } | 235 } |
| 233 | 236 |
| 237 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 238 virtual void OnCreateWifiManager() { |
| 239 wifi_manager_ = wifi_manager_factory_.GetLastCreatedWifiManager(); |
| 240 |
| 241 EXPECT_CALL(*wifi_manager_, Start()); |
| 242 |
| 243 EXPECT_CALL(*wifi_manager_, |
| 244 RequestNetworkCredentialsInternal("SuccessNetwork")) |
| 245 .WillOnce(Invoke(this, &GcdPrivateAPITest::RespondToNetwork)); |
| 246 |
| 247 EXPECT_CALL(*wifi_manager_, |
| 248 RequestNetworkCredentialsInternal("FailureNetwork")) |
| 249 .WillOnce(Invoke(this, &GcdPrivateAPITest::RespondToNetwork)); |
| 250 } |
| 251 |
| 252 void RespondToNetwork(const std::string& network) { |
| 253 bool success = (network == "SuccessNetwork"); |
| 254 |
| 255 wifi_manager_->CallRequestNetworkCredentialsCallback( |
| 256 success, network, success ? "SuccessPass" : ""); |
| 257 } |
| 258 #endif |
| 259 |
| 234 protected: | 260 protected: |
| 235 FakeGCDApiFlowFactory api_flow_factory_; | 261 FakeGCDApiFlowFactory api_flow_factory_; |
| 236 net::FakeURLFetcherFactory url_fetcher_factory_; | 262 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 237 | 263 |
| 238 #if defined(ENABLE_MDNS) | 264 #if defined(ENABLE_MDNS) |
| 239 scoped_refptr<local_discovery::TestServiceDiscoveryClient> | 265 scoped_refptr<local_discovery::TestServiceDiscoveryClient> |
| 240 test_service_discovery_client_; | 266 test_service_discovery_client_; |
| 241 #endif // ENABLE_MDNS | 267 #endif // ENABLE_MDNS |
| 268 |
| 269 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 270 local_discovery::wifi::MockWifiManagerFactory wifi_manager_factory_; |
| 271 local_discovery::wifi::MockWifiManager* wifi_manager_; |
| 272 #endif |
| 242 }; | 273 }; |
| 243 | 274 |
| 244 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { | 275 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { |
| 245 api_flow_factory_.SetResponse( | 276 api_flow_factory_.SetResponse( |
| 246 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse); | 277 GURL("https://www.google.com/cloudprint/search"), kCloudPrintResponse); |
| 247 | 278 |
| 248 api_flow_factory_.SetResponse( | 279 api_flow_factory_.SetResponse( |
| 249 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse); | 280 GURL("https://www.googleapis.com/clouddevices/v1/devices"), kGCDResponse); |
| 250 | 281 |
| 251 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html")); | 282 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "get_cloud_list.html")); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 #if !defined(OS_WIN) || defined(NDEBUG) | 342 #if !defined(OS_WIN) || defined(NDEBUG) |
| 312 EXPECT_CALL(*test_service_discovery_client_, | 343 EXPECT_CALL(*test_service_discovery_client_, |
| 313 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), | 344 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), |
| 314 sizeof(kQueryPacket)))).Times(2); | 345 sizeof(kQueryPacket)))).Times(2); |
| 315 #endif | 346 #endif |
| 316 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); | 347 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); |
| 317 } | 348 } |
| 318 | 349 |
| 319 #endif // ENABLE_MDNS | 350 #endif // ENABLE_MDNS |
| 320 | 351 |
| 352 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 353 |
| 354 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiMessage) { |
| 355 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_message.html")); |
| 356 } |
| 357 |
| 358 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiPasswords) { |
| 359 EXPECT_CALL(wifi_manager_factory_, WifiManagerCreated()) |
| 360 .WillOnce(Invoke(this, &GcdPrivateAPITest::OnCreateWifiManager)); |
| 361 |
| 362 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_password.html")); |
| 363 } |
| 364 |
| 365 #endif // ENABLE_WIFI_BOOTSTRAPPING |
| 366 |
| 321 } // namespace | 367 } // namespace |
| OLD | NEW |