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

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: Fix test 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
« ui/views/view.h ('K') | « 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 // Remove this ifdef once AURA is enabled for MAC.
5027 #if !defined(OS_MACOSX)
sky 2017/04/18 23:02:21 I don't think you need the ifdef, instead early ou
5028 // Validates that if a child of a ScrollView adds a layer, then a layer
5029 // is added to the ScrollView's viewport.
5030 TEST_F(ViewObserverTest, ScrollViewChildAddLayerTest) {
5031 std::unique_ptr<ScrollView> scroll_view(new ScrollView());
5032 scroll_view->SetContents(new View());
5033 EXPECT_FALSE(scroll_view->contents_viewport_->layer());
5034
5035 std::unique_ptr<View> child_view = NewView();
5036 scroll_view->AddChildView(child_view.get());
5037 child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
5038
5039 EXPECT_TRUE(scroll_view->contents_viewport_->layer());
5040 scroll_view->RemoveChildView(child_view.get());
5041 }
5042
5043 // Provides a simple parent view implementation which tracks layer change
5044 // notifications from child views.
5045 class TestParentView : public View {
5046 public:
5047 TestParentView()
5048 : View(),
sky 2017/04/18 23:02:21 This line isn't necessary.
ananta 2017/04/18 23:14:46 Done.
5049 received_layer_change_notification_(false),
5050 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 };
sky 2017/04/18 23:02:21 DISALLOW...
ananta 2017/04/18 23:14:46 Done.
5077
5078 // Tests the following cases.
5079 // 1. We receive the OnChildLayerChanged() notification when a layer change
5080 // occurs in a child view.
5081 // 2. We don't receive two layer changes when a child with an existing layer
5082 // creates a new layer.
5083 TEST_F(ViewObserverTest, ChildViewLayerNotificationTest) {
5084 std::unique_ptr<TestParentView> parent_view(new TestParentView);
5085 std::unique_ptr<View> child_view = NewView();
5086 parent_view->AddChildView(child_view.get());
5087
5088 EXPECT_FALSE(parent_view->received_layer_change_notification());
5089 EXPECT_EQ(parent_view->layer_change_count(), 0);
sky 2017/04/18 23:02:21 Generally we go with expected, actual, e.g. EXPECT
ananta 2017/04/18 23:14:46 Done.
5090
5091 child_view->SetPaintToLayer(ui::LAYER_TEXTURED);
5092 EXPECT_TRUE(parent_view->received_layer_change_notification());
5093 EXPECT_EQ(parent_view->layer_change_count(), 1);
5094
5095 parent_view->Reset();
5096 child_view->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
5097 EXPECT_TRUE(parent_view->received_layer_change_notification());
5098 EXPECT_EQ(parent_view->layer_change_count(), 1);
5099 }
5100
5101 #endif // OS_MACOSX
5102
5026 } // namespace views 5103 } // namespace views
OLDNEW
« ui/views/view.h ('K') | « ui/views/view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698