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

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

Issue 911073005: Drop all uses of //base except ObserverList from view mgr client lib (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: gn check Created 5 years, 10 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
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/view_manager/public/cpp/view_manager.h" 5 #include "mojo/services/view_manager/public/cpp/view_manager.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_vector.h"
10 #include "mojo/public/cpp/application/application_connection.h" 11 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 12 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 13 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/service_provider_impl.h" 14 #include "mojo/public/cpp/application/service_provider_impl.h"
14 #include "mojo/public/interfaces/application/service_provider.mojom.h" 15 #include "mojo/public/interfaces/application/service_provider.mojom.h"
15 #include "mojo/services/geometry/public/cpp/geometry_util.h" 16 #include "mojo/services/geometry/public/cpp/geometry_util.h"
16 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h" 17 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h"
17 #include "mojo/services/view_manager/public/cpp/lib/view_private.h" 18 #include "mojo/services/view_manager/public/cpp/lib/view_private.h"
18 #include "mojo/services/view_manager/public/cpp/util.h" 19 #include "mojo/services/view_manager/public/cpp/util.h"
19 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h" 20 #include "mojo/services/view_manager/public/cpp/view_manager_client_factory.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 InterfaceRequest<ServiceProvider> services, 85 InterfaceRequest<ServiceProvider> services,
85 ServiceProviderPtr exposed_services) override { 86 ServiceProviderPtr exposed_services) override {
86 callback_.Run(root); 87 callback_.Run(root);
87 } 88 }
88 void OnViewManagerDisconnected(ViewManager* view_manager) override {} 89 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
89 90
90 ScopedVector<ApplicationImpl> apps_; 91 ScopedVector<ApplicationImpl> apps_;
91 LoadedCallback callback_; 92 LoadedCallback callback_;
92 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; 93 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
93 94
94 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); 95 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader);
95 }; 96 };
96 97
97 class BoundsChangeObserver : public ViewObserver { 98 class BoundsChangeObserver : public ViewObserver {
98 public: 99 public:
99 explicit BoundsChangeObserver(View* view) : view_(view) {} 100 explicit BoundsChangeObserver(View* view) : view_(view) {}
100 ~BoundsChangeObserver() override {} 101 ~BoundsChangeObserver() override {}
101 102
102 private: 103 private:
103 // Overridden from ViewObserver: 104 // Overridden from ViewObserver:
104 void OnViewBoundsChanged(View* view, 105 void OnViewBoundsChanged(View* view,
105 const Rect& old_bounds, 106 const Rect& old_bounds,
106 const Rect& new_bounds) override { 107 const Rect& new_bounds) override {
107 DCHECK_EQ(view, view_); 108 DCHECK_EQ(view, view_);
108 QuitRunLoop(); 109 QuitRunLoop();
109 } 110 }
110 111
111 View* view_; 112 View* view_;
112 113
113 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 114 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
114 }; 115 };
115 116
116 // Wait until the bounds of the supplied view change. 117 // Wait until the bounds of the supplied view change.
117 void WaitForBoundsToChange(View* view) { 118 void WaitForBoundsToChange(View* view) {
118 BoundsChangeObserver observer(view); 119 BoundsChangeObserver observer(view);
119 view->AddObserver(&observer); 120 view->AddObserver(&observer);
120 DoRunLoop(); 121 DoRunLoop();
121 view->RemoveObserver(&observer); 122 view->RemoveObserver(&observer);
122 } 123 }
123 124
(...skipping 21 matching lines...) Expand all
145 size_t count = 1; 146 size_t count = 1;
146 View::Children::const_iterator it = view->children().begin(); 147 View::Children::const_iterator it = view->children().begin();
147 for (; it != view->children().end(); ++it) 148 for (; it != view->children().end(); ++it)
148 count += CountViews(*it); 149 count += CountViews(*it);
149 return count; 150 return count;
150 } 151 }
151 152
152 View* tree_; 153 View* tree_;
153 size_t tree_size_; 154 size_t tree_size_;
154 155
155 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); 156 MOJO_DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver);
156 }; 157 };
157 158
158 void WaitForTreeSizeToMatch(View* view, size_t tree_size) { 159 void WaitForTreeSizeToMatch(View* view, size_t tree_size) {
159 TreeSizeMatchesObserver observer(view, tree_size); 160 TreeSizeMatchesObserver observer(view, tree_size);
160 if (observer.IsTreeCorrectSize()) 161 if (observer.IsTreeCorrectSize())
161 return; 162 return;
162 view->AddObserver(&observer); 163 view->AddObserver(&observer);
163 DoRunLoop(); 164 DoRunLoop();
164 view->RemoveObserver(&observer); 165 view->RemoveObserver(&observer);
165 } 166 }
(...skipping 14 matching lines...) Expand all
180 if (CanQuit()) 181 if (CanQuit())
181 QuitRunLoop(); 182 QuitRunLoop();
182 } 183 }
183 184
184 bool CanQuit() { 185 bool CanQuit() {
185 return !views_ || views_->empty(); 186 return !views_ || views_->empty();
186 } 187 }
187 188
188 std::set<Id>* views_; 189 std::set<Id>* views_;
189 190
190 DISALLOW_COPY_AND_ASSIGN(DestructionObserver); 191 MOJO_DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
191 }; 192 };
192 193
193 void WaitForDestruction(ViewManager* view_manager, std::set<Id>* views) { 194 void WaitForDestruction(ViewManager* view_manager, std::set<Id>* views) {
194 DestructionObserver observer(views); 195 DestructionObserver observer(views);
195 DCHECK(views); 196 DCHECK(views);
196 if (views) { 197 if (views) {
197 for (std::set<Id>::const_iterator it = views->begin(); 198 for (std::set<Id>::const_iterator it = views->begin();
198 it != views->end(); ++it) { 199 it != views->end(); ++it) {
199 view_manager->GetViewById(*it)->AddObserver(&observer); 200 view_manager->GetViewById(*it)->AddObserver(&observer);
200 } 201 }
(...skipping 12 matching lines...) Expand all
213 // Overridden from ViewObserver: 214 // Overridden from ViewObserver:
214 void OnViewReordered(View* view, 215 void OnViewReordered(View* view,
215 View* relative_view, 216 View* relative_view,
216 OrderDirection direction) override { 217 OrderDirection direction) override {
217 DCHECK_EQ(view, view_); 218 DCHECK_EQ(view, view_);
218 QuitRunLoop(); 219 QuitRunLoop();
219 } 220 }
220 221
221 View* view_; 222 View* view_;
222 223
223 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); 224 MOJO_DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver);
224 }; 225 };
225 226
226 void WaitForOrderChange(ViewManager* view_manager, View* view) { 227 void WaitForOrderChange(ViewManager* view_manager, View* view) {
227 OrderChangeObserver observer(view); 228 OrderChangeObserver observer(view);
228 DoRunLoop(); 229 DoRunLoop();
229 } 230 }
230 231
231 // Tracks a view's destruction. Query is_valid() for current state. 232 // Tracks a view's destruction. Query is_valid() for current state.
232 class ViewTracker : public ViewObserver { 233 class ViewTracker : public ViewObserver {
233 public: 234 public:
(...skipping 10 matching lines...) Expand all
244 private: 245 private:
245 // Overridden from ViewObserver: 246 // Overridden from ViewObserver:
246 void OnViewDestroyed(View* view) override { 247 void OnViewDestroyed(View* view) override {
247 DCHECK_EQ(view, view_); 248 DCHECK_EQ(view, view_);
248 view_ = NULL; 249 view_ = NULL;
249 } 250 }
250 251
251 int id_; 252 int id_;
252 View* view_; 253 View* view_;
253 254
254 DISALLOW_COPY_AND_ASSIGN(ViewTracker); 255 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTracker);
255 }; 256 };
256 257
257 } // namespace 258 } // namespace
258 259
259 // ViewManager ----------------------------------------------------------------- 260 // ViewManager -----------------------------------------------------------------
260 261
261 // These tests model synchronization of two peer connections to the view manager 262 // These tests model synchronization of two peer connections to the view manager
262 // service, that are given access to some root view. 263 // service, that are given access to some root view.
263 264
264 class ViewManagerTest : public testing::Test { 265 class ViewManagerTest : public testing::Test {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 331
331 base::RunLoop* connect_loop_; 332 base::RunLoop* connect_loop_;
332 shell::ShellTestHelper test_helper_; 333 shell::ShellTestHelper test_helper_;
333 // Used to receive the most recent view manager loaded by an embed action. 334 // Used to receive the most recent view manager loaded by an embed action.
334 ViewManager* loaded_view_manager_; 335 ViewManager* loaded_view_manager_;
335 // The View Manager connection held by the window manager (app running at the 336 // The View Manager connection held by the window manager (app running at the
336 // root view). 337 // root view).
337 ViewManager* window_manager_; 338 ViewManager* window_manager_;
338 int commit_count_; 339 int commit_count_;
339 340
340 DISALLOW_COPY_AND_ASSIGN(ViewManagerTest); 341 MOJO_DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
341 }; 342 };
342 343
343 // TODO(sky): all of these tests are disabled as each test triggers running 344 // TODO(sky): all of these tests are disabled as each test triggers running
344 // ViewsInit, which tries to register the same set of paths with the 345 // ViewsInit, which tries to register the same set of paths with the
345 // PathService, triggering a DCHECK. 346 // PathService, triggering a DCHECK.
346 TEST_F(ViewManagerTest, DISABLED_SetUp) {} 347 TEST_F(ViewManagerTest, DISABLED_SetUp) {}
347 348
348 TEST_F(ViewManagerTest, DISABLED_Embed) { 349 TEST_F(ViewManagerTest, DISABLED_Embed) {
349 View* view = window_manager()->CreateView(); 350 View* view = window_manager()->CreateView();
350 view->SetVisible(true); 351 view->SetVisible(true);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 537
537 private: 538 private:
538 // Overridden from ViewObserver: 539 // Overridden from ViewObserver:
539 void OnViewVisibilityChanged(View* view) override { 540 void OnViewVisibilityChanged(View* view) override {
540 EXPECT_EQ(view, view_); 541 EXPECT_EQ(view, view_);
541 QuitRunLoop(); 542 QuitRunLoop();
542 } 543 }
543 544
544 View* view_; 545 View* view_;
545 546
546 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); 547 MOJO_DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
547 }; 548 };
548 549
549 } // namespace 550 } // namespace
550 551
551 TEST_F(ViewManagerTest, DISABLED_Visible) { 552 TEST_F(ViewManagerTest, DISABLED_Visible) {
552 View* view1 = window_manager()->CreateView(); 553 View* view1 = window_manager()->CreateView();
553 view1->SetVisible(true); 554 view1->SetVisible(true);
554 window_manager()->GetRoot()->AddChild(view1); 555 window_manager()->GetRoot()->AddChild(view1);
555 556
556 // Embed another app and verify initial state. 557 // Embed another app and verify initial state.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 600
600 private: 601 private:
601 // Overridden from ViewObserver: 602 // Overridden from ViewObserver:
602 void OnViewDrawnChanged(View* view) override { 603 void OnViewDrawnChanged(View* view) override {
603 EXPECT_EQ(view, view_); 604 EXPECT_EQ(view, view_);
604 QuitRunLoop(); 605 QuitRunLoop();
605 } 606 }
606 607
607 View* view_; 608 View* view_;
608 609
609 DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver); 610 MOJO_DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver);
610 }; 611 };
611 612
612 } // namespace 613 } // namespace
613 614
614 TEST_F(ViewManagerTest, DISABLED_Drawn) { 615 TEST_F(ViewManagerTest, DISABLED_Drawn) {
615 View* view1 = window_manager()->CreateView(); 616 View* view1 = window_manager()->CreateView();
616 view1->SetVisible(true); 617 view1->SetVisible(true);
617 window_manager()->GetRoot()->AddChild(view1); 618 window_manager()->GetRoot()->AddChild(view1);
618 619
619 // Embed another app and verify initial state. 620 // Embed another app and verify initial state.
(...skipping 23 matching lines...) Expand all
643 644
644 // TODO(beng): tests for focus: 645 // TODO(beng): tests for focus:
645 // - focus between two views known to a connection 646 // - focus between two views known to a connection
646 // - focus between views unknown to one of the connections. 647 // - focus between views unknown to one of the connections.
647 // - focus between views unknown to either connection. 648 // - focus between views unknown to either connection.
648 649
649 // TODO(sky): need test of root being destroyed with existing views. See 650 // TODO(sky): need test of root being destroyed with existing views. See
650 // 434555 for specific case. 651 // 434555 for specific case.
651 652
652 } // namespace mojo 653 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698