OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "mojo/public/cpp/bindings/allocation_scope.h" | 13 #include "mojo/public/cpp/bindings/allocation_scope.h" |
14 #include "mojo/public/cpp/environment/environment.h" | 14 #include "mojo/public/cpp/environment/environment.h" |
| 15 #include "mojo/public/cpp/shell/service.h" |
15 #include "mojo/services/public/cpp/view_manager/util.h" | 16 #include "mojo/services/public/cpp/view_manager/util.h" |
16 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
17 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 18 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
18 #include "mojo/shell/shell_test_helper.h" | 19 #include "mojo/shell/shell_test_helper.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 namespace services { | 23 namespace services { |
23 namespace view_manager { | 24 namespace view_manager { |
24 | 25 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 Changes changes_; | 246 Changes changes_; |
246 | 247 |
247 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 248 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
248 }; | 249 }; |
249 | 250 |
250 class ViewManagerConnectionTest : public testing::Test { | 251 class ViewManagerConnectionTest : public testing::Test { |
251 public: | 252 public: |
252 ViewManagerConnectionTest() {} | 253 ViewManagerConnectionTest() {} |
253 | 254 |
254 virtual void SetUp() OVERRIDE { | 255 virtual void SetUp() OVERRIDE { |
255 AllocationScope allocation_scope; | |
256 | |
257 test_helper_.Init(); | 256 test_helper_.Init(); |
258 | 257 |
259 InterfacePipe<IViewManager, AnyInterface> pipe; | 258 ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager_); |
260 test_helper_.shell()->Connect("mojo:mojo_view_manager", | 259 view_manager_->SetClient(&client_); |
261 pipe.handle_to_peer.Pass()); | |
262 view_manager_.reset(pipe.handle_to_self.Pass(), &client_); | |
263 | 260 |
264 client_.WaitForId(); | 261 client_.WaitForId(); |
265 } | 262 } |
266 | 263 |
267 protected: | 264 protected: |
268 // Creates a second connection to the viewmanager. | 265 // Creates a second connection to the viewmanager. |
269 void EstablishSecondConnection() { | 266 void EstablishSecondConnection() { |
270 AllocationScope allocation_scope; | 267 ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager2_); |
271 InterfacePipe<IViewManager, AnyInterface> pipe; | 268 view_manager2_->SetClient(&client2_); |
272 test_helper_.shell()->Connect("mojo:mojo_view_manager", | |
273 pipe.handle_to_peer.Pass()); | |
274 view_manager2_.reset(pipe.handle_to_self.Pass(), &client2_); | |
275 | 269 |
276 client2_.WaitForId(); | 270 client2_.WaitForId(); |
277 } | 271 } |
278 | 272 |
279 void DestroySecondConnection() { | 273 void DestroySecondConnection() { |
280 view_manager2_.reset(); | 274 view_manager2_.reset(); |
281 } | 275 } |
282 | 276 |
283 base::MessageLoop loop_; | 277 base::MessageLoop loop_; |
284 shell::ShellTestHelper test_helper_; | 278 shell::ShellTestHelper test_helper_; |
285 | 279 |
286 ViewManagerClientImpl client_; | 280 ViewManagerClientImpl client_; |
287 RemotePtr<IViewManager> view_manager_; | 281 IViewManagerPtr view_manager_; |
288 | 282 |
289 ViewManagerClientImpl client2_; | 283 ViewManagerClientImpl client2_; |
290 RemotePtr<IViewManager> view_manager2_; | 284 IViewManagerPtr view_manager2_; |
291 | 285 |
292 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); | 286 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); |
293 }; | 287 }; |
294 | 288 |
295 // Verifies client gets a valid id. | 289 // Verifies client gets a valid id. |
296 TEST_F(ViewManagerConnectionTest, ValidId) { | 290 TEST_F(ViewManagerConnectionTest, ValidId) { |
297 // All these tests assume 1 for the client id. The only real assertion here is | 291 // All these tests assume 1 for the client id. The only real assertion here is |
298 // the client id is not zero, but adding this as rest of code here assumes 1. | 292 // the client id is not zero, but adding this as rest of code here assumes 1. |
299 EXPECT_EQ(1, client_.id()); | 293 EXPECT_EQ(1, client_.id()); |
300 } | 294 } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 625 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
632 ASSERT_EQ(2u, nodes.size()); | 626 ASSERT_EQ(2u, nodes.size()); |
633 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 627 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
634 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 628 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
635 } | 629 } |
636 } | 630 } |
637 | 631 |
638 } // namespace view_manager | 632 } // namespace view_manager |
639 } // namespace services | 633 } // namespace services |
640 } // namespace mojo | 634 } // namespace mojo |
OLD | NEW |