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 <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_test_base.h" | 17 #include "mojo/shell/public/cpp/application_test_base.h" |
18 #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" | 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 ShellClient, |
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 // mojo::ShellClient: |
42 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} | 42 void Initialize(Shell* shell, const std::string& url, uint32_t id) override {} |
43 bool AcceptConnection(ApplicationConnection* connection) override { | 43 bool AcceptConnection(Connection* 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(Connection* connection, |
50 ApplicationConnection* connection, | 50 InterfaceRequest<CreateInstanceForHandleTest> request) override { |
51 InterfaceRequest<CreateInstanceForHandleTest> request) override { | |
52 binding_.Bind(std::move(request)); | 51 binding_.Bind(std::move(request)); |
53 } | 52 } |
54 | 53 |
55 // CreateInstanceForHandleTest: | 54 // CreateInstanceForHandleTest: |
56 void SetTargetID(uint32_t target_id) override { | 55 void SetTargetID(uint32_t target_id) override { |
57 target_id_ = target_id; | 56 target_id_ = target_id; |
58 base::MessageLoop::current()->QuitWhenIdle(); | 57 base::MessageLoop::current()->QuitWhenIdle(); |
59 } | 58 } |
60 | 59 |
61 uint32_t target_id_; | 60 uint32_t target_id_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 115 } |
117 | 116 |
118 const std::vector<ApplicationInfo>& applications() const { | 117 const std::vector<ApplicationInfo>& applications() const { |
119 return applications_; | 118 return applications_; |
120 } | 119 } |
121 | 120 |
122 ApplicationManagerAppTestDelegate* delegate() { return delegate_; } | 121 ApplicationManagerAppTestDelegate* delegate() { return delegate_; } |
123 | 122 |
124 private: | 123 private: |
125 // test::ApplicationTestBase: | 124 // test::ApplicationTestBase: |
126 ApplicationDelegate* GetApplicationDelegate() override { | 125 ShellClient* GetShellClient() override { |
127 delegate_ = new ApplicationManagerAppTestDelegate; | 126 delegate_ = new ApplicationManagerAppTestDelegate; |
128 return delegate_; | 127 return delegate_; |
129 } | 128 } |
130 | 129 |
131 // mojom::ApplicationManagerListener: | 130 // mojom::ApplicationManagerListener: |
132 void SetRunningApplications( | 131 void SetRunningApplications( |
133 Array<mojom::ApplicationInfoPtr> applications) override { | 132 Array<mojom::ApplicationInfoPtr> applications) override { |
134 for (size_t i = 0; i < applications.size(); ++i) { | 133 for (size_t i = 0; i < applications.size(); ++i) { |
135 initial_applications_.push_back(ApplicationInfo(applications[i]->id, | 134 initial_applications_.push_back(ApplicationInfo(applications[i]->id, |
136 applications[i]->url, | 135 applications[i]->url, |
(...skipping 30 matching lines...) Expand all Loading... |
167 | 166 |
168 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest); | 167 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest); |
169 }; | 168 }; |
170 | 169 |
171 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) { | 170 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) { |
172 AddListenerAndWaitForApplications(); | 171 AddListenerAndWaitForApplications(); |
173 | 172 |
174 // 1. Launch a process. (Actually, have the runner launch a process that | 173 // 1. Launch a process. (Actually, have the runner launch a process that |
175 // launches a process. #becauselinkerrors). | 174 // launches a process. #becauselinkerrors). |
176 mojo::shell::test::mojom::DriverPtr driver; | 175 mojo::shell::test::mojom::DriverPtr driver; |
177 scoped_ptr<ApplicationConnection> connection = | 176 scoped_ptr<Connection> connection = |
178 shell()->ConnectToApplication("exe:application_manager_apptest_driver"); | 177 shell()->ConnectToApplication("exe:application_manager_apptest_driver"); |
179 connection->ConnectToService(&driver); | 178 connection->ConnectToService(&driver); |
180 | 179 |
181 // 2. Wait for the target to connect to us. (via | 180 // 2. Wait for the target to connect to us. (via |
182 // mojo:application_manager_apptests) | 181 // mojo:application_manager_apptests) |
183 base::MessageLoop::current()->Run(); | 182 base::MessageLoop::current()->Run(); |
184 | 183 |
185 uint32_t remote_id = mojom::Shell::kInvalidApplicationID; | 184 uint32_t remote_id = mojom::Shell::kInvalidApplicationID; |
186 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); | 185 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); |
187 EXPECT_NE(mojom::Shell::kInvalidApplicationID, remote_id); | 186 EXPECT_NE(mojom::Shell::kInvalidApplicationID, remote_id); |
(...skipping 22 matching lines...) Expand all Loading... |
210 | 209 |
211 driver.set_connection_error_handler( | 210 driver.set_connection_error_handler( |
212 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, | 211 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, |
213 base::Unretained(this))); | 212 base::Unretained(this))); |
214 driver->QuitDriver(); | 213 driver->QuitDriver(); |
215 base::MessageLoop::current()->Run(); | 214 base::MessageLoop::current()->Run(); |
216 } | 215 } |
217 | 216 |
218 } // namespace shell | 217 } // namespace shell |
219 } // namespace mojo | 218 } // namespace mojo |
OLD | NEW |