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/public/cpp/bindings/binding_set.h" | 14 #include "mojo/public/cpp/bindings/binding_set.h" |
15 #include "mojo/shell/public/cpp/application_test_base.h" | 15 #include "mojo/shell/public/cpp/application_test_base.h" |
16 #include "mojo/shell/public/cpp/interface_factory.h" | 16 #include "mojo/shell/public/cpp/interface_factory.h" |
17 #include "mojo/shell/public/cpp/shell.h" | 17 #include "mojo/shell/public/cpp/shell_client.h" |
18 #include "mojo/shell/public/interfaces/application_manager.mojom.h" | 18 #include "mojo/shell/public/interfaces/application_manager.mojom.h" |
19 #include "mojo/shell/tests/application_manager_apptests.mojom.h" | 19 #include "mojo/shell/tests/application_manager_apptests.mojom.h" |
20 | 20 |
21 using mojo::shell::test::mojom::CreateInstanceForHandleTest; | 21 using mojo::shell::test::mojom::CreateInstanceForHandleTest; |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace shell { | 24 namespace shell { |
25 namespace { | 25 namespace { |
26 | 26 |
27 class ApplicationManagerAppTestDelegate | 27 class ApplicationManagerAppTestDelegate |
28 : public ShellClient, | 28 : public ShellClient, |
29 public InterfaceFactory<CreateInstanceForHandleTest>, | 29 public InterfaceFactory<CreateInstanceForHandleTest>, |
30 public CreateInstanceForHandleTest { | 30 public CreateInstanceForHandleTest { |
31 public: | 31 public: |
32 ApplicationManagerAppTestDelegate() | 32 ApplicationManagerAppTestDelegate() |
33 : target_id_(mojom::Connector::kInvalidApplicationID), | 33 : target_id_(mojom::Connector::kInvalidApplicationID), |
34 binding_(this) {} | 34 binding_(this) {} |
35 ~ApplicationManagerAppTestDelegate() override {} | 35 ~ApplicationManagerAppTestDelegate() override {} |
36 | 36 |
37 uint32_t target_id() const { return target_id_; } | 37 uint32_t target_id() const { return target_id_; } |
38 | 38 |
39 private: | 39 private: |
40 // mojo::ShellClient: | 40 // mojo::ShellClient: |
41 void Initialize(Shell* shell, const std::string& url, uint32_t id, | |
42 uint32_t user_id) override {} | |
43 bool AcceptConnection(Connection* connection) override { | 41 bool AcceptConnection(Connection* connection) override { |
44 connection->AddInterface<CreateInstanceForHandleTest>(this); | 42 connection->AddInterface<CreateInstanceForHandleTest>(this); |
45 return true; | 43 return true; |
46 } | 44 } |
47 | 45 |
48 // InterfaceFactory<CreateInstanceForHandleTest>: | 46 // InterfaceFactory<CreateInstanceForHandleTest>: |
49 void Create(Connection* connection, | 47 void Create(Connection* connection, |
50 InterfaceRequest<CreateInstanceForHandleTest> request) override { | 48 InterfaceRequest<CreateInstanceForHandleTest> request) override { |
51 binding_.Bind(std::move(request)); | 49 binding_.Bind(std::move(request)); |
52 } | 50 } |
(...skipping 28 matching lines...) Expand all Loading... |
81 ApplicationInfo(uint32_t id, const std::string& url) | 79 ApplicationInfo(uint32_t id, const std::string& url) |
82 : id(id), url(url), pid(base::kNullProcessId) {} | 80 : id(id), url(url), pid(base::kNullProcessId) {} |
83 | 81 |
84 uint32_t id; | 82 uint32_t id; |
85 std::string url; | 83 std::string url; |
86 base::ProcessId pid; | 84 base::ProcessId pid; |
87 }; | 85 }; |
88 | 86 |
89 void AddListenerAndWaitForApplications() { | 87 void AddListenerAndWaitForApplications() { |
90 mojom::ApplicationManagerPtr application_manager; | 88 mojom::ApplicationManagerPtr application_manager; |
91 shell()->ConnectToInterface("mojo:shell", &application_manager); | 89 connector()->ConnectToInterface("mojo:shell", &application_manager); |
92 | 90 |
93 application_manager->AddListener(binding_.CreateInterfacePtrAndBind()); | 91 application_manager->AddListener(binding_.CreateInterfacePtrAndBind()); |
94 binding_.WaitForIncomingMethodCall(); | 92 binding_.WaitForIncomingMethodCall(); |
95 } | 93 } |
96 | 94 |
97 bool ContainsApplicationWithURL(const std::string& url) const { | 95 bool ContainsApplicationWithURL(const std::string& url) const { |
98 for (const auto& application : initial_applications_) { | 96 for (const auto& application : initial_applications_) { |
99 if (application.url == url) | 97 if (application.url == url) |
100 return true; | 98 return true; |
101 } | 99 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest); | 160 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerAppTest); |
163 }; | 161 }; |
164 | 162 |
165 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) { | 163 TEST_F(ApplicationManagerAppTest, CreateInstanceForHandle) { |
166 AddListenerAndWaitForApplications(); | 164 AddListenerAndWaitForApplications(); |
167 | 165 |
168 // 1. Launch a process. (Actually, have the runner launch a process that | 166 // 1. Launch a process. (Actually, have the runner launch a process that |
169 // launches a process. #becauselinkerrors). | 167 // launches a process. #becauselinkerrors). |
170 mojo::shell::test::mojom::DriverPtr driver; | 168 mojo::shell::test::mojom::DriverPtr driver; |
171 scoped_ptr<Connection> connection = | 169 scoped_ptr<Connection> connection = |
172 shell()->Connect("exe:application_manager_apptest_driver"); | 170 connector()->Connect("exe:application_manager_apptest_driver"); |
173 connection->GetInterface(&driver); | 171 connection->GetInterface(&driver); |
174 | 172 |
175 // 2. Wait for the target to connect to us. (via | 173 // 2. Wait for the target to connect to us. (via |
176 // mojo:application_manager_apptests) | 174 // mojo:application_manager_apptests) |
177 base::MessageLoop::current()->Run(); | 175 base::MessageLoop::current()->Run(); |
178 | 176 |
179 uint32_t remote_id = mojom::Connector::kInvalidApplicationID; | 177 uint32_t remote_id = mojom::Connector::kInvalidApplicationID; |
180 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); | 178 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); |
181 EXPECT_NE(mojom::Connector::kInvalidApplicationID, remote_id); | 179 EXPECT_NE(mojom::Connector::kInvalidApplicationID, remote_id); |
182 | 180 |
(...skipping 21 matching lines...) Expand all Loading... |
204 | 202 |
205 driver.set_connection_error_handler( | 203 driver.set_connection_error_handler( |
206 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, | 204 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, |
207 base::Unretained(this))); | 205 base::Unretained(this))); |
208 driver->QuitDriver(); | 206 driver->QuitDriver(); |
209 base::MessageLoop::current()->Run(); | 207 base::MessageLoop::current()->Run(); |
210 } | 208 } |
211 | 209 |
212 } // namespace shell | 210 } // namespace shell |
213 } // namespace mojo | 211 } // namespace mojo |
OLD | NEW |