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/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 "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const char kTestAURLString[] = "test:TestA"; | 26 const char kTestAURLString[] = "test:TestA"; |
27 const char kTestBURLString[] = "test:TestB"; | 27 const char kTestBURLString[] = "test:TestB"; |
28 | 28 |
29 struct TestContext { | 29 struct TestContext { |
30 TestContext() : num_impls(0), num_loader_deletes(0) {} | 30 TestContext() : num_impls(0), num_loader_deletes(0) {} |
31 std::string last_test_string; | 31 std::string last_test_string; |
32 int num_impls; | 32 int num_impls; |
33 int num_loader_deletes; | 33 int num_loader_deletes; |
34 }; | 34 }; |
35 | 35 |
| 36 void QuitClosure(bool* value) { |
| 37 *value = true; |
| 38 base::MessageLoop::current()->QuitWhenIdle(); |
| 39 } |
| 40 |
36 class QuitMessageLoopErrorHandler : public ErrorHandler { | 41 class QuitMessageLoopErrorHandler : public ErrorHandler { |
37 public: | 42 public: |
38 QuitMessageLoopErrorHandler() {} | 43 QuitMessageLoopErrorHandler() {} |
39 ~QuitMessageLoopErrorHandler() override {} | 44 ~QuitMessageLoopErrorHandler() override {} |
40 | 45 |
41 // |ErrorHandler| implementation: | 46 // |ErrorHandler| implementation: |
42 void OnConnectionError() override { | 47 void OnConnectionError() override { |
43 base::MessageLoop::current()->QuitWhenIdle(); | 48 base::MessageLoop::current()->QuitWhenIdle(); |
44 } | 49 } |
45 | 50 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 InterfaceRequest<TestService> request) override { | 135 InterfaceRequest<TestService> request) override { |
131 new TestServiceImpl(context_, request.Pass()); | 136 new TestServiceImpl(context_, request.Pass()); |
132 } | 137 } |
133 | 138 |
134 scoped_ptr<ApplicationImpl> test_app_; | 139 scoped_ptr<ApplicationImpl> test_app_; |
135 TestContext* context_; | 140 TestContext* context_; |
136 int num_loads_; | 141 int num_loads_; |
137 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); | 142 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); |
138 }; | 143 }; |
139 | 144 |
| 145 class ClosingApplicationLoader : public ApplicationLoader { |
| 146 private: |
| 147 // ApplicationLoader implementation. |
| 148 void Load(const GURL& url, |
| 149 InterfaceRequest<Application> application_request) override {} |
| 150 }; |
| 151 |
140 class TesterContext { | 152 class TesterContext { |
141 public: | 153 public: |
142 explicit TesterContext(base::MessageLoop* loop) | 154 explicit TesterContext(base::MessageLoop* loop) |
143 : num_b_calls_(0), | 155 : num_b_calls_(0), |
144 num_c_calls_(0), | 156 num_c_calls_(0), |
145 num_a_deletes_(0), | 157 num_a_deletes_(0), |
146 num_b_deletes_(0), | 158 num_b_deletes_(0), |
147 num_c_deletes_(0), | 159 num_c_deletes_(0), |
148 tester_called_quit_(false), | 160 tester_called_quit_(false), |
149 a_called_quit_(false), | 161 a_called_quit_(false), |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 GURL mapped_url = ResolveMappings(url); | 408 GURL mapped_url = ResolveMappings(url); |
397 // The shell automatically map mojo URLs. | 409 // The shell automatically map mojo URLs. |
398 if (mapped_url.scheme() == "mojo") { | 410 if (mapped_url.scheme() == "mojo") { |
399 url::Replacements<char> replacements; | 411 url::Replacements<char> replacements; |
400 replacements.SetScheme("file", url::Component(0, 4)); | 412 replacements.SetScheme("file", url::Component(0, 4)); |
401 mapped_url = mapped_url.ReplaceComponents(replacements); | 413 mapped_url = mapped_url.ReplaceComponents(replacements); |
402 } | 414 } |
403 return mapped_url; | 415 return mapped_url; |
404 } | 416 } |
405 | 417 |
406 void OnApplicationError(const GURL& url) override {} | |
407 | |
408 private: | 418 private: |
409 std::map<GURL, GURL> mappings_; | 419 std::map<GURL, GURL> mappings_; |
410 }; | 420 }; |
411 | 421 |
412 class TestExternal : public ApplicationDelegate { | 422 class TestExternal : public ApplicationDelegate { |
413 public: | 423 public: |
414 TestExternal() : configure_incoming_connection_called_(false) {} | 424 TestExternal() : configure_incoming_connection_called_(false) {} |
415 | 425 |
416 void Initialize(ApplicationImpl* app) override { | 426 void Initialize(ApplicationImpl* app) override { |
417 initialize_args_ = app->args(); | 427 initialize_args_ = app->args(); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 EXPECT_EQ(1, url_loader->num_loads()); | 804 EXPECT_EQ(1, url_loader->num_loads()); |
795 EXPECT_EQ(0, scheme_loader->num_loads()); | 805 EXPECT_EQ(0, scheme_loader->num_loads()); |
796 | 806 |
797 // test::test2 should go to scheme loader. | 807 // test::test2 should go to scheme loader. |
798 application_manager_->ConnectToService(GURL("test:test2?foo=bar"), | 808 application_manager_->ConnectToService(GURL("test:test2?foo=bar"), |
799 &test_service); | 809 &test_service); |
800 EXPECT_EQ(1, url_loader->num_loads()); | 810 EXPECT_EQ(1, url_loader->num_loads()); |
801 EXPECT_EQ(1, scheme_loader->num_loads()); | 811 EXPECT_EQ(1, scheme_loader->num_loads()); |
802 } | 812 } |
803 | 813 |
| 814 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { |
| 815 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); |
| 816 application_manager_->SetLoaderForScheme( |
| 817 scoped_ptr<ApplicationLoader>(loader), "test"); |
| 818 |
| 819 bool called = false; |
| 820 application_manager_->ConnectToApplication( |
| 821 GURL("test:test"), GURL(), nullptr, nullptr, |
| 822 base::Bind(&QuitClosure, base::Unretained(&called))); |
| 823 loop_.Run(); |
| 824 EXPECT_TRUE(called); |
| 825 } |
| 826 |
804 } // namespace | 827 } // namespace |
805 } // namespace shell | 828 } // namespace shell |
806 } // namespace mojo | 829 } // namespace mojo |
OLD | NEW |