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