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

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

Issue 287053004: SetBounds for ViewTreeNode. (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
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 "mojo/services/public/cpp/view_manager/view_manager.h" 5 #include "mojo/services/public/cpp/view_manager/view_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" 9 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h"
10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" 10 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
11 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" 11 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h"
12 #include "mojo/services/public/cpp/view_manager/util.h" 12 #include "mojo/services/public/cpp/view_manager/util.h"
13 #include "mojo/services/public/cpp/view_manager/view.h" 13 #include "mojo/services/public/cpp/view_manager/view.h"
14 #include "mojo/services/public/cpp/view_manager/view_observer.h" 14 #include "mojo/services/public/cpp/view_manager/view_observer.h"
15 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" 15 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
16 #include "mojo/shell/shell_test_helper.h" 16 #include "mojo/shell/shell_test_helper.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace view_manager { 20 namespace view_manager {
21 namespace {
21 22
22 base::RunLoop* current_run_loop = NULL; 23 base::RunLoop* current_run_loop = NULL;
23 24
24 void DoRunLoop() { 25 void DoRunLoop() {
25 base::RunLoop run_loop; 26 base::RunLoop run_loop;
26 current_run_loop = &run_loop; 27 current_run_loop = &run_loop;
27 current_run_loop->Run(); 28 current_run_loop->Run();
28 current_run_loop = NULL; 29 current_run_loop = NULL;
29 } 30 }
30 31
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 }; 66 };
66 67
67 // Waits until the active view id of the supplied node changes. 68 // Waits until the active view id of the supplied node changes.
68 void WaitForActiveViewToChange(ViewTreeNode* node) { 69 void WaitForActiveViewToChange(ViewTreeNode* node) {
69 ActiveViewChangedObserver observer(node); 70 ActiveViewChangedObserver observer(node);
70 node->AddObserver(&observer); 71 node->AddObserver(&observer);
71 DoRunLoop(); 72 DoRunLoop();
72 node->RemoveObserver(&observer); 73 node->RemoveObserver(&observer);
73 } 74 }
74 75
76 class BoundsChangeObserver : public ViewTreeNodeObserver {
77 public:
78 explicit BoundsChangeObserver(ViewTreeNode* node) : node_(node) {}
79 virtual ~BoundsChangeObserver() {}
80
81 private:
82 // Overridden from ViewTreeNodeObserver:
83 virtual void OnNodeBoundsChange(ViewTreeNode* node,
84 const gfx::Rect& old_bounds,
85 const gfx::Rect& new_bounds,
86 DispositionChangePhase phase) OVERRIDE {
87 DCHECK_EQ(node, node_);
88 if (phase != ViewTreeNodeObserver::DISPOSITION_CHANGED)
89 return;
90 QuitRunLoop();
91 }
92
93 ViewTreeNode* node_;
94
95 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
96 };
97
98 // Wait until the bounds of the supplied node change.
99 void WaitForBoundsToChange(ViewTreeNode* node) {
100 BoundsChangeObserver observer(node);
101 node->AddObserver(&observer);
102 DoRunLoop();
103 node->RemoveObserver(&observer);
104 }
105
75 // Spins a runloop until the tree beginning at |root| has |tree_size| nodes 106 // Spins a runloop until the tree beginning at |root| has |tree_size| nodes
76 // (including |root|). 107 // (including |root|).
77 class TreeSizeMatchesObserver : public ViewTreeNodeObserver { 108 class TreeSizeMatchesObserver : public ViewTreeNodeObserver {
78 public: 109 public:
79 TreeSizeMatchesObserver(ViewTreeNode* tree, size_t tree_size) 110 TreeSizeMatchesObserver(ViewTreeNode* tree, size_t tree_size)
80 : tree_(tree), 111 : tree_(tree),
81 tree_size_(tree_size) {} 112 tree_size_(tree_size) {}
82 virtual ~TreeSizeMatchesObserver() {} 113 virtual ~TreeSizeMatchesObserver() {}
83 114
84 bool IsTreeCorrectSize() { 115 bool IsTreeCorrectSize() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 209 }
179 if (views) { 210 if (views) {
180 for (std::set<TransportViewId>::const_iterator it = views->begin(); 211 for (std::set<TransportViewId>::const_iterator it = views->begin();
181 it != views->end(); ++it) { 212 it != views->end(); ++it) {
182 view_manager->GetViewById(*it)->AddObserver(&observer); 213 view_manager->GetViewById(*it)->AddObserver(&observer);
183 } 214 }
184 } 215 }
185 DoRunLoop(); 216 DoRunLoop();
186 } 217 }
187 218
219 } // namespace
220
188 // ViewManager ----------------------------------------------------------------- 221 // ViewManager -----------------------------------------------------------------
189 222
190 // These tests model synchronization of two peer connections to the view manager 223 // These tests model synchronization of two peer connections to the view manager
191 // service, that are given access to some root node. 224 // service, that are given access to some root node.
192 225
193 class ViewManagerTest : public testing::Test { 226 class ViewManagerTest : public testing::Test {
194 public: 227 public:
195 ViewManagerTest() : commit_count_(0) {} 228 ViewManagerTest() : commit_count_(0) {}
196 229
197 protected: 230 protected:
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // second connection. 554 // second connection.
522 view_manager_1()->tree()->AddChild(node1); 555 view_manager_1()->tree()->AddChild(node1);
523 WaitForTreeSizeToMatch(view_manager_2()->tree(), 3); 556 WaitForTreeSizeToMatch(view_manager_2()->tree(), 3);
524 557
525 ViewTreeNode* node11_2 = view_manager_2()->GetNodeById(node11->id()); 558 ViewTreeNode* node11_2 = view_manager_2()->GetNodeById(node11->id());
526 View* view11_2 = view_manager_2()->GetViewById(view11->id()); 559 View* view11_2 = view_manager_2()->GetViewById(view11->id());
527 EXPECT_TRUE(node11_2 != NULL); 560 EXPECT_TRUE(node11_2 != NULL);
528 EXPECT_EQ(view11_2, node11_2->active_view()); 561 EXPECT_EQ(view11_2, node11_2->active_view());
529 } 562 }
530 563
564 // Verifies that bounds changes applied to a node hierarchy in one connection
565 // are reflected to another.
566 TEST_F(ViewManagerTest, SetBounds) {
567 ViewTreeNode* node1 = CreateNodeInParent(view_manager_1()->tree());
568 WaitForTreeSizeToMatch(view_manager_2()->tree(), 2);
569
570 ViewTreeNode* node1_2 = view_manager_2()->GetNodeById(node1->id());
571 EXPECT_EQ(node1->bounds(), node1_2->bounds());
572
573 node1->SetBounds(gfx::Rect(0, 0, 100, 100));
574 WaitForBoundsToChange(node1_2);
575 EXPECT_EQ(node1->bounds(), node1_2->bounds());
576 }
577
531 } // namespace view_manager 578 } // namespace view_manager
532 } // namespace mojo 579 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698