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

Side by Side Diff: mojo/shell/application_manager_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
OLDNEW
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 <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/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
14 #include "mojo/common/weak_binding_set.h" 14 #include "mojo/common/weak_binding_set.h"
15 #include "mojo/converters/network/network_type_converters.h" 15 #include "mojo/converters/network/network_type_converters.h"
16 #include "mojo/shell/application_manager_apptests.mojom.h" 16 #include "mojo/shell/application_manager_apptests.mojom.h"
17 #include "mojo/shell/public/cpp/application_impl.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"
19 #include "mojo/shell/public/cpp/shell.h"
20 #include "mojo/shell/public/interfaces/application_manager.mojom.h" 20 #include "mojo/shell/public/interfaces/application_manager.mojom.h"
21 21
22 using mojo::shell::test::mojom::CreateInstanceForHandleTest; 22 using mojo::shell::test::mojom::CreateInstanceForHandleTest;
23 23
24 namespace mojo { 24 namespace mojo {
25 namespace shell { 25 namespace shell {
26 namespace { 26 namespace {
27 27
28 class ApplicationManagerAppTestDelegate 28 class ApplicationManagerAppTestDelegate
29 : public ApplicationDelegate, 29 : public ApplicationDelegate,
30 public InterfaceFactory<CreateInstanceForHandleTest>, 30 public InterfaceFactory<CreateInstanceForHandleTest>,
31 public CreateInstanceForHandleTest { 31 public CreateInstanceForHandleTest {
32 public: 32 public:
33 ApplicationManagerAppTestDelegate() 33 ApplicationManagerAppTestDelegate()
34 : target_id_(mojom::Shell::kInvalidApplicationID), 34 : target_id_(mojom::Shell::kInvalidApplicationID),
35 binding_(this) {} 35 binding_(this) {}
36 ~ApplicationManagerAppTestDelegate() override {} 36 ~ApplicationManagerAppTestDelegate() override {}
37 37
38 uint32_t target_id() const { return target_id_; } 38 uint32_t target_id() const { return target_id_; }
39 39
40 private: 40 private:
41 // ApplicationDelegate: 41 // ApplicationDelegate:
42 void Initialize(ApplicationImpl* app) override {} 42 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {}
43 bool AcceptConnection(ApplicationConnection* connection) override { 43 bool AcceptConnection(ApplicationConnection* connection) override {
44 connection->AddService<CreateInstanceForHandleTest>(this); 44 connection->AddService<CreateInstanceForHandleTest>(this);
45 return true; 45 return true;
46 } 46 }
47 47
48 // InterfaceFactory<CreateInstanceForHandleTest>: 48 // InterfaceFactory<CreateInstanceForHandleTest>:
49 void Create( 49 void Create(
50 ApplicationConnection* connection, 50 ApplicationConnection* connection,
51 InterfaceRequest<CreateInstanceForHandleTest> request) override { 51 InterfaceRequest<CreateInstanceForHandleTest> request) override {
52 binding_.Bind(std::move(request)); 52 binding_.Bind(std::move(request));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 : id(id), url(url), pid(base::kNullProcessId), name(name) {} 85 : id(id), url(url), pid(base::kNullProcessId), name(name) {}
86 86
87 uint32_t id; 87 uint32_t id;
88 std::string url; 88 std::string url;
89 base::ProcessId pid; 89 base::ProcessId pid;
90 std::string name; 90 std::string name;
91 }; 91 };
92 92
93 void AddListenerAndWaitForApplications() { 93 void AddListenerAndWaitForApplications() {
94 mojom::ApplicationManagerPtr application_manager; 94 mojom::ApplicationManagerPtr application_manager;
95 application_impl()->ConnectToService("mojo:shell", &application_manager); 95 shell()->ConnectToService("mojo:shell", &application_manager);
96 96
97 application_manager->AddListener(binding_.CreateInterfacePtrAndBind()); 97 application_manager->AddListener(binding_.CreateInterfacePtrAndBind());
98 binding_.WaitForIncomingMethodCall(); 98 binding_.WaitForIncomingMethodCall();
99 } 99 }
100 100
101 bool ContainsApplicationNamed(const std::string& name) const { 101 bool ContainsApplicationNamed(const std::string& name) const {
102 for (const auto& application : initial_applications_) { 102 for (const auto& application : initial_applications_) {
103 if (application.name == name) 103 if (application.name == name)
104 return true; 104 return true;
105 } 105 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest); 168 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest);
169 }; 169 };
170 170
171 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) { 171 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) {
172 AddListenerAndWaitForApplications(); 172 AddListenerAndWaitForApplications();
173 173
174 // 1. Launch a process. (Actually, have the runner launch a process that 174 // 1. Launch a process. (Actually, have the runner launch a process that
175 // launches a process. #becauselinkerrors). 175 // launches a process. #becauselinkerrors).
176 mojo::shell::test::mojom::DriverPtr driver; 176 mojo::shell::test::mojom::DriverPtr driver;
177 scoped_ptr<ApplicationConnection> connection = 177 scoped_ptr<ApplicationConnection> connection =
178 application_impl()->ConnectToApplication( 178 shell()->ConnectToApplication("exe:application_manager_apptest_driver");
179 "exe:application_manager_apptest_driver");
180 connection->ConnectToService(&driver); 179 connection->ConnectToService(&driver);
181 180
182 // 2. Wait for the target to connect to us. (via 181 // 2. Wait for the target to connect to us. (via
183 // mojo:application_manager_apptests) 182 // mojo:application_manager_apptests)
184 base::MessageLoop::current()->Run(); 183 base::MessageLoop::current()->Run();
185 184
186 uint32_t remote_id = mojom::Shell::kInvalidApplicationID; 185 uint32_t remote_id = mojom::Shell::kInvalidApplicationID;
187 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); 186 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id));
188 EXPECT_NE(mojom::Shell::kInvalidApplicationID, remote_id); 187 EXPECT_NE(mojom::Shell::kInvalidApplicationID, remote_id);
189 188
(...skipping 21 matching lines...) Expand all
211 210
212 driver.set_connection_error_handler( 211 driver.set_connection_error_handler(
213 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, 212 base::Bind(&ApplicationManagerAppTest::OnDriverQuit,
214 base::Unretained(this))); 213 base::Unretained(this)));
215 driver->QuitDriver(); 214 driver->QuitDriver();
216 base::MessageLoop::current()->Run(); 215 base::MessageLoop::current()->Run();
217 } 216 }
218 217
219 } // namespace shell 218 } // namespace shell
220 } // namespace mojo 219 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/tracing/public/cpp/tracing_impl.cc ('k') | mojo/shell/application_manager_apptest_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698