OLD | NEW |
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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 WaitForOrderChange(window_manager(), | 521 WaitForOrderChange(window_manager(), |
522 window_manager()->GetViewById(view11->id())); | 522 window_manager()->GetViewById(view11->id())); |
523 | 523 |
524 EXPECT_EQ(view1_in_wm->children().front(), | 524 EXPECT_EQ(view1_in_wm->children().front(), |
525 window_manager()->GetViewById(view11->id())); | 525 window_manager()->GetViewById(view11->id())); |
526 EXPECT_EQ(view1_in_wm->children().back(), | 526 EXPECT_EQ(view1_in_wm->children().back(), |
527 window_manager()->GetViewById(view12->id())); | 527 window_manager()->GetViewById(view12->id())); |
528 } | 528 } |
529 } | 529 } |
530 | 530 |
| 531 namespace { |
| 532 |
| 533 class VisibilityChangeObserver : public ViewObserver { |
| 534 public: |
| 535 explicit VisibilityChangeObserver(View* view) : view_(view) { |
| 536 view_->AddObserver(this); |
| 537 } |
| 538 virtual ~VisibilityChangeObserver() { view_->RemoveObserver(this); } |
| 539 |
| 540 private: |
| 541 // Overridden from ViewObserver: |
| 542 virtual void OnViewVisibilityChanged(View* view) OVERRIDE { |
| 543 EXPECT_EQ(view, view_); |
| 544 QuitRunLoop(); |
| 545 } |
| 546 |
| 547 View* view_; |
| 548 |
| 549 DISALLOW_COPY_AND_ASSIGN(VisibilityChangeObserver); |
| 550 }; |
| 551 |
| 552 } // namespace |
| 553 |
| 554 TEST_F(ViewManagerTest, DISABLED_Visible) { |
| 555 View* view1 = View::Create(window_manager()); |
| 556 window_manager()->GetRoots().front()->AddChild(view1); |
| 557 |
| 558 // Embed another app and verify initial state. |
| 559 ViewManager* embedded = Embed(window_manager(), view1); |
| 560 ASSERT_EQ(1u, embedded->GetRoots().size()); |
| 561 View* embedded_root = embedded->GetRoots().front(); |
| 562 EXPECT_TRUE(embedded_root->visible()); |
| 563 EXPECT_TRUE(embedded_root->IsDrawn()); |
| 564 |
| 565 // Change the visible state from the first connection and verify its mirrored |
| 566 // correctly to the embedded app. |
| 567 { |
| 568 VisibilityChangeObserver observer(embedded_root); |
| 569 view1->SetVisible(false); |
| 570 DoRunLoop(); |
| 571 } |
| 572 |
| 573 EXPECT_FALSE(view1->visible()); |
| 574 EXPECT_FALSE(view1->IsDrawn()); |
| 575 |
| 576 EXPECT_FALSE(embedded_root->visible()); |
| 577 EXPECT_FALSE(embedded_root->IsDrawn()); |
| 578 |
| 579 // Make the node visible again. |
| 580 { |
| 581 VisibilityChangeObserver observer(embedded_root); |
| 582 view1->SetVisible(true); |
| 583 DoRunLoop(); |
| 584 } |
| 585 |
| 586 EXPECT_TRUE(view1->visible()); |
| 587 EXPECT_TRUE(view1->IsDrawn()); |
| 588 |
| 589 EXPECT_TRUE(embedded_root->visible()); |
| 590 EXPECT_TRUE(embedded_root->IsDrawn()); |
| 591 } |
| 592 |
| 593 namespace { |
| 594 |
| 595 class DrawnChangeObserver : public ViewObserver { |
| 596 public: |
| 597 explicit DrawnChangeObserver(View* view) : view_(view) { |
| 598 view_->AddObserver(this); |
| 599 } |
| 600 virtual ~DrawnChangeObserver() { view_->RemoveObserver(this); } |
| 601 |
| 602 private: |
| 603 // Overridden from ViewObserver: |
| 604 virtual void OnViewDrawnChanged(View* view) OVERRIDE { |
| 605 EXPECT_EQ(view, view_); |
| 606 QuitRunLoop(); |
| 607 } |
| 608 |
| 609 View* view_; |
| 610 |
| 611 DISALLOW_COPY_AND_ASSIGN(DrawnChangeObserver); |
| 612 }; |
| 613 |
| 614 } // namespace |
| 615 |
| 616 TEST_F(ViewManagerTest, DISABLED_Drawn) { |
| 617 View* view1 = View::Create(window_manager()); |
| 618 window_manager()->GetRoots().front()->AddChild(view1); |
| 619 |
| 620 // Embed another app and verify initial state. |
| 621 ViewManager* embedded = Embed(window_manager(), view1); |
| 622 ASSERT_EQ(1u, embedded->GetRoots().size()); |
| 623 View* embedded_root = embedded->GetRoots().front(); |
| 624 EXPECT_TRUE(embedded_root->visible()); |
| 625 EXPECT_TRUE(embedded_root->IsDrawn()); |
| 626 |
| 627 // Change the visibility of the root, this should propagate a drawn state |
| 628 // change to |embedded|. |
| 629 { |
| 630 DrawnChangeObserver observer(embedded_root); |
| 631 window_manager()->GetRoots().front()->SetVisible(false); |
| 632 DoRunLoop(); |
| 633 } |
| 634 |
| 635 EXPECT_TRUE(view1->visible()); |
| 636 EXPECT_FALSE(view1->IsDrawn()); |
| 637 |
| 638 EXPECT_TRUE(embedded_root->visible()); |
| 639 EXPECT_FALSE(embedded_root->IsDrawn()); |
| 640 } |
| 641 |
531 // TODO(beng): tests for view event dispatcher. | 642 // TODO(beng): tests for view event dispatcher. |
532 // - verify that we see events for all views. | 643 // - verify that we see events for all views. |
533 | 644 |
534 // TODO(beng): tests for focus: | 645 // TODO(beng): tests for focus: |
535 // - focus between two views known to a connection | 646 // - focus between two views known to a connection |
536 // - focus between views unknown to one of the connections. | 647 // - focus between views unknown to one of the connections. |
537 // - focus between views unknown to either connection. | 648 // - focus between views unknown to either connection. |
538 | 649 |
539 } // namespace mojo | 650 } // namespace mojo |
OLD | NEW |