Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(641)

Side by Side Diff: mojo/shell/application_package_apptest.cc

Issue 1674903003: Extract shell methods from ApplicationImpl into a base class, and pass this to Initialize() instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojom
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/application_manager_apptest_target.cc ('k') | mojo/shell/capability_filter_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/threading/simple_thread.h" 13 #include "base/threading/simple_thread.h"
14 #include "mojo/common/weak_binding_set.h" 14 #include "mojo/common/weak_binding_set.h"
15 #include "mojo/shell/application_package_apptest.mojom.h" 15 #include "mojo/shell/application_package_apptest.mojom.h"
16 #include "mojo/shell/public/cpp/application_impl.h"
17 #include "mojo/shell/public/cpp/application_runner.h" 16 #include "mojo/shell/public/cpp/application_runner.h"
18 #include "mojo/shell/public/cpp/application_test_base.h" 17 #include "mojo/shell/public/cpp/application_test_base.h"
19 #include "mojo/shell/public/cpp/interface_factory.h" 18 #include "mojo/shell/public/cpp/interface_factory.h"
20 #include "mojo/shell/public/interfaces/content_handler.mojom.h" 19 #include "mojo/shell/public/interfaces/content_handler.mojom.h"
21 20
22 // Tests that multiple applications can be packaged in a single Mojo application 21 // Tests that multiple applications can be packaged in a single Mojo application
23 // implementing ContentHandler; that these applications can be specified by 22 // implementing ContentHandler; that these applications can be specified by
24 // the package's manifest and are thus registered with the PackageManager. 23 // the package's manifest and are thus registered with the PackageManager.
25 24
26 namespace mojo { 25 namespace mojo {
(...skipping 18 matching lines...) Expand all
45 destruct_callback_(destruct_callback) { 44 destruct_callback_(destruct_callback) {
46 Start(); 45 Start();
47 } 46 }
48 ~ProvidedApplicationDelegate() override { 47 ~ProvidedApplicationDelegate() override {
49 Join(); 48 Join();
50 destruct_callback_.Run(); 49 destruct_callback_.Run();
51 } 50 }
52 51
53 private: 52 private:
54 // ApplicationDelegate: 53 // ApplicationDelegate:
55 void Initialize(ApplicationImpl* app) override {} 54 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
56 bool AcceptConnection(ApplicationConnection* connection) override { 55 bool AcceptConnection(ApplicationConnection* connection) override {
57 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); 56 connection->AddService<test::mojom::ApplicationPackageApptestService>(this);
58 return true; 57 return true;
59 } 58 }
60 59
61 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>: 60 // InterfaceFactory<test::mojom::ApplicationPackageApptestService>:
62 void Create( 61 void Create(
63 ApplicationConnection* connection, 62 ApplicationConnection* connection,
64 InterfaceRequest<test::mojom::ApplicationPackageApptestService> request) 63 InterfaceRequest<test::mojom::ApplicationPackageApptestService> request)
65 override { 64 override {
(...skipping 25 matching lines...) Expand all
91 public InterfaceFactory<mojom::ContentHandler>, 90 public InterfaceFactory<mojom::ContentHandler>,
92 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>, 91 public InterfaceFactory<test::mojom::ApplicationPackageApptestService>,
93 public mojom::ContentHandler, 92 public mojom::ContentHandler,
94 public test::mojom::ApplicationPackageApptestService { 93 public test::mojom::ApplicationPackageApptestService {
95 public: 94 public:
96 ApplicationPackageApptestDelegate() {} 95 ApplicationPackageApptestDelegate() {}
97 ~ApplicationPackageApptestDelegate() override {} 96 ~ApplicationPackageApptestDelegate() override {}
98 97
99 private: 98 private:
100 // ApplicationDelegate: 99 // ApplicationDelegate:
101 void Initialize(ApplicationImpl* app) override {} 100 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
102 bool AcceptConnection(ApplicationConnection* connection) override { 101 bool AcceptConnection(ApplicationConnection* connection) override {
103 connection->AddService<ContentHandler>(this); 102 connection->AddService<ContentHandler>(this);
104 connection->AddService<test::mojom::ApplicationPackageApptestService>(this); 103 connection->AddService<test::mojom::ApplicationPackageApptestService>(this);
105 return true; 104 return true;
106 } 105 }
107 106
108 // InterfaceFactory<mojom::ContentHandler>: 107 // InterfaceFactory<mojom::ContentHandler>:
109 void Create(ApplicationConnection* connection, 108 void Create(ApplicationConnection* connection,
110 InterfaceRequest<mojom::ContentHandler> request) override { 109 InterfaceRequest<mojom::ContentHandler> request) override {
111 content_handler_bindings_.AddBinding(this, std::move(request)); 110 content_handler_bindings_.AddBinding(this, std::move(request));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ApplicationPackageApptestDelegate* delegate_; 167 ApplicationPackageApptestDelegate* delegate_;
169 168
170 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptest); 169 DISALLOW_COPY_AND_ASSIGN(ApplicationPackageApptest);
171 }; 170 };
172 171
173 TEST_F(ApplicationPackageApptest, Basic) { 172 TEST_F(ApplicationPackageApptest, Basic) {
174 { 173 {
175 // We need to do this to force the shell to read the test app's manifest and 174 // We need to do this to force the shell to read the test app's manifest and
176 // register aliases. 175 // register aliases.
177 test::mojom::ApplicationPackageApptestServicePtr root_service; 176 test::mojom::ApplicationPackageApptestServicePtr root_service;
178 application_impl()->ConnectToService("mojo:mojo_shell_apptests", 177 shell()->ConnectToService("mojo:mojo_shell_apptests", &root_service);
179 &root_service);
180 base::RunLoop run_loop; 178 base::RunLoop run_loop;
181 std::string root_name; 179 std::string root_name;
182 root_service->GetName(base::Bind(&ReceiveName, &root_name, &run_loop)); 180 root_service->GetName(base::Bind(&ReceiveName, &root_name, &run_loop));
183 run_loop.Run(); 181 run_loop.Run();
184 } 182 }
185 183
186 { 184 {
187 // Now subsequent connects to applications provided by the root app will be 185 // Now subsequent connects to applications provided by the root app will be
188 // resolved correctly. 186 // resolved correctly.
189 test::mojom::ApplicationPackageApptestServicePtr service_a; 187 test::mojom::ApplicationPackageApptestServicePtr service_a;
190 application_impl()->ConnectToService("mojo:package_test_a", &service_a); 188 shell()->ConnectToService("mojo:package_test_a", &service_a);
191 base::RunLoop run_loop; 189 base::RunLoop run_loop;
192 std::string a_name; 190 std::string a_name;
193 service_a->GetName(base::Bind(&ReceiveName, &a_name, &run_loop)); 191 service_a->GetName(base::Bind(&ReceiveName, &a_name, &run_loop));
194 run_loop.Run(); 192 run_loop.Run();
195 EXPECT_EQ("A", a_name); 193 EXPECT_EQ("A", a_name);
196 } 194 }
197 195
198 { 196 {
199 test::mojom::ApplicationPackageApptestServicePtr service_b; 197 test::mojom::ApplicationPackageApptestServicePtr service_b;
200 application_impl()->ConnectToService("mojo:package_test_b", &service_b); 198 shell()->ConnectToService("mojo:package_test_b", &service_b);
201 base::RunLoop run_loop; 199 base::RunLoop run_loop;
202 std::string b_name; 200 std::string b_name;
203 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop)); 201 service_b->GetName(base::Bind(&ReceiveName, &b_name, &run_loop));
204 run_loop.Run(); 202 run_loop.Run();
205 EXPECT_EQ("B", b_name); 203 EXPECT_EQ("B", b_name);
206 } 204 }
207 } 205 }
208 206
209 } // namespace shell 207 } // namespace shell
210 } // namespace mojo 208 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager_apptest_target.cc ('k') | mojo/shell/capability_filter_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698