| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // the package's manifest and are thus registered with the PackageManager. | 23 // the package's manifest and are thus registered with the PackageManager. |
| 24 | 24 |
| 25 namespace mojo { | 25 namespace mojo { |
| 26 namespace shell { | 26 namespace shell { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 using GetNameCallback = | 29 using GetNameCallback = |
| 30 test::mojom::ApplicationPackageApptestService::GetNameCallback; | 30 test::mojom::ApplicationPackageApptestService::GetNameCallback; |
| 31 | 31 |
| 32 class ProvidedApplicationDelegate | 32 class ProvidedApplicationDelegate |
| 33 : public ApplicationDelegate, | 33 : public ShellClient, |
| 34 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, | 34 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, |
| 35 public test::mojom::ApplicationPackageApptestService, | 35 public test::mojom::ApplicationPackageApptestService, |
| 36 public base::SimpleThread { | 36 public base::SimpleThread { |
| 37 public: | 37 public: |
| 38 ProvidedApplicationDelegate(const std::string& name, | 38 ProvidedApplicationDelegate(const std::string& name, |
| 39 InterfaceRequest<mojom::Application> request, | 39 InterfaceRequest<mojom::Application> request, |
| 40 const Callback<void()>& destruct_callback) | 40 const Callback<void()>& destruct_callback) |
| 41 : base::SimpleThread(name), | 41 : base::SimpleThread(name), |
| 42 name_(name), | 42 name_(name), |
| 43 request_(std::move(request)), | 43 request_(std::move(request)), |
| 44 destruct_callback_(destruct_callback) { | 44 destruct_callback_(destruct_callback) { |
| 45 Start(); | 45 Start(); |
| 46 } | 46 } |
| 47 ~ProvidedApplicationDelegate() override { | 47 ~ProvidedApplicationDelegate() override { |
| 48 Join(); | 48 Join(); |
| 49 destruct_callback_.Run(); | 49 destruct_callback_.Run(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // ApplicationDelegate: | 53 // mojo::ShellClient: |
| 54 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} | 54 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} |
| 55 bool AcceptConnection(ApplicationConnection* connection) override { | 55 bool AcceptConnection(Connection* connection) override { |
| 56 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); | 56 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: | 60 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: |
| 61 void Create( | 61 void Create( |
| 62 ApplicationConnection* connection, | 62 Connection* connection, |
| 63 InterfaceRequest<test::mojom::ApplicationPackageApptestService> request) | 63 InterfaceRequest<test::mojom::ApplicationPackageApptestService> request) |
| 64 override { | 64 override { |
| 65 bindings_.AddBinding(this, std::move(request)); | 65 bindings_.AddBinding(this, std::move(request)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // test::mojom::ApplicationPackageApptestService: | 68 // test::mojom::ApplicationPackageApptestService: |
| 69 void GetName(const GetNameCallback& callback) override { | 69 void GetName(const GetNameCallback& callback) override { |
| 70 callback.Run(name_); | 70 callback.Run(name_); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // base::SimpleThread: | 73 // base::SimpleThread: |
| 74 void Run() override { | 74 void Run() override { |
| 75 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), | 75 ApplicationRunner(this).Run(request_.PassMessagePipe().release().value(), |
| 76 false); | 76 false); |
| 77 delete this; | 77 delete this; |
| 78 } | 78 } |
| 79 | 79 |
| 80 const std::string name_; | 80 const std::string name_; |
| 81 InterfaceRequest<mojom::Application> request_; | 81 InterfaceRequest<mojom::Application> request_; |
| 82 const Callback<void()> destruct_callback_; | 82 const Callback<void()> destruct_callback_; |
| 83 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; | 83 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(ProvidedApplicationDelegate); | 85 DISALLOW_COPY_AND_ASSIGN(ProvidedApplicationDelegate); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 class ApplicationPackageApptestDelegate | 88 class ApplicationPackageApptestDelegate |
| 89 : public ApplicationDelegate, | 89 : public ShellClient, |
| 90 public InterfaceFactory<mojom::ContentHandler>, | 90 public InterfaceFactory<mojom::ContentHandler>, |
| 91 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, | 91 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, |
| 92 public mojom::ContentHandler, | 92 public mojom::ContentHandler, |
| 93 public test::mojom::ApplicationPackageApptestService { | 93 public test::mojom::ApplicationPackageApptestService { |
| 94 public: | 94 public: |
| 95 ApplicationPackageApptestDelegate() {} | 95 ApplicationPackageApptestDelegate() {} |
| 96 ~ApplicationPackageApptestDelegate() override {} | 96 ~ApplicationPackageApptestDelegate() override {} |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 // ApplicationDelegate: | 99 // mojo::ShellClient: |
| 100 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} | 100 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} |
| 101 bool AcceptConnection(ApplicationConnection* connection) override { | 101 bool AcceptConnection(Connection* connection) override { |
| 102 connection->AddService<ContentHandler>(this); | 102 connection->AddService<ContentHandler>(this); |
| 103 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); | 103 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // InterfaceFactory<mojom::ContentHandler>: | 107 // InterfaceFactory<mojom::ContentHandler>: |
| 108 void Create(ApplicationConnection* connection, | 108 void Create(Connection* connection, |
| 109 InterfaceRequest<mojom::ContentHandler> request) override { | 109 InterfaceRequest<mojom::ContentHandler> request) override { |
| 110 content_handler_bindings_.AddBinding(this, std::move(request)); | 110 content_handler_bindings_.AddBinding(this, std::move(request)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: | 113 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: |
| 114 void Create(ApplicationConnection* connection, | 114 void Create(Connection* connection, |
| 115 InterfaceRequest<test::mojom::ApplicationPackageApptestService> | 115 InterfaceRequest<test::mojom::ApplicationPackageApptestService> |
| 116 request) override { | 116 request) override { |
| 117 bindings_.AddBinding(this, std::move(request)); | 117 bindings_.AddBinding(this, std::move(request)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // mojom::ContentHandler: | 120 // mojom::ContentHandler: |
| 121 void StartApplication(InterfaceRequest<mojom::Application> request, | 121 void StartApplication(InterfaceRequest<mojom::Application> request, |
| 122 URLResponsePtr response, | 122 URLResponsePtr response, |
| 123 const Callback<void()>& destruct_callback) override { | 123 const Callback<void()>& destruct_callback) override { |
| 124 const std::string url = response->url; | 124 const std::string url = response->url; |
| 125 if (url == "mojo://package_test_a/") { | 125 if (url == "mojo://package_test_a/") { |
| 126 new ProvidedApplicationDelegate("A", std::move(request), | 126 new ProvidedApplicationDelegate("A", std::move(request), |
| 127 destruct_callback); | 127 destruct_callback); |
| 128 } else if (url == "mojo://package_test_b/") { | 128 } else if (url == "mojo://package_test_b/") { |
| 129 new ProvidedApplicationDelegate("B", std::move(request), | 129 new ProvidedApplicationDelegate("B", std::move(request), |
| 130 destruct_callback); | 130 destruct_callback); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 // test::mojom::ApplicationPackageApptestService: | 134 // test::mojom::ApplicationPackageApptestService: |
| 135 void GetName(const GetNameCallback& callback) override { | 135 void GetName(const GetNameCallback& callback) override { |
| 136 callback.Run("ROOT"); | 136 callback.Run("ROOT"); |
| 137 } | 137 } |
| 138 | 138 |
| 139 std::vector<scoped_ptr<ApplicationDelegate>> delegates_; | 139 std::vector<scoped_ptr<ShellClient>> delegates_; |
| 140 WeakBindingSet<mojom::ContentHandler> content_handler_bindings_; | 140 WeakBindingSet<mojom::ContentHandler> content_handler_bindings_; |
| 141 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; | 141 WeakBindingSet<test::mojom::ApplicationPackageApptestService> bindings_; |
| 142 | 142 |
| 143 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptestDelegate); | 143 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptestDelegate); |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 void ReceiveName(std::string* out_name, | 146 void ReceiveName(std::string* out_name, |
| 147 base::RunLoop* loop, | 147 base::RunLoop* loop, |
| 148 const String& name) { | 148 const String& name) { |
| 149 *out_name = name; | 149 *out_name = name; |
| 150 loop->Quit(); | 150 loop->Quit(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace | 153 } // namespace |
| 154 | 154 |
| 155 class ApplicationPackageApptest : public mojo::test::ApplicationTestBase { | 155 class ApplicationPackageApptest : public mojo::test::ApplicationTestBase { |
| 156 public: | 156 public: |
| 157 ApplicationPackageApptest() : delegate_(nullptr) {} | 157 ApplicationPackageApptest() : delegate_(nullptr) {} |
| 158 ~ApplicationPackageApptest() override {} | 158 ~ApplicationPackageApptest() override {} |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 // test::ApplicationTestBase: | 161 // test::ApplicationTestBase: |
| 162 ApplicationDelegate* GetApplicationDelegate() override { | 162 ShellClient* GetShellClient() override { |
| 163 delegate_ = new ApplicationPackageApptestDelegate; | 163 delegate_ = new ApplicationPackageApptestDelegate; |
| 164 return delegate_; | 164 return delegate_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 ApplicationPackageApptestDelegate* delegate_; | 167 ApplicationPackageApptestDelegate* delegate_; |
| 168 | 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptest); | 169 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptest); |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 TEST_F(ApplicationPackageApptest, Basic) { | 172 TEST_F(ApplicationPackageApptest, Basic) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 199 base::RunLoop run_loop; | 199 base::RunLoop run_loop; |
| 200 std::string b_name; | 200 std::string b_name; |
| 201 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop)); | 201 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop)); |
| 202 run_loop.Run(); | 202 run_loop.Run(); |
| 203 EXPECT_EQ("B", b_name); | 203 EXPECT_EQ("B", b_name); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace shell | 207 } // namespace shell |
| 208 } // namespace mojo | 208 } // namespace mojo |
| OLD | NEW |