| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
| 6 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h" |
| 7 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 8 #include "ui/views/widget/widget.h" |
| 9 #include "ui/views/widget/widget_observer.h" |
| 10 |
| 11 class ExclusiveAccessBubbleViewsTest : public FullscreenControllerTest, |
| 12 public views::WidgetObserver { |
| 13 public: |
| 14 ExclusiveAccessBubbleViewsTest() {} |
| 15 |
| 16 ExclusiveAccessBubbleViews* bubble() { |
| 17 BrowserView* browser_view = |
| 18 BrowserView::GetBrowserViewForBrowser(browser()); |
| 19 return browser_view->exclusive_access_bubble(); |
| 20 } |
| 21 |
| 22 // WidgetObserver: |
| 23 void OnWidgetDestroying(views::Widget* widget) override { |
| 24 was_observing_in_destroying_ = widget->HasObserver(bubble()); |
| 25 was_destroying_ = true; |
| 26 widget->RemoveObserver(this); |
| 27 } |
| 28 |
| 29 protected: |
| 30 bool was_destroying_ = false; |
| 31 bool was_observing_in_destroying_ = false; |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessBubbleViewsTest); |
| 35 }; |
| 36 |
| 37 // Simulate obscure codepaths resulting in the bubble Widget being closed before |
| 38 // the ExclusiveAccessBubbleViews destructor asks for it. If a close bypasses |
| 39 // the destructor, animations could still be running that attempt to manipulate |
| 40 // a destroyed Widget and crash. |
| 41 IN_PROC_BROWSER_TEST_F(ExclusiveAccessBubbleViewsTest, NativeClose) { |
| 42 EXPECT_FALSE(bubble()); |
| 43 EnterActiveTabFullscreen(); |
| 44 EXPECT_TRUE(bubble()); |
| 45 |
| 46 bubble()->GetView()->GetWidget()->AddObserver(this); |
| 47 |
| 48 // Simulate the bubble being closed out from under its controller, which seems |
| 49 // to happen in some odd corner cases, like system log-off while the bubble is |
| 50 // showing. |
| 51 bubble()->GetView()->GetWidget()->CloseNow(); |
| 52 EXPECT_FALSE(bubble()); |
| 53 |
| 54 // Verify that teardown is really happening via OnWidgetDestroyed() rather |
| 55 // than the usual path via the ExclusiveAccessBubbleViews destructor. Since |
| 56 // the destructor always first removes ExclusiveAccessBubbleViews as an |
| 57 // observer before starting the close, checking in OnWidgetDestroyed that it's |
| 58 // still observing achieves this. |
| 59 EXPECT_TRUE(was_observing_in_destroying_); |
| 60 EXPECT_TRUE(was_destroying_); |
| 61 } |
| OLD | NEW |