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" |
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/test/test_suite.h" | 13 #include "base/test/test_suite.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/names.h" |
15 #include "mojo/shell/public/cpp/shell_test.h" | 16 #include "mojo/shell/public/cpp/shell_test.h" |
16 #include "mojo/shell/public/interfaces/shell.mojom.h" | 17 #include "mojo/shell/public/interfaces/shell.mojom.h" |
17 #include "mojo/shell/tests/connect/connect_test.mojom.h" | 18 #include "mojo/shell/tests/connect/connect_test.mojom.h" |
18 | 19 |
19 // Tests that multiple applications can be packaged in a single Mojo application | 20 // Tests that multiple applications can be packaged in a single Mojo application |
20 // implementing ShellClientFactory; that these applications can be specified by | 21 // implementing ShellClientFactory; that these applications can be specified by |
21 // the package's manifest and are thus registered with the PackageManager. | 22 // the package's manifest and are thus registered with the PackageManager. |
22 | 23 |
23 namespace mojo { | 24 namespace mojo { |
24 namespace shell { | 25 namespace shell { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 EXPECT_NE(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID()); | 130 EXPECT_NE(mojom::kInvalidInstanceID, connection->GetRemoteInstanceID()); |
130 EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppName); | 131 EXPECT_EQ(connection->GetRemoteIdentity().name(), kTestAppName); |
131 } | 132 } |
132 | 133 |
133 TEST_F(ConnectTest, Instances) { | 134 TEST_F(ConnectTest, Instances) { |
134 Connector::ConnectParams params_a( | 135 Connector::ConnectParams params_a( |
135 Identity(kTestAppName, mojom::kInheritUserID, "A")); | 136 Identity(kTestAppName, mojom::kInheritUserID, "A")); |
136 scoped_ptr<Connection> connection_a1 = ConnectTo(¶ms_a); | 137 scoped_ptr<Connection> connection_a1 = ConnectTo(¶ms_a); |
137 scoped_ptr<Connection> connection_a2 = ConnectTo(¶ms_a); | 138 scoped_ptr<Connection> connection_a2 = ConnectTo(¶ms_a); |
138 std::string instance_a1, instance_a2; | 139 std::string instance_a1, instance_a2; |
139 test::mojom::StandaloneAppPtr standalone_app_a1; | 140 test::mojom::ConnectTestServicePtr service_a1; |
140 { | 141 { |
141 connection_a1->GetInterface(&standalone_app_a1); | 142 connection_a1->GetInterface(&service_a1); |
142 base::RunLoop loop; | 143 base::RunLoop loop; |
143 standalone_app_a1->GetInstance( | 144 service_a1->GetInstance(base::Bind(&ReceiveTitle, &instance_a1, &loop)); |
144 base::Bind(&ReceiveTitle, &instance_a1, &loop)); | |
145 loop.Run(); | 145 loop.Run(); |
146 } | 146 } |
147 test::mojom::StandaloneAppPtr standalone_app_a2; | 147 test::mojom::ConnectTestServicePtr service_a2; |
148 { | 148 { |
149 connection_a2->GetInterface(&standalone_app_a2); | 149 connection_a2->GetInterface(&service_a2); |
150 base::RunLoop loop; | 150 base::RunLoop loop; |
151 standalone_app_a2->GetInstance( | 151 service_a2->GetInstance(base::Bind(&ReceiveTitle, &instance_a2, &loop)); |
152 base::Bind(&ReceiveTitle, &instance_a2, &loop)); | |
153 loop.Run(); | 152 loop.Run(); |
154 } | 153 } |
155 EXPECT_EQ(instance_a1, instance_a2); | 154 EXPECT_EQ(instance_a1, instance_a2); |
156 | 155 |
157 Connector::ConnectParams params_b( | 156 Connector::ConnectParams params_b( |
158 Identity(kTestAppName, mojom::kInheritUserID, "B")); | 157 Identity(kTestAppName, mojom::kInheritUserID, "B")); |
159 scoped_ptr<Connection> connection_b = ConnectTo(¶ms_b); | 158 scoped_ptr<Connection> connection_b = ConnectTo(¶ms_b); |
160 std::string instance_b; | 159 std::string instance_b; |
161 test::mojom::StandaloneAppPtr standalone_app_b; | 160 test::mojom::ConnectTestServicePtr service_b; |
162 { | 161 { |
163 connection_b->GetInterface(&standalone_app_b); | 162 connection_b->GetInterface(&service_b); |
164 base::RunLoop loop; | 163 base::RunLoop loop; |
165 standalone_app_b->GetInstance( | 164 service_b->GetInstance(base::Bind(&ReceiveTitle, &instance_b, &loop)); |
166 base::Bind(&ReceiveTitle, &instance_b, &loop)); | |
167 loop.Run(); | 165 loop.Run(); |
168 } | 166 } |
169 | 167 |
170 EXPECT_NE(instance_a1, instance_b); | 168 EXPECT_NE(instance_a1, instance_b); |
171 } | 169 } |
172 | 170 |
| 171 // When both the unresolved and resolved instance names are their default |
| 172 // values, the instance name from the unresolved name must be used. |
| 173 // (The case where the instance names differ is covered by |
| 174 // LifecycleTest.PackagedApp_CrashCrashesOtherProvidedApp). |
| 175 TEST_F(ConnectTest, PreferUnresolvedDefaultInstanceName) { |
| 176 // Connect to an app with no manifest-supplied instance name provided by a |
| 177 // package, the instance name must be derived from the application instance |
| 178 // name, not the package. |
| 179 scoped_ptr<Connection> connection = connector()->Connect(kTestAppName); |
| 180 { |
| 181 base::RunLoop loop; |
| 182 connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop)); |
| 183 loop.Run(); |
| 184 } |
| 185 |
| 186 std::string instance; |
| 187 { |
| 188 test::mojom::ConnectTestServicePtr service; |
| 189 connection->GetInterface(&service); |
| 190 base::RunLoop loop; |
| 191 service->GetInstance(base::Bind(&ReceiveTitle, &instance, &loop)); |
| 192 loop.Run(); |
| 193 } |
| 194 EXPECT_EQ(GetNamePath(kTestAppName), instance); |
| 195 } |
| 196 |
173 // BlockedInterface should not be exposed to this application because it is not | 197 // BlockedInterface should not be exposed to this application because it is not |
174 // in our CapabilityFilter whitelist. | 198 // in our CapabilityFilter whitelist. |
175 TEST_F(ConnectTest, BlockedInterface) { | 199 TEST_F(ConnectTest, BlockedInterface) { |
176 scoped_ptr<Connection> connection = connector()->Connect(kTestAppName); | 200 scoped_ptr<Connection> connection = connector()->Connect(kTestAppName); |
177 base::RunLoop run_loop; | 201 base::RunLoop run_loop; |
178 test::mojom::BlockedInterfacePtr blocked; | 202 test::mojom::BlockedInterfacePtr blocked; |
179 connection->GetInterface(&blocked); | 203 connection->GetInterface(&blocked); |
180 blocked.set_connection_error_handler(base::Bind(&QuitLoop, &run_loop)); | 204 blocked.set_connection_error_handler(base::Bind(&QuitLoop, &run_loop)); |
181 std::string title = "unchanged"; | 205 std::string title = "unchanged"; |
182 blocked->GetTitleBlocked(base::Bind(&ReceiveTitle, &title, &run_loop)); | 206 blocked->GetTitleBlocked(base::Bind(&ReceiveTitle, &title, &run_loop)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 CompareConnectionState( | 325 CompareConnectionState( |
302 kTestAppAName, test_name(), test_userid(), test_instance_id(), | 326 kTestAppAName, test_name(), test_userid(), test_instance_id(), |
303 kTestAppAName, connection->GetRemoteIdentity().user_id(), remote_id); | 327 kTestAppAName, connection->GetRemoteIdentity().user_id(), remote_id); |
304 } | 328 } |
305 | 329 |
306 } | 330 } |
307 } | 331 } |
308 | 332 |
309 } // namespace shell | 333 } // namespace shell |
310 } // namespace mojo | 334 } // namespace mojo |
OLD | NEW |