| 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" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 private: | 210 private: |
| 211 FakeGCDApiFlowFactory* factory_; | 211 FakeGCDApiFlowFactory* factory_; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 std::map<GURL /*request url*/, std::string /*response json*/> responses_; | 214 std::map<GURL /*request url*/, std::string /*response json*/> responses_; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 class GcdPrivateAPITest : public ExtensionApiTest { | 217 class GcdPrivateAPITest : public ExtensionApiTest { |
| 218 public: | 218 public: |
| 219 GcdPrivateAPITest() : url_fetcher_factory_(NULL) { | 219 GcdPrivateAPITest() : url_fetcher_factory_(&url_fetcher_impl_factory_) { |
| 220 #if defined(ENABLE_MDNS) | 220 #if defined(ENABLE_MDNS) |
| 221 test_service_discovery_client_ = | 221 test_service_discovery_client_ = |
| 222 new local_discovery::TestServiceDiscoveryClient(); | 222 new local_discovery::TestServiceDiscoveryClient(); |
| 223 test_service_discovery_client_->Start(); | 223 test_service_discovery_client_->Start(); |
| 224 #endif // ENABLE_MDNS | 224 #endif // ENABLE_MDNS |
| 225 } | 225 } |
| 226 | 226 |
| 227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 227 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 228 ExtensionApiTest::SetUpCommandLine(command_line); | 228 ExtensionApiTest::SetUpCommandLine(command_line); |
| 229 command_line->AppendSwitchASCII( | 229 command_line->AppendSwitchASCII( |
| 230 extensions::switches::kWhitelistedExtensionID, | 230 extensions::switches::kWhitelistedExtensionID, |
| 231 "ddchlicdkolnonkihahngkmmmjnjlkkf"); | 231 "ddchlicdkolnonkihahngkmmmjnjlkkf"); |
| 232 } | 232 } |
| 233 | 233 |
| 234 protected: | 234 protected: |
| 235 FakeGCDApiFlowFactory api_flow_factory_; | 235 FakeGCDApiFlowFactory api_flow_factory_; |
| 236 net::URLFetcherImplFactory url_fetcher_impl_factory_; |
| 236 net::FakeURLFetcherFactory url_fetcher_factory_; | 237 net::FakeURLFetcherFactory url_fetcher_factory_; |
| 237 | 238 |
| 238 #if defined(ENABLE_MDNS) | 239 #if defined(ENABLE_MDNS) |
| 239 scoped_refptr<local_discovery::TestServiceDiscoveryClient> | 240 scoped_refptr<local_discovery::TestServiceDiscoveryClient> |
| 240 test_service_discovery_client_; | 241 test_service_discovery_client_; |
| 241 #endif // ENABLE_MDNS | 242 #endif // ENABLE_MDNS |
| 242 }; | 243 }; |
| 243 | 244 |
| 244 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { | 245 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, GetCloudList) { |
| 245 api_flow_factory_.SetResponse( | 246 api_flow_factory_.SetResponse( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, | 282 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, |
| 282 test_service_discovery_client_, | 283 test_service_discovery_client_, |
| 283 kAnnouncePacket, | 284 kAnnouncePacket, |
| 284 sizeof(kAnnouncePacket)), | 285 sizeof(kAnnouncePacket)), |
| 285 base::TimeDelta::FromSeconds(1)); | 286 base::TimeDelta::FromSeconds(1)); |
| 286 | 287 |
| 287 EXPECT_TRUE( | 288 EXPECT_TRUE( |
| 288 RunExtensionSubtest("gcd_private/api", "receive_new_device.html")); | 289 RunExtensionSubtest("gcd_private/api", "receive_new_device.html")); |
| 289 } | 290 } |
| 290 | 291 |
| 291 // http://crbug.com/312328 | 292 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, AddRemove) { |
| 292 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, DISABLED_AddRemove) { | |
| 293 test_service_discovery_client_->SimulateReceive(kAnnouncePacket, | 293 test_service_discovery_client_->SimulateReceive(kAnnouncePacket, |
| 294 sizeof(kAnnouncePacket)); | 294 sizeof(kAnnouncePacket)); |
| 295 | 295 |
| 296 base::MessageLoopProxy::current()->PostDelayedTask( | 296 base::MessageLoopProxy::current()->PostDelayedTask( |
| 297 FROM_HERE, | 297 FROM_HERE, |
| 298 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, | 298 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, |
| 299 test_service_discovery_client_, | 299 test_service_discovery_client_, |
| 300 kGoodbyePacket, | 300 kGoodbyePacket, |
| 301 sizeof(kGoodbyePacket)), | 301 sizeof(kGoodbyePacket)), |
| 302 base::TimeDelta::FromSeconds(1)); | 302 base::TimeDelta::FromSeconds(1)); |
| 303 | 303 |
| 304 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); | 304 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); |
| 305 } | 305 } |
| 306 | 306 |
| 307 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, SendQuery) { | 307 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, SendQuery) { |
| 308 // TODO(noamsml): Win Dbg has a workaround that makes RunExtensionSubtest | 308 // TODO(noamsml): Win Dbg has a workaround that makes RunExtensionSubtest |
| 309 // always return true without actually running the test. Remove when fixed. | 309 // always return true without actually running the test. Remove when fixed. |
| 310 // See http://crbug.com/177163 for details. | 310 // See http://crbug.com/177163 for details. |
| 311 #if !defined(OS_WIN) || defined(NDEBUG) | 311 #if !defined(OS_WIN) || defined(NDEBUG) |
| 312 EXPECT_CALL(*test_service_discovery_client_, | 312 EXPECT_CALL(*test_service_discovery_client_, |
| 313 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), | 313 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), |
| 314 sizeof(kQueryPacket)))).Times(2); | 314 sizeof(kQueryPacket)))).Times(2); |
| 315 #endif | 315 #endif |
| 316 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); | 316 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); |
| 317 } | 317 } |
| 318 | 318 |
| 319 #endif // ENABLE_MDNS | 319 #endif // ENABLE_MDNS |
| 320 | 320 |
| 321 } // namespace | 321 } // namespace |
| OLD | NEW |