OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "mojo/application/public/cpp/application_connection.h" | 12 #include "mojo/application/public/cpp/application_connection.h" |
13 #include "mojo/application/public/cpp/application_delegate.h" | 13 #include "mojo/application/public/cpp/application_delegate.h" |
14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
15 #include "mojo/application/public/cpp/connect.h" | 15 #include "mojo/application/public/cpp/connect.h" |
16 #include "mojo/application/public/cpp/interface_factory.h" | 16 #include "mojo/application/public/cpp/interface_factory.h" |
17 #include "mojo/application/public/cpp/service_provider_impl.h" | 17 #include "mojo/application/public/cpp/service_provider_impl.h" |
18 #include "mojo/application/public/interfaces/content_handler.mojom.h" | 18 #include "mojo/application/public/interfaces/content_handler.mojom.h" |
19 #include "mojo/common/weak_binding_set.h" | 19 #include "mojo/common/weak_binding_set.h" |
20 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 21 #include "mojo/shell/application_fetcher.h" |
21 #include "mojo/shell/application_loader.h" | 22 #include "mojo/shell/application_loader.h" |
22 #include "mojo/shell/application_manager.h" | 23 #include "mojo/shell/application_manager.h" |
23 #include "mojo/shell/capability_filter_unittest.mojom.h" | 24 #include "mojo/shell/capability_filter_unittest.mojom.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace mojo { | 27 namespace mojo { |
27 namespace shell { | 28 namespace shell { |
28 namespace { | 29 namespace { |
29 | 30 |
30 const char kTestMimeType[] = "test/mime-type"; | 31 const char kTestMimeType[] = "test/mime-type"; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 base::Callback<void(const base::FilePath&, bool)> callback) override {} | 278 base::Callback<void(const base::FilePath&, bool)> callback) override {} |
278 std::string MimeType() override { return kTestMimeType; } | 279 std::string MimeType() override { return kTestMimeType; } |
279 bool HasMojoMagic() override { return false; } | 280 bool HasMojoMagic() override { return false; } |
280 bool PeekFirstLine(std::string* line) override { return false; } | 281 bool PeekFirstLine(std::string* line) override { return false; } |
281 | 282 |
282 const GURL url_; | 283 const GURL url_; |
283 | 284 |
284 DISALLOW_COPY_AND_ASSIGN(TestFetcher); | 285 DISALLOW_COPY_AND_ASSIGN(TestFetcher); |
285 }; | 286 }; |
286 | 287 |
287 class TestApplicationManagerDelegate : public ApplicationManager::Delegate { | 288 class TestApplicationFetcher : public ApplicationFetcher { |
288 public: | 289 public: |
289 TestApplicationManagerDelegate() {} | 290 TestApplicationFetcher() {} |
290 ~TestApplicationManagerDelegate() override {} | 291 ~TestApplicationFetcher() override {} |
291 | 292 |
292 void set_use_test_fetcher(bool use_test_fetcher) { | 293 void set_use_test_fetcher(bool use_test_fetcher) { |
293 use_test_fetcher_ = use_test_fetcher; | 294 use_test_fetcher_ = use_test_fetcher; |
294 } | 295 } |
295 | 296 |
296 private: | 297 private: |
297 // Overridden from ApplicationManager::Delegate: | 298 // Overridden from ApplicationFetcher: |
298 GURL ResolveMappings(const GURL& url) override { | 299 void SetApplicationManager(ApplicationManager* manager) override {} |
| 300 GURL ResolveURL(const GURL& url) override { |
299 return url; | 301 return url; |
300 } | 302 } |
301 GURL ResolveMojoURL(const GURL& url) override { | 303 void FetchRequest(URLRequestPtr request, |
302 return url; | 304 const Fetcher::FetchCallback& loader_callback) override { |
303 } | 305 if (use_test_fetcher_) |
304 bool CreateFetcher(const GURL& url, | 306 new TestFetcher(GURL(request->url), loader_callback); |
305 const Fetcher::FetchCallback& loader_callback) override { | |
306 if (use_test_fetcher_) { | |
307 new TestFetcher(url, loader_callback); | |
308 return true; | |
309 } | |
310 return false; | |
311 } | 307 } |
312 | 308 |
313 bool use_test_fetcher_; | 309 bool use_test_fetcher_; |
314 | 310 |
315 DISALLOW_COPY_AND_ASSIGN(TestApplicationManagerDelegate); | 311 DISALLOW_COPY_AND_ASSIGN(TestApplicationFetcher); |
316 }; | 312 }; |
317 | 313 |
318 class TestLoader : public ApplicationLoader { | 314 class TestLoader : public ApplicationLoader { |
319 public: | 315 public: |
320 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} | 316 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} |
321 ~TestLoader() override {} | 317 ~TestLoader() override {} |
322 | 318 |
323 private: | 319 private: |
324 // Overridden from ApplicationLoader: | 320 // Overridden from ApplicationLoader: |
325 void Load(const GURL& url, InterfaceRequest<Application> request) override { | 321 void Load(const GURL& url, InterfaceRequest<Application> request) override { |
326 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass())); | 322 app_.reset(new ApplicationImpl(delegate_.get(), request.Pass())); |
327 } | 323 } |
328 | 324 |
329 scoped_ptr<ApplicationDelegate> delegate_; | 325 scoped_ptr<ApplicationDelegate> delegate_; |
330 scoped_ptr<ApplicationImpl> app_; | 326 scoped_ptr<ApplicationImpl> app_; |
331 | 327 |
332 DISALLOW_COPY_AND_ASSIGN(TestLoader); | 328 DISALLOW_COPY_AND_ASSIGN(TestLoader); |
333 }; | 329 }; |
334 | 330 |
335 class CapabilityFilterTest : public testing::Test { | 331 class CapabilityFilterTest : public testing::Test { |
336 public: | 332 public: |
337 CapabilityFilterTest() : validator_(nullptr) {} | 333 CapabilityFilterTest() |
| 334 : test_application_fetcher_(nullptr), |
| 335 validator_(nullptr) {} |
338 ~CapabilityFilterTest() override {} | 336 ~CapabilityFilterTest() override {} |
339 | 337 |
340 protected: | 338 protected: |
341 void RunApplication(const std::string& url, const CapabilityFilter& filter) { | 339 void RunApplication(const std::string& url, const CapabilityFilter& filter) { |
342 ServiceProviderPtr services; | 340 ServiceProviderPtr services; |
343 | 341 |
344 // We expose Validator to the test application via ConnectToApplication | 342 // We expose Validator to the test application via ConnectToApplication |
345 // because we don't allow the test application to connect to test:validator. | 343 // because we don't allow the test application to connect to test:validator. |
346 // Adding it to the CapabilityFilter would interfere with the test. | 344 // Adding it to the CapabilityFilter would interfere with the test. |
347 ServiceProviderPtr exposed_services; | 345 ServiceProviderPtr exposed_services; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 CreateLoader<TestContentHandler>(content_handler_url.spec()); | 382 CreateLoader<TestContentHandler>(content_handler_url.spec()); |
385 RunTest(); | 383 RunTest(); |
386 } | 384 } |
387 | 385 |
388 base::MessageLoop* loop() { return &loop_; } | 386 base::MessageLoop* loop() { return &loop_; } |
389 ApplicationManager* application_manager() { | 387 ApplicationManager* application_manager() { |
390 return application_manager_.get(); | 388 return application_manager_.get(); |
391 } | 389 } |
392 ConnectionValidator* validator() { return validator_; } | 390 ConnectionValidator* validator() { return validator_; } |
393 void set_use_test_fetcher() { | 391 void set_use_test_fetcher() { |
394 test_delegate_.set_use_test_fetcher(true); | 392 test_application_fetcher_->set_use_test_fetcher(true); |
395 } | 393 } |
396 | 394 |
397 // Overridden from testing::Test: | 395 // Overridden from testing::Test: |
398 void SetUp() override { | 396 void SetUp() override { |
399 application_manager_.reset(new ApplicationManager(&test_delegate_)); | 397 test_application_fetcher_ = new TestApplicationFetcher; |
| 398 application_manager_.reset( |
| 399 new ApplicationManager(make_scoped_ptr(test_application_fetcher_))); |
400 CreateLoader<ServiceApplication>("test:service"); | 400 CreateLoader<ServiceApplication>("test:service"); |
401 CreateLoader<ServiceApplication>("test:service2"); | 401 CreateLoader<ServiceApplication>("test:service2"); |
402 } | 402 } |
403 void TearDown() override { | 403 void TearDown() override { |
404 application_manager_.reset(); | 404 application_manager_.reset(); |
405 test_delegate_.set_use_test_fetcher(false); | 405 test_application_fetcher_->set_use_test_fetcher(false); |
406 } | 406 } |
407 | 407 |
408 private: | 408 private: |
409 template<class T> | 409 template<class T> |
410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() { | 410 scoped_ptr<ApplicationDelegate> CreateApplicationDelegate() { |
411 return scoped_ptr<ApplicationDelegate>(new T); | 411 return scoped_ptr<ApplicationDelegate>(new T); |
412 } | 412 } |
413 | 413 |
| 414 TestApplicationFetcher* test_application_fetcher_; |
414 base::ShadowingAtExitManager at_exit_; | 415 base::ShadowingAtExitManager at_exit_; |
415 TestApplicationManagerDelegate test_delegate_; | |
416 base::MessageLoop loop_; | 416 base::MessageLoop loop_; |
417 scoped_ptr<ApplicationManager> application_manager_; | 417 scoped_ptr<ApplicationManager> application_manager_; |
418 ConnectionValidator* validator_; | 418 ConnectionValidator* validator_; |
419 | 419 |
420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); | 420 DISALLOW_COPY_AND_ASSIGN(CapabilityFilterTest); |
421 }; | 421 }; |
422 | 422 |
423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest { | 423 class CapabilityFilter_BlockingTest : public CapabilityFilterTest { |
424 public: | 424 public: |
425 CapabilityFilter_BlockingTest() {} | 425 CapabilityFilter_BlockingTest() {} |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 RunTest(); | 545 RunTest(); |
546 } | 546 } |
547 | 547 |
548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { | 548 TEST_F(CapabilityFilter_WildcardsTest, ContentHandler) { |
549 RunContentHandlerTest(); | 549 RunContentHandlerTest(); |
550 } | 550 } |
551 | 551 |
552 } // namespace | 552 } // namespace |
553 } // namespace shell | 553 } // namespace shell |
554 } // namespace mojo | 554 } // namespace mojo |
OLD | NEW |