| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 Changes changes_; | 238 Changes changes_; |
| 238 | 239 |
| 239 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); | 240 DISALLOW_COPY_AND_ASSIGN(ViewManagerClientImpl); |
| 240 }; | 241 }; |
| 241 | 242 |
| 242 class ViewManagerConnectionTest : public testing::Test { | 243 class ViewManagerConnectionTest : public testing::Test { |
| 243 public: | 244 public: |
| 244 ViewManagerConnectionTest() {} | 245 ViewManagerConnectionTest() {} |
| 245 | 246 |
| 246 virtual void SetUp() OVERRIDE { | 247 virtual void SetUp() OVERRIDE { |
| 247 AllocationScope allocation_scope; | |
| 248 | |
| 249 test_helper_.Init(); | 248 test_helper_.Init(); |
| 250 | 249 |
| 251 InterfacePipe<IViewManager, AnyInterface> pipe; | 250 ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager_); |
| 252 test_helper_.shell()->Connect("mojo:mojo_view_manager", | 251 view_manager_->SetClient(&client_); |
| 253 pipe.handle_to_peer.Pass()); | |
| 254 view_manager_.reset(pipe.handle_to_self.Pass(), &client_); | |
| 255 | 252 |
| 256 client_.WaitForId(); | 253 client_.WaitForId(); |
| 257 } | 254 } |
| 258 | 255 |
| 259 protected: | 256 protected: |
| 260 // Creates a second connection to the viewmanager. | 257 // Creates a second connection to the viewmanager. |
| 261 void EstablishSecondConnection() { | 258 void EstablishSecondConnection() { |
| 262 AllocationScope allocation_scope; | 259 ConnectTo(test_helper_.shell(), "mojo:mojo_view_manager", &view_manager2_); |
| 263 InterfacePipe<IViewManager, AnyInterface> pipe; | 260 view_manager2_->SetClient(&client2_); |
| 264 test_helper_.shell()->Connect("mojo:mojo_view_manager", | |
| 265 pipe.handle_to_peer.Pass()); | |
| 266 view_manager2_.reset(pipe.handle_to_self.Pass(), &client2_); | |
| 267 | 261 |
| 268 client2_.WaitForId(); | 262 client2_.WaitForId(); |
| 269 } | 263 } |
| 270 | 264 |
| 271 void DestroySecondConnection() { | 265 void DestroySecondConnection() { |
| 272 view_manager2_.reset(); | 266 view_manager2_.reset(); |
| 273 } | 267 } |
| 274 | 268 |
| 275 base::MessageLoop loop_; | 269 base::MessageLoop loop_; |
| 276 shell::ShellTestHelper test_helper_; | 270 shell::ShellTestHelper test_helper_; |
| 277 | 271 |
| 278 ViewManagerClientImpl client_; | 272 ViewManagerClientImpl client_; |
| 279 RemotePtr<IViewManager> view_manager_; | 273 IViewManagerPtr view_manager_; |
| 280 | 274 |
| 281 ViewManagerClientImpl client2_; | 275 ViewManagerClientImpl client2_; |
| 282 RemotePtr<IViewManager> view_manager2_; | 276 IViewManagerPtr view_manager2_; |
| 283 | 277 |
| 284 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); | 278 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnectionTest); |
| 285 }; | 279 }; |
| 286 | 280 |
| 287 // Verifies client gets a valid id. | 281 // Verifies client gets a valid id. |
| 288 TEST_F(ViewManagerConnectionTest, ValidId) { | 282 TEST_F(ViewManagerConnectionTest, ValidId) { |
| 289 // All these tests assume 1 for the client id. The only real assertion here is | 283 // All these tests assume 1 for the client id. The only real assertion here is |
| 290 // the client id is not zero, but adding this as rest of code here assumes 1. | 284 // the client id is not zero, but adding this as rest of code here assumes 1. |
| 291 EXPECT_EQ(1, client_.id()); | 285 EXPECT_EQ(1, client_.id()); |
| 292 } | 286 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); | 615 GetNodeTree(view_manager2_.get(), CreateNodeId(1, 1), &nodes); |
| 622 ASSERT_EQ(2u, nodes.size()); | 616 ASSERT_EQ(2u, nodes.size()); |
| 623 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); | 617 EXPECT_EQ("node=1,1 parent=0,1 view=null", nodes[0].ToString()); |
| 624 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); | 618 EXPECT_EQ("node=1,11 parent=1,1 view=1,51", nodes[1].ToString()); |
| 625 } | 619 } |
| 626 } | 620 } |
| 627 | 621 |
| 628 } // namespace view_manager | 622 } // namespace view_manager |
| 629 } // namespace services | 623 } // namespace services |
| 630 } // namespace mojo | 624 } // namespace mojo |
| OLD | NEW |