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

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

Issue 2813353002: Ensure that the focus ring in the bookmarks bar does not paint outside the parent view. (Closed)
Patch Set: \ Created 3 years, 8 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.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 5005 matching lines...) Expand 10 before | Expand all | Expand 10 after
5016 TEST_F(ViewObserverTest, ChildViewReordered) { 5016 TEST_F(ViewObserverTest, ChildViewReordered) {
5017 std::unique_ptr<View> view = NewView(); 5017 std::unique_ptr<View> view = NewView();
5018 std::unique_ptr<View> child_view = NewView(); 5018 std::unique_ptr<View> child_view = NewView();
5019 std::unique_ptr<View> child_view2 = NewView(); 5019 std::unique_ptr<View> child_view2 = NewView();
5020 view->AddChildView(child_view.get()); 5020 view->AddChildView(child_view.get());
5021 view->AddChildView(child_view2.get()); 5021 view->AddChildView(child_view2.get());
5022 view->ReorderChildView(child_view2.get(), 0); 5022 view->ReorderChildView(child_view2.get(), 0);
5023 EXPECT_EQ(child_view2.get(), view_reordered()); 5023 EXPECT_EQ(child_view2.get(), view_reordered());
5024 } 5024 }
5025 5025
5026 // Validates that if a child of a ScrollView adds a layer, then a layer
5027 // is added to the ScrollView's viewport.
5028 TEST_F(ViewObserverTest, ScrollViewChildAddLayerTest) {
5029 std::unique_ptr<ScrollView> scroll_view(new ScrollView());
5030 scroll_view->SetContents(new View());
5031 // Bail if the scroll view already has a layer.
5032 if (scroll_view->contents_viewport_->layer())
5033 return;
5034
5035 EXPECT_FALSE(scroll_view->contents_viewport_->layer());
5036
5037 std::unique_ptr<View> child_view = NewView();
5038 scroll_view->AddChildView(child_view.get());
5039 child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
5040
5041 EXPECT_TRUE(scroll_view->contents_viewport_->layer());
5042 scroll_view->RemoveChildView(child_view.get());
5043 }
5044
5045 // Provides a simple parent view implementation which tracks layer change
5046 // notifications from child views.
5047 class TestParentView : public View {
5048 public:
5049 TestParentView()
5050 : received_layer_change_notification_(false), layer_change_count_(0) {}
5051
5052 void Reset() {
5053 received_layer_change_notification_ = false;
5054 layer_change_count_ = 0;
5055 }
5056
5057 bool received_layer_change_notification() const {
5058 return received_layer_change_notification_;
5059 }
5060
5061 int layer_change_count() const { return layer_change_count_; }
5062
5063 // View overrides.
5064 void OnChildLayerChanged(View* child) override {
5065 received_layer_change_notification_ = true;
5066 layer_change_count_++;
5067 }
5068
5069 private:
5070 // Set to true if we receive the OnChildLayerChanged() notification for a
5071 // child.
5072 bool received_layer_change_notification_;
5073
5074 // Contains the number of OnChildLayerChanged() notifications for a child.
5075 int layer_change_count_;
5076
5077 DISALLOW_COPY_AND_ASSIGN(TestParentView);
5078 };
5079
5080 // Tests the following cases.
5081 // 1. We receive the OnChildLayerChanged() notification when a layer change
5082 // occurs in a child view.
5083 // 2. We don't receive two layer changes when a child with an existing layer
5084 // creates a new layer.
5085 TEST_F(ViewObserverTest, ChildViewLayerNotificationTest) {
5086 std::unique_ptr<TestParentView> parent_view(new TestParentView);
5087 std::unique_ptr<View> child_view = NewView();
5088 parent_view->AddChildView(child_view.get());
5089
5090 EXPECT_FALSE(parent_view->received_layer_change_notification());
5091 EXPECT_EQ(0, parent_view->layer_change_count());
5092
5093 child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
5094 EXPECT_TRUE(parent_view->received_layer_change_notification());
5095 EXPECT_EQ(1, parent_view->layer_change_count());
5096
5097 parent_view->Reset();
5098 child_view->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
5099 EXPECT_TRUE(parent_view->received_layer_change_notification());
5100 EXPECT_EQ(1, parent_view->layer_change_count());
5101 }
5102
5026 } // namespace views 5103 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698