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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { | 170 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { |
171 public: | 171 public: |
172 FakeGCDApiFlowFactory() { | 172 FakeGCDApiFlowFactory() { |
173 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); | 173 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); |
174 } | 174 } |
175 | 175 |
176 virtual ~FakeGCDApiFlowFactory() { | 176 virtual ~FakeGCDApiFlowFactory() { |
177 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(NULL); | 177 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(NULL); |
178 } | 178 } |
179 | 179 |
180 virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() OVERRIDE { | 180 virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() override { |
181 return scoped_ptr<local_discovery::GCDApiFlow>(new FakeGCDApiFlow(this)); | 181 return scoped_ptr<local_discovery::GCDApiFlow>(new FakeGCDApiFlow(this)); |
182 } | 182 } |
183 | 183 |
184 void SetResponse(const GURL& url, const std::string& response) { | 184 void SetResponse(const GURL& url, const std::string& response) { |
185 responses_[url] = response; | 185 responses_[url] = response; |
186 } | 186 } |
187 | 187 |
188 private: | 188 private: |
189 class FakeGCDApiFlow : public local_discovery::GCDApiFlow { | 189 class FakeGCDApiFlow : public local_discovery::GCDApiFlow { |
190 public: | 190 public: |
191 explicit FakeGCDApiFlow(FakeGCDApiFlowFactory* factory) | 191 explicit FakeGCDApiFlow(FakeGCDApiFlowFactory* factory) |
192 : factory_(factory) {} | 192 : factory_(factory) {} |
193 | 193 |
194 virtual ~FakeGCDApiFlow() {} | 194 virtual ~FakeGCDApiFlow() {} |
195 | 195 |
196 virtual void Start(scoped_ptr<Request> request) OVERRIDE { | 196 virtual void Start(scoped_ptr<Request> request) override { |
197 std::string response_str = factory_->responses_[request->GetURL()]; | 197 std::string response_str = factory_->responses_[request->GetURL()]; |
198 | 198 |
199 if (response_str == kResponseValueFailure) { | 199 if (response_str == kResponseValueFailure) { |
200 request->OnGCDAPIFlowError( | 200 request->OnGCDAPIFlowError( |
201 local_discovery::GCDApiFlow::ERROR_MALFORMED_RESPONSE); | 201 local_discovery::GCDApiFlow::ERROR_MALFORMED_RESPONSE); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 scoped_ptr<base::Value> response(base::JSONReader::Read(response_str)); | 205 scoped_ptr<base::Value> response(base::JSONReader::Read(response_str)); |
206 ASSERT_TRUE(response); | 206 ASSERT_TRUE(response); |
(...skipping 14 matching lines...) Expand all Loading... |
221 class GcdPrivateAPITest : public ExtensionApiTest { | 221 class GcdPrivateAPITest : public ExtensionApiTest { |
222 public: | 222 public: |
223 GcdPrivateAPITest() : url_fetcher_factory_(&url_fetcher_impl_factory_) { | 223 GcdPrivateAPITest() : url_fetcher_factory_(&url_fetcher_impl_factory_) { |
224 #if defined(ENABLE_MDNS) | 224 #if defined(ENABLE_MDNS) |
225 test_service_discovery_client_ = | 225 test_service_discovery_client_ = |
226 new local_discovery::TestServiceDiscoveryClient(); | 226 new local_discovery::TestServiceDiscoveryClient(); |
227 test_service_discovery_client_->Start(); | 227 test_service_discovery_client_->Start(); |
228 #endif // ENABLE_MDNS | 228 #endif // ENABLE_MDNS |
229 } | 229 } |
230 | 230 |
231 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 231 virtual void SetUpCommandLine(CommandLine* command_line) override { |
232 ExtensionApiTest::SetUpCommandLine(command_line); | 232 ExtensionApiTest::SetUpCommandLine(command_line); |
233 command_line->AppendSwitchASCII( | 233 command_line->AppendSwitchASCII( |
234 extensions::switches::kWhitelistedExtensionID, | 234 extensions::switches::kWhitelistedExtensionID, |
235 "ddchlicdkolnonkihahngkmmmjnjlkkf"); | 235 "ddchlicdkolnonkihahngkmmmjnjlkkf"); |
236 } | 236 } |
237 | 237 |
238 #if defined(ENABLE_WIFI_BOOTSTRAPPING) | 238 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
239 virtual void OnCreateWifiManager() { | 239 virtual void OnCreateWifiManager() { |
240 wifi_manager_ = wifi_manager_factory_.GetLastCreatedWifiManager(); | 240 wifi_manager_ = wifi_manager_factory_.GetLastCreatedWifiManager(); |
241 | 241 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 EXPECT_CALL(wifi_manager_factory_, WifiManagerCreated()) | 364 EXPECT_CALL(wifi_manager_factory_, WifiManagerCreated()) |
365 .WillOnce(Invoke(this, &GcdPrivateAPITest::OnCreateWifiManager)); | 365 .WillOnce(Invoke(this, &GcdPrivateAPITest::OnCreateWifiManager)); |
366 #endif | 366 #endif |
367 | 367 |
368 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_password.html")); | 368 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "wifi_password.html")); |
369 } | 369 } |
370 | 370 |
371 #endif // ENABLE_WIFI_BOOTSTRAPPING | 371 #endif // ENABLE_WIFI_BOOTSTRAPPING |
372 | 372 |
373 } // namespace | 373 } // namespace |
OLD | NEW |