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

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

Issue 2577593002: MacViews: Be robust against Views manipulating Layers during Widget::Close(). (Closed)
Patch Set: selfnits Created 4 years 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/cocoa/bridged_native_widget.mm ('k') | ui/views/widget/native_widget_mac.mm » ('j') | 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 4600 matching lines...) Expand 10 before | Expand all | Expand 10 after
4611 params.bounds = gfx::Rect(50, 50, 350, 350); 4611 params.bounds = gfx::Rect(50, 50, 350, 350);
4612 widget.Init(params); 4612 widget.Init(params);
4613 4613
4614 AddViewWithChildLayer(widget.GetRootView()); 4614 AddViewWithChildLayer(widget.GetRootView());
4615 ViewThatAddsViewInOnNativeThemeChanged* v = 4615 ViewThatAddsViewInOnNativeThemeChanged* v =
4616 new ViewThatAddsViewInOnNativeThemeChanged; 4616 new ViewThatAddsViewInOnNativeThemeChanged;
4617 widget.GetRootView()->AddChildView(v); 4617 widget.GetRootView()->AddChildView(v);
4618 EXPECT_TRUE(v->on_native_theme_changed_called()); 4618 EXPECT_TRUE(v->on_native_theme_changed_called());
4619 } 4619 }
4620 4620
4621 // A View that removes its Layer when hidden.
4622 class NoLayerWhenHiddenView : public View {
4623 public:
4624 NoLayerWhenHiddenView() {
4625 SetPaintToLayer(true);
4626 set_owned_by_client();
4627 SetBounds(0, 0, 100, 100);
4628 }
4629
4630 bool was_hidden() const { return was_hidden_; }
4631
4632 // View:
4633 void VisibilityChanged(View* starting_from, bool is_visible) override {
4634 if (!is_visible) {
4635 was_hidden_ = true;
4636 SetPaintToLayer(false);
4637 }
4638 }
4639
4640 private:
4641 bool was_hidden_ = false;
4642
4643 DISALLOW_COPY_AND_ASSIGN(NoLayerWhenHiddenView);
4644 };
4645
4646 // Test that Views can safely manipulate Layers during Widget closure.
4647 TEST_F(ViewTest, DestroyLayerInClose) {
4648 NoLayerWhenHiddenView view;
4649 Widget* widget = new Widget;
4650 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
4651 widget->Init(params);
4652 widget->SetBounds(gfx::Rect(0, 0, 100, 100));
4653 widget->GetContentsView()->AddChildView(&view);
4654 widget->Show();
4655
4656 EXPECT_TRUE(view.layer());
4657 EXPECT_TRUE(view.GetWidget());
4658 EXPECT_FALSE(view.was_hidden());
4659
4660 widget->Close();
4661 if (IsAuraMusClient()) {
4662 // Mus on Ozone doesn't send the visibility change during Close().
4663 // See http://crbug.com/674003.
4664 EXPECT_TRUE(view.layer());
4665 EXPECT_FALSE(view.was_hidden());
4666 } else {
4667 EXPECT_FALSE(view.layer());
4668 // Ensure the layer went away via VisibilityChanged().
4669 EXPECT_TRUE(view.was_hidden());
4670 }
4671
4672 // Not removed from Widget until Close() completes.
4673 EXPECT_TRUE(view.GetWidget());
4674 base::RunLoop().RunUntilIdle(); // Let the Close() complete.
4675 EXPECT_FALSE(view.GetWidget());
4676 }
4677
4621 //////////////////////////////////////////////////////////////////////////////// 4678 ////////////////////////////////////////////////////////////////////////////////
4622 // Observer tests. 4679 // Observer tests.
4623 //////////////////////////////////////////////////////////////////////////////// 4680 ////////////////////////////////////////////////////////////////////////////////
4624 4681
4625 class ViewObserverTest : public ViewTest, public ViewObserver { 4682 class ViewObserverTest : public ViewTest, public ViewObserver {
4626 public: 4683 public:
4627 ViewObserverTest() 4684 ViewObserverTest()
4628 : child_view_added_times_(0), 4685 : child_view_added_times_(0),
4629 child_view_removed_times_(0), 4686 child_view_removed_times_(0),
4630 child_view_added_(nullptr), 4687 child_view_added_(nullptr),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4770 std::unique_ptr<View> view = NewView(); 4827 std::unique_ptr<View> view = NewView();
4771 std::unique_ptr<View> child_view = NewView(); 4828 std::unique_ptr<View> child_view = NewView();
4772 std::unique_ptr<View> child_view2 = NewView(); 4829 std::unique_ptr<View> child_view2 = NewView();
4773 view->AddChildView(child_view.get()); 4830 view->AddChildView(child_view.get());
4774 view->AddChildView(child_view2.get()); 4831 view->AddChildView(child_view2.get());
4775 view->ReorderChildView(child_view2.get(), 0); 4832 view->ReorderChildView(child_view2.get(), 0);
4776 EXPECT_EQ(child_view2.get(), view_reordered()); 4833 EXPECT_EQ(child_view2.get(), view_reordered());
4777 } 4834 }
4778 4835
4779 } // namespace views 4836 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.mm ('k') | ui/views/widget/native_widget_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698