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

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

Issue 668663006: Standardize usage of virtual/override/final in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/public/cpp/view_manager/view_manager.h" 5 #include "mojo/services/public/cpp/view_manager/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 "mojo/application_manager/application_manager.h" 10 #include "mojo/application_manager/application_manager.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 class ConnectApplicationLoader : public ApplicationLoader, 44 class ConnectApplicationLoader : public ApplicationLoader,
45 public ApplicationDelegate, 45 public ApplicationDelegate,
46 public ViewManagerDelegate { 46 public ViewManagerDelegate {
47 public: 47 public:
48 typedef base::Callback<void(ViewManager*, View*)> LoadedCallback; 48 typedef base::Callback<void(ViewManager*, View*)> LoadedCallback;
49 49
50 explicit ConnectApplicationLoader(const LoadedCallback& callback) 50 explicit ConnectApplicationLoader(const LoadedCallback& callback)
51 : callback_(callback) {} 51 : callback_(callback) {}
52 virtual ~ConnectApplicationLoader() {} 52 ~ConnectApplicationLoader() override {}
53 53
54 private: 54 private:
55 // Overridden from ApplicationDelegate: 55 // Overridden from ApplicationDelegate:
56 virtual void Initialize(ApplicationImpl* app) override { 56 void Initialize(ApplicationImpl* app) override {
57 view_manager_client_factory_.reset( 57 view_manager_client_factory_.reset(
58 new ViewManagerClientFactory(app->shell(), this)); 58 new ViewManagerClientFactory(app->shell(), this));
59 } 59 }
60 60
61 // Overridden from ApplicationLoader: 61 // Overridden from ApplicationLoader:
62 virtual void Load(ApplicationManager* manager, 62 void Load(ApplicationManager* manager,
63 const GURL& url, 63 const GURL& url,
64 scoped_refptr<LoadCallbacks> callbacks) override { 64 scoped_refptr<LoadCallbacks> callbacks) override {
65 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication(); 65 ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
66 if (!shell_handle.is_valid()) 66 if (!shell_handle.is_valid())
67 return; 67 return;
68 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this, 68 scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this,
69 shell_handle.Pass())); 69 shell_handle.Pass()));
70 apps_.push_back(app.release()); 70 apps_.push_back(app.release());
71 } 71 }
72 72
73 virtual void OnApplicationError(ApplicationManager* manager, 73 void OnApplicationError(ApplicationManager* manager,
74 const GURL& url) override {} 74 const GURL& url) override {}
75 75
76 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 76 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
77 override {
78 connection->AddService(view_manager_client_factory_.get()); 77 connection->AddService(view_manager_client_factory_.get());
79 return true; 78 return true;
80 } 79 }
81 80
82 // Overridden from ViewManagerDelegate: 81 // Overridden from ViewManagerDelegate:
83 virtual void OnEmbed(ViewManager* view_manager, 82 void OnEmbed(ViewManager* view_manager,
84 View* root, 83 View* root,
85 ServiceProviderImpl* exported_services, 84 ServiceProviderImpl* exported_services,
86 scoped_ptr<ServiceProvider> imported_services) override { 85 scoped_ptr<ServiceProvider> imported_services) override {
87 callback_.Run(view_manager, root); 86 callback_.Run(view_manager, root);
88 } 87 }
89 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {} 88 void OnViewManagerDisconnected(ViewManager* view_manager) override {}
90 89
91 ScopedVector<ApplicationImpl> apps_; 90 ScopedVector<ApplicationImpl> apps_;
92 LoadedCallback callback_; 91 LoadedCallback callback_;
93 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; 92 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
94 93
95 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader); 94 DISALLOW_COPY_AND_ASSIGN(ConnectApplicationLoader);
96 }; 95 };
97 96
98 class BoundsChangeObserver : public ViewObserver { 97 class BoundsChangeObserver : public ViewObserver {
99 public: 98 public:
100 explicit BoundsChangeObserver(View* view) : view_(view) {} 99 explicit BoundsChangeObserver(View* view) : view_(view) {}
101 virtual ~BoundsChangeObserver() {} 100 ~BoundsChangeObserver() override {}
102 101
103 private: 102 private:
104 // Overridden from ViewObserver: 103 // Overridden from ViewObserver:
105 virtual void OnViewBoundsChanged(View* view, 104 void OnViewBoundsChanged(View* view,
106 const gfx::Rect& old_bounds, 105 const gfx::Rect& old_bounds,
107 const gfx::Rect& new_bounds) override { 106 const gfx::Rect& new_bounds) override {
108 DCHECK_EQ(view, view_); 107 DCHECK_EQ(view, view_);
109 QuitRunLoop(); 108 QuitRunLoop();
110 } 109 }
111 110
112 View* view_; 111 View* view_;
113 112
114 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 113 DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
115 }; 114 };
116 115
117 // Wait until the bounds of the supplied view change. 116 // Wait until the bounds of the supplied view change.
118 void WaitForBoundsToChange(View* view) { 117 void WaitForBoundsToChange(View* view) {
119 BoundsChangeObserver observer(view); 118 BoundsChangeObserver observer(view);
120 view->AddObserver(&observer); 119 view->AddObserver(&observer);
121 DoRunLoop(); 120 DoRunLoop();
122 view->RemoveObserver(&observer); 121 view->RemoveObserver(&observer);
123 } 122 }
124 123
125 // Spins a runloop until the tree beginning at |root| has |tree_size| views 124 // Spins a runloop until the tree beginning at |root| has |tree_size| views
126 // (including |root|). 125 // (including |root|).
127 class TreeSizeMatchesObserver : public ViewObserver { 126 class TreeSizeMatchesObserver : public ViewObserver {
128 public: 127 public:
129 TreeSizeMatchesObserver(View* tree, size_t tree_size) 128 TreeSizeMatchesObserver(View* tree, size_t tree_size)
130 : tree_(tree), 129 : tree_(tree),
131 tree_size_(tree_size) {} 130 tree_size_(tree_size) {}
132 virtual ~TreeSizeMatchesObserver() {} 131 ~TreeSizeMatchesObserver() override {}
133 132
134 bool IsTreeCorrectSize() { 133 bool IsTreeCorrectSize() {
135 return CountViews(tree_) == tree_size_; 134 return CountViews(tree_) == tree_size_;
136 } 135 }
137 136
138 private: 137 private:
139 // Overridden from ViewObserver: 138 // Overridden from ViewObserver:
140 virtual void OnTreeChanged(const TreeChangeParams& params) override { 139 void OnTreeChanged(const TreeChangeParams& params) override {
141 if (IsTreeCorrectSize()) 140 if (IsTreeCorrectSize())
142 QuitRunLoop(); 141 QuitRunLoop();
143 } 142 }
144 143
145 size_t CountViews(const View* view) const { 144 size_t CountViews(const View* view) const {
146 size_t count = 1; 145 size_t count = 1;
147 View::Children::const_iterator it = view->children().begin(); 146 View::Children::const_iterator it = view->children().begin();
148 for (; it != view->children().end(); ++it) 147 for (; it != view->children().end(); ++it)
149 count += CountViews(*it); 148 count += CountViews(*it);
150 return count; 149 return count;
(...skipping 16 matching lines...) Expand all
167 166
168 // Utility class that waits for the destruction of some number of views and 167 // Utility class that waits for the destruction of some number of views and
169 // views. 168 // views.
170 class DestructionObserver : public ViewObserver { 169 class DestructionObserver : public ViewObserver {
171 public: 170 public:
172 // |views| or |views| can be NULL. 171 // |views| or |views| can be NULL.
173 explicit DestructionObserver(std::set<Id>* views) : views_(views) {} 172 explicit DestructionObserver(std::set<Id>* views) : views_(views) {}
174 173
175 private: 174 private:
176 // Overridden from ViewObserver: 175 // Overridden from ViewObserver:
177 virtual void OnViewDestroyed(View* view) override { 176 void OnViewDestroyed(View* view) override {
178 std::set<Id>::iterator it = views_->find(view->id()); 177 std::set<Id>::iterator it = views_->find(view->id());
179 if (it != views_->end()) 178 if (it != views_->end())
180 views_->erase(it); 179 views_->erase(it);
181 if (CanQuit()) 180 if (CanQuit())
182 QuitRunLoop(); 181 QuitRunLoop();
183 } 182 }
184 183
185 bool CanQuit() { 184 bool CanQuit() {
186 return !views_ || views_->empty(); 185 return !views_ || views_->empty();
187 } 186 }
(...skipping 13 matching lines...) Expand all
201 } 200 }
202 } 201 }
203 DoRunLoop(); 202 DoRunLoop();
204 } 203 }
205 204
206 class OrderChangeObserver : public ViewObserver { 205 class OrderChangeObserver : public ViewObserver {
207 public: 206 public:
208 OrderChangeObserver(View* view) : view_(view) { 207 OrderChangeObserver(View* view) : view_(view) {
209 view_->AddObserver(this); 208 view_->AddObserver(this);
210 } 209 }
211 virtual ~OrderChangeObserver() { 210 ~OrderChangeObserver() override { view_->RemoveObserver(this); }
212 view_->RemoveObserver(this);
213 }
214 211
215 private: 212 private:
216 // Overridden from ViewObserver: 213 // Overridden from ViewObserver:
217 virtual void OnViewReordered(View* view, 214 void OnViewReordered(View* view,
218 View* relative_view, 215 View* relative_view,
219 OrderDirection direction) override { 216 OrderDirection direction) override {
220 DCHECK_EQ(view, view_); 217 DCHECK_EQ(view, view_);
221 QuitRunLoop(); 218 QuitRunLoop();
222 } 219 }
223 220
224 View* view_; 221 View* view_;
225 222
226 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); 223 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver);
227 }; 224 };
228 225
229 void WaitForOrderChange(ViewManager* view_manager, View* view) { 226 void WaitForOrderChange(ViewManager* view_manager, View* view) {
230 OrderChangeObserver observer(view); 227 OrderChangeObserver observer(view);
231 DoRunLoop(); 228 DoRunLoop();
232 } 229 }
233 230
234 // Tracks a view's destruction. Query is_valid() for current state. 231 // Tracks a view's destruction. Query is_valid() for current state.
235 class ViewTracker : public ViewObserver { 232 class ViewTracker : public ViewObserver {
236 public: 233 public:
237 explicit ViewTracker(View* view) : view_(view) { 234 explicit ViewTracker(View* view) : view_(view) {
238 view_->AddObserver(this); 235 view_->AddObserver(this);
239 } 236 }
240 virtual ~ViewTracker() { 237 ~ViewTracker() override {
241 if (view_) 238 if (view_)
242 view_->RemoveObserver(this); 239 view_->RemoveObserver(this);
243 } 240 }
244 241
245 bool is_valid() const { return !!view_; } 242 bool is_valid() const { return !!view_; }
246 243
247 private: 244 private:
248 // Overridden from ViewObserver: 245 // Overridden from ViewObserver:
249 virtual void OnViewDestroyed(View* view) override { 246 void OnViewDestroyed(View* view) override {
250 DCHECK_EQ(view, view_); 247 DCHECK_EQ(view, view_);
251 view_ = NULL; 248 view_ = NULL;
252 } 249 }
253 250
254 int id_; 251 int id_;
255 View* view_; 252 View* view_;
256 253
257 DISALLOW_COPY_AND_ASSIGN(ViewTracker); 254 DISALLOW_COPY_AND_ASSIGN(ViewTracker);
258 }; 255 };
259 256
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 525 }
529 } 526 }
530 527
531 namespace { 528 namespace {
532 529
533 class VisibilityChangeObserver : public ViewObserver { 530 class VisibilityChangeObserver : public ViewObserver {
534 public: 531 public:
535 explicit VisibilityChangeObserver(View* view) : view_(view) { 532 explicit VisibilityChangeObserver(View* view) : view_(view) {
536 view_->AddObserver(this); 533 view_->AddObserver(this);
537 } 534 }
538 virtual ~VisibilityChangeObserver() { view_->RemoveObserver(this); } 535 ~VisibilityChangeObserver() override { view_->RemoveObserver(this); }
539 536
540 private: 537 private:
541 // Overridden from ViewObserver: 538 // Overridden from ViewObserver:
542 virtual void OnViewVisibilityChanged(View* view) override { 539 void OnViewVisibilityChanged(View* view) override {
543 EXPECT_EQ(view, view_); 540 EXPECT_EQ(view, view_);
544 QuitRunLoop(); 541 QuitRunLoop();
545 } 542 }
546 543
547 View* view_; 544 View* view_;
548 545
549 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); 546 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
550 }; 547 };
551 548
552 } // namespace 549 } // namespace
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 EXPECT_TRUE(embedded_root->IsDrawn()); 587 EXPECT_TRUE(embedded_root->IsDrawn());
591 } 588 }
592 589
593 namespace { 590 namespace {
594 591
595 class DrawnChangeObserver : public ViewObserver { 592 class DrawnChangeObserver : public ViewObserver {
596 public: 593 public:
597 explicit DrawnChangeObserver(View* view) : view_(view) { 594 explicit DrawnChangeObserver(View* view) : view_(view) {
598 view_->AddObserver(this); 595 view_->AddObserver(this);
599 } 596 }
600 virtual ~DrawnChangeObserver() { view_->RemoveObserver(this); } 597 ~DrawnChangeObserver() override { view_->RemoveObserver(this); }
601 598
602 private: 599 private:
603 // Overridden from ViewObserver: 600 // Overridden from ViewObserver:
604 virtual void OnViewDrawnChanged(View* view) override { 601 void OnViewDrawnChanged(View* view) override {
605 EXPECT_EQ(view, view_); 602 EXPECT_EQ(view, view_);
606 QuitRunLoop(); 603 QuitRunLoop();
607 } 604 }
608 605
609 View* view_; 606 View* view_;
610 607
611 DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver); 608 DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver);
612 }; 609 };
613 610
614 } // namespace 611 } // namespace
(...skipping 26 matching lines...) Expand all
641 638
642 // TODO(beng): tests for view event dispatcher. 639 // TODO(beng): tests for view event dispatcher.
643 // - verify that we see events for all views. 640 // - verify that we see events for all views.
644 641
645 // TODO(beng): tests for focus: 642 // TODO(beng): tests for focus:
646 // - focus between two views known to a connection 643 // - focus between two views known to a connection
647 // - focus between views unknown to one of the connections. 644 // - focus between views unknown to one of the connections.
648 // - focus between views unknown to either connection. 645 // - focus between views unknown to either connection.
649 646
650 } // namespace mojo 647 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698