| 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/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 count += CountNodes(*it); | 167 count += CountNodes(*it); |
| 168 return count; | 168 return count; |
| 169 } | 169 } |
| 170 | 170 |
| 171 Node* tree_; | 171 Node* tree_; |
| 172 size_t tree_size_; | 172 size_t tree_size_; |
| 173 | 173 |
| 174 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); | 174 DISALLOW_COPY_AND_ASSIGN(TreeSizeMatchesObserver); |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 void WaitForTreeSizeToMatch(Node* node, size_t tree_size) { |
| 178 TreeSizeMatchesObserver observer(node, tree_size); |
| 179 if (observer.IsTreeCorrectSize()) |
| 180 return; |
| 181 node->AddObserver(&observer); |
| 182 DoRunLoop(); |
| 183 node->RemoveObserver(&observer); |
| 184 } |
| 185 |
| 177 // Utility class that waits for the destruction of some number of nodes and | 186 // Utility class that waits for the destruction of some number of nodes and |
| 178 // views. | 187 // views. |
| 179 class DestructionObserver : public NodeObserver, public ViewObserver { | 188 class DestructionObserver : public NodeObserver, public ViewObserver { |
| 180 public: | 189 public: |
| 181 // |nodes| or |views| can be NULL. | 190 // |nodes| or |views| can be NULL. |
| 182 DestructionObserver(std::set<Id>* nodes, std::set<Id>* views) | 191 DestructionObserver(std::set<Id>* nodes, std::set<Id>* views) |
| 183 : nodes_(nodes), | 192 : nodes_(nodes), |
| 184 views_(views) {} | 193 views_(views) {} |
| 185 | 194 |
| 186 private: | 195 private: |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 Node* node = Node::Create(window_manager()); | 628 Node* node = Node::Create(window_manager()); |
| 620 window_manager()->GetRoots().front()->AddChild(node); | 629 window_manager()->GetRoots().front()->AddChild(node); |
| 621 ViewManager* embedded = Embed(window_manager(), node); | 630 ViewManager* embedded = Embed(window_manager(), node); |
| 622 EXPECT_EQ(kWindowManagerURL, embedded->GetEmbedderURL()); | 631 EXPECT_EQ(kWindowManagerURL, embedded->GetEmbedderURL()); |
| 623 } | 632 } |
| 624 | 633 |
| 625 TEST_F(ViewManagerTest, Reorder) { | 634 TEST_F(ViewManagerTest, Reorder) { |
| 626 Node* node1 = Node::Create(window_manager()); | 635 Node* node1 = Node::Create(window_manager()); |
| 627 window_manager()->GetRoots().front()->AddChild(node1); | 636 window_manager()->GetRoots().front()->AddChild(node1); |
| 628 | 637 |
| 629 Node* node11 = Node::Create(window_manager()); | |
| 630 node1->AddChild(node11); | |
| 631 Node* node12 = Node::Create(window_manager()); | |
| 632 node1->AddChild(node12); | |
| 633 | |
| 634 ViewManager* embedded = Embed(window_manager(), node1); | 638 ViewManager* embedded = Embed(window_manager(), node1); |
| 635 | 639 |
| 636 Node* node1_in_embedded = embedded->GetNodeById(node1->id()); | 640 Node* node11 = Node::Create(embedded); |
| 641 embedded->GetRoots().front()->AddChild(node11); |
| 642 Node* node12 = Node::Create(embedded); |
| 643 embedded->GetRoots().front()->AddChild(node12); |
| 644 |
| 645 Node* node1_in_wm = window_manager()->GetNodeById(node1->id()); |
| 637 | 646 |
| 638 { | 647 { |
| 648 WaitForTreeSizeToMatch(node1, 2u); |
| 639 node11->MoveToFront(); | 649 node11->MoveToFront(); |
| 640 WaitForOrderChange(embedded, embedded->GetNodeById(node11->id())); | 650 WaitForOrderChange(window_manager(), |
| 651 window_manager()->GetNodeById(node11->id())); |
| 641 | 652 |
| 642 EXPECT_EQ(node1_in_embedded->children().front(), | 653 EXPECT_EQ(node1_in_wm->children().front(), |
| 643 embedded->GetNodeById(node12->id())); | 654 window_manager()->GetNodeById(node12->id())); |
| 644 EXPECT_EQ(node1_in_embedded->children().back(), | 655 EXPECT_EQ(node1_in_wm->children().back(), |
| 645 embedded->GetNodeById(node11->id())); | 656 window_manager()->GetNodeById(node11->id())); |
| 646 } | 657 } |
| 647 | 658 |
| 648 { | 659 { |
| 649 node11->MoveToBack(); | 660 node11->MoveToBack(); |
| 650 WaitForOrderChange(embedded, embedded->GetNodeById(node11->id())); | 661 WaitForOrderChange(window_manager(), |
| 662 window_manager()->GetNodeById(node11->id())); |
| 651 | 663 |
| 652 EXPECT_EQ(node1_in_embedded->children().front(), | 664 EXPECT_EQ(node1_in_wm->children().front(), |
| 653 embedded->GetNodeById(node11->id())); | 665 window_manager()->GetNodeById(node11->id())); |
| 654 EXPECT_EQ(node1_in_embedded->children().back(), | 666 EXPECT_EQ(node1_in_wm->children().back(), |
| 655 embedded->GetNodeById(node12->id())); | 667 window_manager()->GetNodeById(node12->id())); |
| 656 } | 668 } |
| 657 } | 669 } |
| 658 | 670 |
| 659 // TODO(beng): tests for view event dispatcher. | 671 // TODO(beng): tests for view event dispatcher. |
| 660 // - verify that we see events for all views. | 672 // - verify that we see events for all views. |
| 661 | 673 |
| 662 // TODO(beng): tests for focus: | 674 // TODO(beng): tests for focus: |
| 663 // - focus between two nodes known to a connection | 675 // - focus between two nodes known to a connection |
| 664 // - focus between nodes unknown to one of the connections. | 676 // - focus between nodes unknown to one of the connections. |
| 665 // - focus between nodes unknown to either connection. | 677 // - focus between nodes unknown to either connection. |
| 666 | 678 |
| 667 } // namespace mojo | 679 } // namespace mojo |
| OLD | NEW |