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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/view_unittest.cc
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 6013c84b2bc5def66ad445a9a1cde0dce3044b8d..7567394429b0e4468984ae055adb9ec34ea22951 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -4618,6 +4618,63 @@ TEST_F(ViewTest, CrashOnAddFromFromOnNativeThemeChanged) {
EXPECT_TRUE(v->on_native_theme_changed_called());
}
+// A View that removes its Layer when hidden.
+class NoLayerWhenHiddenView : public View {
+ public:
+ NoLayerWhenHiddenView() {
+ SetPaintToLayer(true);
+ set_owned_by_client();
+ SetBounds(0, 0, 100, 100);
+ }
+
+ bool was_hidden() const { return was_hidden_; }
+
+ // View:
+ void VisibilityChanged(View* starting_from, bool is_visible) override {
+ if (!is_visible) {
+ was_hidden_ = true;
+ SetPaintToLayer(false);
+ }
+ }
+
+ private:
+ bool was_hidden_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(NoLayerWhenHiddenView);
+};
+
+// Test that Views can safely manipulate Layers during Widget closure.
+TEST_F(ViewTest, DestroyLayerInClose) {
+ NoLayerWhenHiddenView view;
+ Widget* widget = new Widget;
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
+ widget->Init(params);
+ widget->SetBounds(gfx::Rect(0, 0, 100, 100));
+ widget->GetContentsView()->AddChildView(&view);
+ widget->Show();
+
+ EXPECT_TRUE(view.layer());
+ EXPECT_TRUE(view.GetWidget());
+ EXPECT_FALSE(view.was_hidden());
+
+ widget->Close();
+ if (IsAuraMusClient()) {
+ // Mus on Ozone doesn't send the visibility change during Close().
+ // See http://crbug.com/674003.
+ EXPECT_TRUE(view.layer());
+ EXPECT_FALSE(view.was_hidden());
+ } else {
+ EXPECT_FALSE(view.layer());
+ // Ensure the layer went away via VisibilityChanged().
+ EXPECT_TRUE(view.was_hidden());
+ }
+
+ // Not removed from Widget until Close() completes.
+ EXPECT_TRUE(view.GetWidget());
+ base::RunLoop().RunUntilIdle(); // Let the Close() complete.
+ EXPECT_FALSE(view.GetWidget());
+}
+
////////////////////////////////////////////////////////////////////////////////
// Observer tests.
////////////////////////////////////////////////////////////////////////////////
« 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