OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "mojo/services/public/cpp/view_manager/lib/view_manager_observer.h" |
| 10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| 11 #include "mojo/services/public/cpp/view_manager/util.h" |
| 12 #include "mojo/shell/shell_test_helper.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace mojo { |
| 16 namespace services { |
| 17 namespace view_manager { |
| 18 |
| 19 base::RunLoop* current_run_loop = NULL; |
| 20 |
| 21 void DoRunLoop() { |
| 22 base::RunLoop run_loop; |
| 23 current_run_loop = &run_loop; |
| 24 current_run_loop->Run(); |
| 25 current_run_loop = NULL; |
| 26 } |
| 27 |
| 28 void QuitRunLoop() { |
| 29 current_run_loop->Quit(); |
| 30 } |
| 31 |
| 32 // ViewManager ----------------------------------------------------------------- |
| 33 |
| 34 class ViewManagerTest : public testing::Test, |
| 35 public ViewManagerObserver { |
| 36 public: |
| 37 ViewManagerTest() : connection_count_(0), commit_count_(0) {} |
| 38 |
| 39 protected: |
| 40 ViewManager* view_manager_1() { return view_manager_1_.get(); } |
| 41 ViewManager* view_manager_2() { return view_manager_2_.get(); } |
| 42 |
| 43 private: |
| 44 // Overridden from testing::Test: |
| 45 virtual void SetUp() OVERRIDE { |
| 46 test_helper_.Init(); |
| 47 view_manager_1_.reset(new ViewManager(test_helper_.shell())); |
| 48 view_manager_2_.reset(new ViewManager(test_helper_.shell())); |
| 49 ViewManagerPrivate(view_manager_1_.get()).AddObserver(this); |
| 50 ViewManagerPrivate(view_manager_2_.get()).AddObserver(this); |
| 51 |
| 52 // Wait for service connection to be established. |
| 53 DoRunLoop(); |
| 54 } |
| 55 |
| 56 // Overridden from ViewManagerObserver: |
| 57 virtual void OnViewManagerConnected(ViewManager* manager) OVERRIDE { |
| 58 if (++connection_count_ == 2) |
| 59 QuitRunLoop(); |
| 60 } |
| 61 virtual void OnCommit(ViewManager* manager) OVERRIDE { |
| 62 ++commit_count_; |
| 63 } |
| 64 virtual void OnCommitResponse(ViewManager* manager, bool success) OVERRIDE { |
| 65 if (--commit_count_ == 0) |
| 66 QuitRunLoop(); |
| 67 } |
| 68 |
| 69 base::MessageLoop loop_; |
| 70 shell::ShellTestHelper test_helper_; |
| 71 scoped_ptr<ViewManager> view_manager_1_; |
| 72 scoped_ptr<ViewManager> view_manager_2_; |
| 73 int connection_count_; |
| 74 int commit_count_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); |
| 77 }; |
| 78 |
| 79 TEST_F(ViewManagerTest, BuildNodeTree) { |
| 80 view_manager_1()->BuildNodeTree(base::Bind(&QuitRunLoop)); |
| 81 DoRunLoop(); |
| 82 |
| 83 scoped_ptr<ViewTreeNode> node1(new ViewTreeNode(view_manager_1())); |
| 84 view_manager_1()->tree()->AddChild(node1.get()); |
| 85 DoRunLoop(); |
| 86 |
| 87 view_manager_2()->BuildNodeTree(base::Bind(&QuitRunLoop)); |
| 88 DoRunLoop(); |
| 89 |
| 90 EXPECT_EQ(LoWord(view_manager_2()->tree()->children().front()->id()), |
| 91 LoWord(node1->id())); |
| 92 } |
| 93 |
| 94 // TODO(beng): node hierarchy changed |
| 95 // TODO(beng): node destruction |
| 96 |
| 97 } // namespace view_manager |
| 98 } // namespace services |
| 99 } // namespace mojo |
OLD | NEW |