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

Side by Side Diff: mojo/services/public/cpp/view_manager/tests/view_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, 1 month 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.h" 5 #include "mojo/services/public/cpp/view_manager/view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h"
10 #include "mojo/services/public/cpp/view_manager/util.h" 10 #include "mojo/services/public/cpp/view_manager/util.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const ViewObserver::TreeChangeParams& rhs) { 110 const ViewObserver::TreeChangeParams& rhs) {
111 return lhs.target == rhs.target && lhs.old_parent == rhs.old_parent && 111 return lhs.target == rhs.target && lhs.old_parent == rhs.old_parent &&
112 lhs.new_parent == rhs.new_parent && lhs.receiver == rhs.receiver; 112 lhs.new_parent == rhs.new_parent && lhs.receiver == rhs.receiver;
113 } 113 }
114 114
115 class TreeChangeObserver : public ViewObserver { 115 class TreeChangeObserver : public ViewObserver {
116 public: 116 public:
117 explicit TreeChangeObserver(View* observee) : observee_(observee) { 117 explicit TreeChangeObserver(View* observee) : observee_(observee) {
118 observee_->AddObserver(this); 118 observee_->AddObserver(this);
119 } 119 }
120 virtual ~TreeChangeObserver() { 120 ~TreeChangeObserver() override { observee_->RemoveObserver(this); }
121 observee_->RemoveObserver(this);
122 }
123 121
124 void Reset() { 122 void Reset() {
125 received_params_.clear(); 123 received_params_.clear();
126 } 124 }
127 125
128 const std::vector<TreeChangeParams>& received_params() { 126 const std::vector<TreeChangeParams>& received_params() {
129 return received_params_; 127 return received_params_;
130 } 128 }
131 129
132 private: 130 private:
133 // Overridden from ViewObserver: 131 // Overridden from ViewObserver:
134 virtual void OnTreeChanging(const TreeChangeParams& params) override { 132 void OnTreeChanging(const TreeChangeParams& params) override {
135 received_params_.push_back(params); 133 received_params_.push_back(params);
136 } 134 }
137 virtual void OnTreeChanged(const TreeChangeParams& params) override { 135 void OnTreeChanged(const TreeChangeParams& params) override {
138 received_params_.push_back(params); 136 received_params_.push_back(params);
139 } 137 }
140 138
141 View* observee_; 139 View* observee_;
142 std::vector<TreeChangeParams> received_params_; 140 std::vector<TreeChangeParams> received_params_;
143 141
144 DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver); 142 DISALLOW_COPY_AND_ASSIGN(TreeChangeObserver);
145 }; 143 };
146 144
147 // Adds/Removes v11 to v1. 145 // Adds/Removes v11 to v1.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 struct Change { 344 struct Change {
347 View* view; 345 View* view;
348 View* relative_view; 346 View* relative_view;
349 OrderDirection direction; 347 OrderDirection direction;
350 }; 348 };
351 typedef std::vector<Change> Changes; 349 typedef std::vector<Change> Changes;
352 350
353 explicit OrderChangeObserver(View* observee) : observee_(observee) { 351 explicit OrderChangeObserver(View* observee) : observee_(observee) {
354 observee_->AddObserver(this); 352 observee_->AddObserver(this);
355 } 353 }
356 virtual ~OrderChangeObserver() { 354 ~OrderChangeObserver() override { observee_->RemoveObserver(this); }
357 observee_->RemoveObserver(this);
358 }
359 355
360 Changes GetAndClearChanges() { 356 Changes GetAndClearChanges() {
361 Changes changes; 357 Changes changes;
362 changes_.swap(changes); 358 changes_.swap(changes);
363 return changes; 359 return changes;
364 } 360 }
365 361
366 private: 362 private:
367 // Overridden from ViewObserver: 363 // Overridden from ViewObserver:
368 virtual void OnViewReordering(View* view, 364 void OnViewReordering(View* view,
369 View* relative_view, 365 View* relative_view,
370 OrderDirection direction) override { 366 OrderDirection direction) override {
371 OnViewReordered(view, relative_view, direction); 367 OnViewReordered(view, relative_view, direction);
372 } 368 }
373 369
374 virtual void OnViewReordered(View* view, 370 void OnViewReordered(View* view,
375 View* relative_view, 371 View* relative_view,
376 OrderDirection direction) override { 372 OrderDirection direction) override {
377 Change change; 373 Change change;
378 change.view = view; 374 change.view = view;
379 change.relative_view = relative_view; 375 change.relative_view = relative_view;
380 change.direction = direction; 376 change.direction = direction;
381 changes_.push_back(change); 377 changes_.push_back(change);
382 } 378 }
383 379
384 View* observee_; 380 View* observee_;
385 Changes changes_; 381 Changes changes_;
386 382
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 std::string RectToString(const gfx::Rect& rect) { 489 std::string RectToString(const gfx::Rect& rect) {
494 return base::StringPrintf("%d,%d %dx%d", 490 return base::StringPrintf("%d,%d %dx%d",
495 rect.x(), rect.y(), rect.width(), rect.height()); 491 rect.x(), rect.y(), rect.width(), rect.height());
496 } 492 }
497 493
498 class BoundsChangeObserver : public ViewObserver { 494 class BoundsChangeObserver : public ViewObserver {
499 public: 495 public:
500 explicit BoundsChangeObserver(View* view) : view_(view) { 496 explicit BoundsChangeObserver(View* view) : view_(view) {
501 view_->AddObserver(this); 497 view_->AddObserver(this);
502 } 498 }
503 virtual ~BoundsChangeObserver() { 499 ~BoundsChangeObserver() override { view_->RemoveObserver(this); }
504 view_->RemoveObserver(this);
505 }
506 500
507 Changes GetAndClearChanges() { 501 Changes GetAndClearChanges() {
508 Changes changes; 502 Changes changes;
509 changes.swap(changes_); 503 changes.swap(changes_);
510 return changes; 504 return changes;
511 } 505 }
512 506
513 private: 507 private:
514 // Overridden from ViewObserver: 508 // Overridden from ViewObserver:
515 virtual void OnViewBoundsChanging(View* view, 509 void OnViewBoundsChanging(View* view,
516 const gfx::Rect& old_bounds, 510 const gfx::Rect& old_bounds,
517 const gfx::Rect& new_bounds) override { 511 const gfx::Rect& new_bounds) override {
518 changes_.push_back( 512 changes_.push_back(
519 base::StringPrintf( 513 base::StringPrintf(
520 "view=%s old_bounds=%s new_bounds=%s phase=changing", 514 "view=%s old_bounds=%s new_bounds=%s phase=changing",
521 ViewIdToString(view->id()).c_str(), 515 ViewIdToString(view->id()).c_str(),
522 RectToString(old_bounds).c_str(), 516 RectToString(old_bounds).c_str(),
523 RectToString(new_bounds).c_str())); 517 RectToString(new_bounds).c_str()));
524 } 518 }
525 virtual void OnViewBoundsChanged(View* view, 519 void OnViewBoundsChanged(View* view,
526 const gfx::Rect& old_bounds, 520 const gfx::Rect& old_bounds,
527 const gfx::Rect& new_bounds) override { 521 const gfx::Rect& new_bounds) override {
528 changes_.push_back( 522 changes_.push_back(
529 base::StringPrintf( 523 base::StringPrintf(
530 "view=%s old_bounds=%s new_bounds=%s phase=changed", 524 "view=%s old_bounds=%s new_bounds=%s phase=changed",
531 ViewIdToString(view->id()).c_str(), 525 ViewIdToString(view->id()).c_str(),
532 RectToString(old_bounds).c_str(), 526 RectToString(old_bounds).c_str(),
533 RectToString(new_bounds).c_str())); 527 RectToString(new_bounds).c_str()));
534 } 528 }
535 529
536 View* view_; 530 View* view_;
537 Changes changes_; 531 Changes changes_;
(...skipping 20 matching lines...) Expand all
558 } 552 }
559 } 553 }
560 554
561 namespace { 555 namespace {
562 556
563 class VisibilityChangeObserver : public ViewObserver { 557 class VisibilityChangeObserver : public ViewObserver {
564 public: 558 public:
565 explicit VisibilityChangeObserver(View* view) : view_(view) { 559 explicit VisibilityChangeObserver(View* view) : view_(view) {
566 view_->AddObserver(this); 560 view_->AddObserver(this);
567 } 561 }
568 virtual ~VisibilityChangeObserver() { view_->RemoveObserver(this); } 562 ~VisibilityChangeObserver() override { view_->RemoveObserver(this); }
569 563
570 Changes GetAndClearChanges() { 564 Changes GetAndClearChanges() {
571 Changes changes; 565 Changes changes;
572 changes.swap(changes_); 566 changes.swap(changes_);
573 return changes; 567 return changes;
574 } 568 }
575 569
576 private: 570 private:
577 // Overridden from ViewObserver: 571 // Overridden from ViewObserver:
578 virtual void OnViewVisibilityChanging(View* view) override { 572 void OnViewVisibilityChanging(View* view) override {
579 changes_.push_back( 573 changes_.push_back(
580 base::StringPrintf("view=%s phase=changing visibility=%s", 574 base::StringPrintf("view=%s phase=changing visibility=%s",
581 ViewIdToString(view->id()).c_str(), 575 ViewIdToString(view->id()).c_str(),
582 view->visible() ? "true" : "false")); 576 view->visible() ? "true" : "false"));
583 } 577 }
584 virtual void OnViewVisibilityChanged(View* view) override { 578 void OnViewVisibilityChanged(View* view) override {
585 changes_.push_back(base::StringPrintf("view=%s phase=changed visibility=%s", 579 changes_.push_back(base::StringPrintf("view=%s phase=changed visibility=%s",
586 ViewIdToString(view->id()).c_str(), 580 ViewIdToString(view->id()).c_str(),
587 view->visible() ? "true" : "false")); 581 view->visible() ? "true" : "false"));
588 } 582 }
589 583
590 View* view_; 584 View* view_;
591 Changes changes_; 585 Changes changes_;
592 586
593 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); 587 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver);
594 }; 588 };
(...skipping 15 matching lines...) Expand all
610 } 604 }
611 { 605 {
612 // Set visible to existing value and verify no notifications. 606 // Set visible to existing value and verify no notifications.
613 VisibilityChangeObserver observer(&v1); 607 VisibilityChangeObserver observer(&v1);
614 v1.SetVisible(false); 608 v1.SetVisible(false);
615 EXPECT_TRUE(observer.GetAndClearChanges().empty()); 609 EXPECT_TRUE(observer.GetAndClearChanges().empty());
616 } 610 }
617 } 611 }
618 612
619 } // namespace mojo 613 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698