Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1113)

Side by Side Diff: mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc

Issue 260863008: Add support for mapping node tree on the client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698