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

Side by Side Diff: ui/views/view_unittest.cc

Issue 2561253002: [ash-md] Adds support for Z-order iteration in views::View (Closed)
Patch Set: [ash-md] Adds support for Z-order iteration in views::View (rebased) Created 3 years, 11 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
« no previous file with comments | « ui/views/view_targeter_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/view.h" 5 #include "ui/views/view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 4651 matching lines...) Expand 10 before | Expand all | Expand 10 after
4662 EXPECT_FALSE(view.layer()); 4662 EXPECT_FALSE(view.layer());
4663 // Ensure the layer went away via VisibilityChanged(). 4663 // Ensure the layer went away via VisibilityChanged().
4664 EXPECT_TRUE(view.was_hidden()); 4664 EXPECT_TRUE(view.was_hidden());
4665 4665
4666 // Not removed from Widget until Close() completes. 4666 // Not removed from Widget until Close() completes.
4667 EXPECT_TRUE(view.GetWidget()); 4667 EXPECT_TRUE(view.GetWidget());
4668 base::RunLoop().RunUntilIdle(); // Let the Close() complete. 4668 base::RunLoop().RunUntilIdle(); // Let the Close() complete.
4669 EXPECT_FALSE(view.GetWidget()); 4669 EXPECT_FALSE(view.GetWidget());
4670 } 4670 }
4671 4671
4672 // A View that keeps the children with a special ID above other children.
4673 class OrderableView : public View {
4674 public:
4675 static const int VIEW_ID_RAISED = 1000;
sky 2017/01/03 21:46:36 constexpr and a description.
varkha 2017/01/03 22:21:35 Done.
4676
4677 OrderableView() : View() {}
4678 ~OrderableView() override {}
4679
4680 View::Views GetChildrenInZOrder() override {
4681 View::Views children;
4682 // Iterate over regular children and later over the raised children to
4683 // create a custom Z-order.
4684 for (int i = 0; i < child_count(); ++i) {
4685 if (child_at(i)->id() != VIEW_ID_RAISED)
4686 children.push_back(child_at(i));
4687 }
4688 for (int i = 0; i < child_count(); ++i) {
4689 if (child_at(i)->id() == VIEW_ID_RAISED)
4690 children.push_back(child_at(i));
4691 }
4692 DCHECK_EQ(child_count(), static_cast<int>(children.size()));
4693 return children;
4694 }
4695
4696 private:
4697 DISALLOW_COPY_AND_ASSIGN(OrderableView);
4698 };
4699
4700 TEST_F(ViewTest, ChildViewZOrderChanged) {
4701 const int kChildrenCount = 4;
4702 std::unique_ptr<View> view(new OrderableView());
4703 view->SetPaintToLayer(true);
4704 for (int i = 0; i < kChildrenCount; ++i)
4705 AddViewWithChildLayer(view.get());
4706 View::Views children = view->GetChildrenInZOrder();
4707 const std::vector<ui::Layer*>& layers = view->layer()->children();
4708 EXPECT_EQ(kChildrenCount, static_cast<int>(layers.size()));
4709 EXPECT_EQ(kChildrenCount, static_cast<int>(children.size()));
4710 for (int i = 0; i < kChildrenCount; ++i) {
4711 EXPECT_EQ(view->child_at(i)->layer(), layers[i]);
4712 EXPECT_EQ(view->child_at(i), children[i]);
4713 }
4714
4715 // Raise one of the children in z-order and add another child to reorder.
4716 view->child_at(2)->set_id(OrderableView::VIEW_ID_RAISED);
4717 AddViewWithChildLayer(view.get());
4718
4719 // 2nd child should be now on top, i.e. the last element in the array returned
4720 // by GetChildrenInZOrder(). Its layer should also be above the others.
4721 // The rest of the children and layers order should be unchanged.
4722 const int expected_order[] = {0, 1, 3, 4, 2};
4723 children = view->GetChildrenInZOrder();
4724 EXPECT_EQ(kChildrenCount + 1, static_cast<int>(children.size()));
4725 EXPECT_EQ(kChildrenCount + 1, static_cast<int>(layers.size()));
4726 for (size_t i = 0; i < kChildrenCount + 1; ++i) {
4727 EXPECT_EQ(view->child_at(expected_order[i]), children[i]);
4728 EXPECT_EQ(view->child_at(expected_order[i])->layer(), layers[i]);
4729 }
4730 }
4731
4672 //////////////////////////////////////////////////////////////////////////////// 4732 ////////////////////////////////////////////////////////////////////////////////
4673 // Observer tests. 4733 // Observer tests.
4674 //////////////////////////////////////////////////////////////////////////////// 4734 ////////////////////////////////////////////////////////////////////////////////
4675 4735
4676 class ViewObserverTest : public ViewTest, public ViewObserver { 4736 class ViewObserverTest : public ViewTest, public ViewObserver {
4677 public: 4737 public:
4678 ViewObserverTest() 4738 ViewObserverTest()
4679 : child_view_added_times_(0), 4739 : child_view_added_times_(0),
4680 child_view_removed_times_(0), 4740 child_view_removed_times_(0),
4681 child_view_added_(nullptr), 4741 child_view_added_(nullptr),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4821 std::unique_ptr<View> view = NewView(); 4881 std::unique_ptr<View> view = NewView();
4822 std::unique_ptr<View> child_view = NewView(); 4882 std::unique_ptr<View> child_view = NewView();
4823 std::unique_ptr<View> child_view2 = NewView(); 4883 std::unique_ptr<View> child_view2 = NewView();
4824 view->AddChildView(child_view.get()); 4884 view->AddChildView(child_view.get());
4825 view->AddChildView(child_view2.get()); 4885 view->AddChildView(child_view2.get());
4826 view->ReorderChildView(child_view2.get(), 0); 4886 view->ReorderChildView(child_view2.get(), 0);
4827 EXPECT_EQ(child_view2.get(), view_reordered()); 4887 EXPECT_EQ(child_view2.get(), view_reordered());
4828 } 4888 }
4829 4889
4830 } // namespace views 4890 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view_targeter_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698