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

Side by Side Diff: components/mus/public/cpp/tests/view_unittest.cc

Issue 1340983002: Mandoline UI Process: Update namespaces and file names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 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 "components/mus/public/cpp/view.h" 5 #include "components/mus/public/cpp/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 "components/mus/public/cpp/lib/view_private.h" 9 #include "components/mus/public/cpp/lib/view_private.h"
10 #include "components/mus/public/cpp/util.h" 10 #include "components/mus/public/cpp/util.h"
11 #include "components/mus/public/cpp/view_observer.h" 11 #include "components/mus/public/cpp/view_observer.h"
12 #include "components/mus/public/cpp/view_property.h" 12 #include "components/mus/public/cpp/view_property.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace mojo { 15 namespace mus {
16 16
17 // View ------------------------------------------------------------------------ 17 // View ------------------------------------------------------------------------
18 18
19 typedef testing::Test ViewTest; 19 typedef testing::Test ViewTest;
20 20
21 // Subclass with public ctor/dtor. 21 // Subclass with public ctor/dtor.
22 class TestView : public View { 22 class TestView : public View {
23 public: 23 public:
24 TestView() { ViewPrivate(this).set_id(1); } 24 TestView() { ViewPrivate(this).set_id(1); }
25 ~TestView() {} 25 ~TestView() {}
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 EXPECT_TRUE(TreeChangeParamsMatch(p111, o111.received_params().back())); 416 EXPECT_TRUE(TreeChangeParamsMatch(p111, o111.received_params().back()));
417 } 417 }
418 418
419 namespace { 419 namespace {
420 420
421 class OrderChangeObserver : public ViewObserver { 421 class OrderChangeObserver : public ViewObserver {
422 public: 422 public:
423 struct Change { 423 struct Change {
424 View* view; 424 View* view;
425 View* relative_view; 425 View* relative_view;
426 OrderDirection direction; 426 mojo::OrderDirection direction;
427 }; 427 };
428 typedef std::vector<Change> Changes; 428 typedef std::vector<Change> Changes;
429 429
430 explicit OrderChangeObserver(View* observee) : observee_(observee) { 430 explicit OrderChangeObserver(View* observee) : observee_(observee) {
431 observee_->AddObserver(this); 431 observee_->AddObserver(this);
432 } 432 }
433 ~OrderChangeObserver() override { observee_->RemoveObserver(this); } 433 ~OrderChangeObserver() override { observee_->RemoveObserver(this); }
434 434
435 Changes GetAndClearChanges() { 435 Changes GetAndClearChanges() {
436 Changes changes; 436 Changes changes;
437 changes_.swap(changes); 437 changes_.swap(changes);
438 return changes; 438 return changes;
439 } 439 }
440 440
441 private: 441 private:
442 // Overridden from ViewObserver: 442 // Overridden from ViewObserver:
443 void OnViewReordering(View* view, 443 void OnViewReordering(View* view,
444 View* relative_view, 444 View* relative_view,
445 OrderDirection direction) override { 445 mojo::OrderDirection direction) override {
446 OnViewReordered(view, relative_view, direction); 446 OnViewReordered(view, relative_view, direction);
447 } 447 }
448 448
449 void OnViewReordered(View* view, 449 void OnViewReordered(View* view,
450 View* relative_view, 450 View* relative_view,
451 OrderDirection direction) override { 451 mojo::OrderDirection direction) override {
452 Change change; 452 Change change;
453 change.view = view; 453 change.view = view;
454 change.relative_view = relative_view; 454 change.relative_view = relative_view;
455 change.direction = direction; 455 change.direction = direction;
456 changes_.push_back(change); 456 changes_.push_back(change);
457 } 457 }
458 458
459 View* observee_; 459 View* observee_;
460 Changes changes_; 460 Changes changes_;
461 461
(...skipping 19 matching lines...) Expand all
481 // Move v11 to front. 481 // Move v11 to front.
482 // Resulting order: v12, v13, v11 482 // Resulting order: v12, v13, v11
483 v11.MoveToFront(); 483 v11.MoveToFront();
484 EXPECT_EQ(&v12, v1.children().front()); 484 EXPECT_EQ(&v12, v1.children().front());
485 EXPECT_EQ(&v11, v1.children().back()); 485 EXPECT_EQ(&v11, v1.children().back());
486 486
487 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); 487 OrderChangeObserver::Changes changes = observer.GetAndClearChanges();
488 ASSERT_EQ(2U, changes.size()); 488 ASSERT_EQ(2U, changes.size());
489 EXPECT_EQ(&v11, changes[0].view); 489 EXPECT_EQ(&v11, changes[0].view);
490 EXPECT_EQ(&v13, changes[0].relative_view); 490 EXPECT_EQ(&v13, changes[0].relative_view);
491 EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[0].direction); 491 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[0].direction);
492 492
493 EXPECT_EQ(&v11, changes[1].view); 493 EXPECT_EQ(&v11, changes[1].view);
494 EXPECT_EQ(&v13, changes[1].relative_view); 494 EXPECT_EQ(&v13, changes[1].relative_view);
495 EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[1].direction); 495 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[1].direction);
496 } 496 }
497 497
498 { 498 {
499 OrderChangeObserver observer(&v11); 499 OrderChangeObserver observer(&v11);
500 500
501 // Move v11 to back. 501 // Move v11 to back.
502 // Resulting order: v11, v12, v13 502 // Resulting order: v11, v12, v13
503 v11.MoveToBack(); 503 v11.MoveToBack();
504 EXPECT_EQ(&v11, v1.children().front()); 504 EXPECT_EQ(&v11, v1.children().front());
505 EXPECT_EQ(&v13, v1.children().back()); 505 EXPECT_EQ(&v13, v1.children().back());
506 506
507 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); 507 OrderChangeObserver::Changes changes = observer.GetAndClearChanges();
508 ASSERT_EQ(2U, changes.size()); 508 ASSERT_EQ(2U, changes.size());
509 EXPECT_EQ(&v11, changes[0].view); 509 EXPECT_EQ(&v11, changes[0].view);
510 EXPECT_EQ(&v12, changes[0].relative_view); 510 EXPECT_EQ(&v12, changes[0].relative_view);
511 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[0].direction); 511 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[0].direction);
512 512
513 EXPECT_EQ(&v11, changes[1].view); 513 EXPECT_EQ(&v11, changes[1].view);
514 EXPECT_EQ(&v12, changes[1].relative_view); 514 EXPECT_EQ(&v12, changes[1].relative_view);
515 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[1].direction); 515 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[1].direction);
516 } 516 }
517 517
518 { 518 {
519 OrderChangeObserver observer(&v11); 519 OrderChangeObserver observer(&v11);
520 520
521 // Move v11 above v12. 521 // Move v11 above v12.
522 // Resulting order: v12. v11, v13 522 // Resulting order: v12. v11, v13
523 v11.Reorder(&v12, ORDER_DIRECTION_ABOVE); 523 v11.Reorder(&v12, mojo::ORDER_DIRECTION_ABOVE);
524 EXPECT_EQ(&v12, v1.children().front()); 524 EXPECT_EQ(&v12, v1.children().front());
525 EXPECT_EQ(&v13, v1.children().back()); 525 EXPECT_EQ(&v13, v1.children().back());
526 526
527 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); 527 OrderChangeObserver::Changes changes = observer.GetAndClearChanges();
528 ASSERT_EQ(2U, changes.size()); 528 ASSERT_EQ(2U, changes.size());
529 EXPECT_EQ(&v11, changes[0].view); 529 EXPECT_EQ(&v11, changes[0].view);
530 EXPECT_EQ(&v12, changes[0].relative_view); 530 EXPECT_EQ(&v12, changes[0].relative_view);
531 EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[0].direction); 531 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[0].direction);
532 532
533 EXPECT_EQ(&v11, changes[1].view); 533 EXPECT_EQ(&v11, changes[1].view);
534 EXPECT_EQ(&v12, changes[1].relative_view); 534 EXPECT_EQ(&v12, changes[1].relative_view);
535 EXPECT_EQ(ORDER_DIRECTION_ABOVE, changes[1].direction); 535 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[1].direction);
536 } 536 }
537 537
538 { 538 {
539 OrderChangeObserver observer(&v11); 539 OrderChangeObserver observer(&v11);
540 540
541 // Move v11 below v12. 541 // Move v11 below v12.
542 // Resulting order: v11, v12, v13 542 // Resulting order: v11, v12, v13
543 v11.Reorder(&v12, ORDER_DIRECTION_BELOW); 543 v11.Reorder(&v12, mojo::ORDER_DIRECTION_BELOW);
544 EXPECT_EQ(&v11, v1.children().front()); 544 EXPECT_EQ(&v11, v1.children().front());
545 EXPECT_EQ(&v13, v1.children().back()); 545 EXPECT_EQ(&v13, v1.children().back());
546 546
547 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); 547 OrderChangeObserver::Changes changes = observer.GetAndClearChanges();
548 ASSERT_EQ(2U, changes.size()); 548 ASSERT_EQ(2U, changes.size());
549 EXPECT_EQ(&v11, changes[0].view); 549 EXPECT_EQ(&v11, changes[0].view);
550 EXPECT_EQ(&v12, changes[0].relative_view); 550 EXPECT_EQ(&v12, changes[0].relative_view);
551 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[0].direction); 551 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[0].direction);
552 552
553 EXPECT_EQ(&v11, changes[1].view); 553 EXPECT_EQ(&v11, changes[1].view);
554 EXPECT_EQ(&v12, changes[1].relative_view); 554 EXPECT_EQ(&v12, changes[1].relative_view);
555 EXPECT_EQ(ORDER_DIRECTION_BELOW, changes[1].direction); 555 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[1].direction);
556 } 556 }
557 } 557 }
558 558
559 namespace { 559 namespace {
560 560
561 typedef std::vector<std::string> Changes; 561 typedef std::vector<std::string> Changes;
562 562
563 std::string ViewIdToString(Id id) { 563 std::string ViewIdToString(Id id) {
564 return (id == 0) ? "null" 564 return (id == 0) ? "null"
565 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); 565 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
566 } 566 }
567 567
568 std::string RectToString(const Rect& rect) { 568 std::string RectToString(const mojo::Rect& rect) {
569 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width, 569 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width,
570 rect.height); 570 rect.height);
571 } 571 }
572 572
573 class BoundsChangeObserver : public ViewObserver { 573 class BoundsChangeObserver : public ViewObserver {
574 public: 574 public:
575 explicit BoundsChangeObserver(View* view) : view_(view) { 575 explicit BoundsChangeObserver(View* view) : view_(view) {
576 view_->AddObserver(this); 576 view_->AddObserver(this);
577 } 577 }
578 ~BoundsChangeObserver() override { view_->RemoveObserver(this); } 578 ~BoundsChangeObserver() override { view_->RemoveObserver(this); }
579 579
580 Changes GetAndClearChanges() { 580 Changes GetAndClearChanges() {
581 Changes changes; 581 Changes changes;
582 changes.swap(changes_); 582 changes.swap(changes_);
583 return changes; 583 return changes;
584 } 584 }
585 585
586 private: 586 private:
587 // Overridden from ViewObserver: 587 // Overridden from ViewObserver:
588 void OnViewBoundsChanging(View* view, 588 void OnViewBoundsChanging(View* view,
589 const Rect& old_bounds, 589 const mojo::Rect& old_bounds,
590 const Rect& new_bounds) override { 590 const mojo::Rect& new_bounds) override {
591 changes_.push_back(base::StringPrintf( 591 changes_.push_back(base::StringPrintf(
592 "view=%s old_bounds=%s new_bounds=%s phase=changing", 592 "view=%s old_bounds=%s new_bounds=%s phase=changing",
593 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(), 593 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(),
594 RectToString(new_bounds).c_str())); 594 RectToString(new_bounds).c_str()));
595 } 595 }
596 void OnViewBoundsChanged(View* view, 596 void OnViewBoundsChanged(View* view,
597 const Rect& old_bounds, 597 const mojo::Rect& old_bounds,
598 const Rect& new_bounds) override { 598 const mojo::Rect& new_bounds) override {
599 changes_.push_back(base::StringPrintf( 599 changes_.push_back(base::StringPrintf(
600 "view=%s old_bounds=%s new_bounds=%s phase=changed", 600 "view=%s old_bounds=%s new_bounds=%s phase=changed",
601 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(), 601 ViewIdToString(view->id()).c_str(), RectToString(old_bounds).c_str(),
602 RectToString(new_bounds).c_str())); 602 RectToString(new_bounds).c_str()));
603 } 603 }
604 604
605 View* view_; 605 View* view_;
606 Changes changes_; 606 Changes changes_;
607 607
608 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver); 608 MOJO_DISALLOW_COPY_AND_ASSIGN(BoundsChangeObserver);
609 }; 609 };
610 610
611 } // namespace 611 } // namespace
612 612
613 TEST_F(ViewObserverTest, SetBounds) { 613 TEST_F(ViewObserverTest, SetBounds) {
614 TestView v1; 614 TestView v1;
615 { 615 {
616 BoundsChangeObserver observer(&v1); 616 BoundsChangeObserver observer(&v1);
617 Rect rect; 617 mojo::Rect rect;
618 rect.width = rect.height = 100; 618 rect.width = rect.height = 100;
619 v1.SetBounds(rect); 619 v1.SetBounds(rect);
620 620
621 Changes changes = observer.GetAndClearChanges(); 621 Changes changes = observer.GetAndClearChanges();
622 ASSERT_EQ(2U, changes.size()); 622 ASSERT_EQ(2U, changes.size());
623 EXPECT_EQ( 623 EXPECT_EQ(
624 "view=0,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100 phase=changing", 624 "view=0,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100 phase=changing",
625 changes[0]); 625 changes[0]);
626 EXPECT_EQ( 626 EXPECT_EQ(
627 "view=0,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100 phase=changed", 627 "view=0,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100 phase=changed",
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 v1.SetLocalProperty(&prop, 3); 864 v1.SetLocalProperty(&prop, 3);
865 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); 865 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear());
866 v1.ClearLocalProperty(&prop); 866 v1.ClearLocalProperty(&prop);
867 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); 867 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear());
868 868
869 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. 869 // Sanity check to see if |PropertyChangeInfoAndClear| really clears.
870 EXPECT_EQ(PropertyChangeInfo(reinterpret_cast<const void*>(NULL), -3), 870 EXPECT_EQ(PropertyChangeInfo(reinterpret_cast<const void*>(NULL), -3),
871 o.PropertyChangeInfoAndClear()); 871 o.PropertyChangeInfoAndClear());
872 } 872 }
873 873
874 } // namespace mojo 874 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/tests/view_manager_test_suite.cc ('k') | components/mus/public/cpp/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698