Chromium Code Reviews| 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 } | |
| 27 void OnWidgetDestroyed(views::Widget* widget) override { | |
| 28 widget->RemoveObserver(this); | |
|
msw
2017/05/03 18:48:33
optional nit: move this into OnWidgetDestroying?
tapted
2017/05/04 06:42:08
Done.
| |
| 29 } | |
| 30 | |
| 31 protected: | |
| 32 bool was_destroying_ = false; | |
| 33 bool was_observing_in_destroying_ = false; | |
| 34 | |
| 35 private: | |
| 36 DISALLOW_COPY_AND_ASSIGN(ExclusiveAccessBubbleViewsTest); | |
| 37 }; | |
| 38 | |
| 39 // Simulate obscure codepaths resulting in the bubble Widget being Closed before | |
|
msw
2017/05/03 18:48:34
nit: "closed"?
tapted
2017/05/04 06:42:08
Done.
| |
| 40 // the ExclusiveAccessBubbleViews destructor will tear down the bubble and any | |
|
msw
2017/05/03 18:48:34
nit: this sentence is a bit run-on and could be cl
tapted
2017/05/04 06:42:07
Done.
| |
| 41 // running animations that could trigger crashes. | |
| 42 IN_PROC_BROWSER_TEST_F(ExclusiveAccessBubbleViewsTest, NativeClose) { | |
|
msw
2017/05/03 18:48:34
nit: maybe make a test for the normal close codepa
tapted
2017/05/04 06:42:07
Yup - most of the tests in FullscreenControllerInt
| |
| 43 EXPECT_FALSE(bubble()); | |
| 44 EnterActiveTabFullscreen(); | |
| 45 EXPECT_TRUE(bubble()); | |
| 46 | |
| 47 bubble()->GetView()->GetWidget()->AddObserver(this); | |
| 48 | |
| 49 // It's hard to nail down a codepath that results in the bubble Widget being | |
|
msw
2017/05/03 18:48:34
Maybe this comment should just say "Simulate the b
tapted
2017/05/04 06:42:07
Done. Yeah is probably too much info.
| |
| 50 // destroyed before the call to the ExclusiveAccessBubbleViewsTest destructor. | |
|
msw
2017/05/03 18:48:34
q: Did you mean ExclusiveAccessBubbleViewsTest? (I
tapted
2017/05/04 06:42:07
Ahh yep - I meant the ExclusiveAccessBubbleViews d
| |
| 51 // CloseAllTabs() will destroy the bubble via the ExclusiveAccessBubbleViews | |
| 52 // destructor (via RenderViewTerminated -> ExitFullscreenMode). | |
| 53 // CloseAllBrowsers() does a graceful exit via Browser::OnWindowClosing() | |
| 54 // (which triggers CloseAllTabs()). | |
| 55 // However, when closing via BrowserWindow::DestroyBrowser(), BrowserView | |
| 56 // first stops observing its Widget, so never sees an OnWindowClosing(). | |
| 57 // DestroyBrowser is triggered by chrome::SessionEnding() which ends up in | |
| 58 // RenderProcessHostImpl::FastShutdownIfPossible() and only if fast shutdown | |
| 59 // IS possible, does it call ProcessDied() which also results in graceful | |
| 60 // termination via RenderViewTerminated. | |
| 61 // If fast shutdown is NOT possible (e.g. unload handlers), then the browser | |
| 62 // window can be torn down before RenderViewTerminated is sent and since the | |
| 63 // bubble is a child window it will get town down as well. | |
| 64 // That's all a bit complicated for a test, but it boils down to the window | |
| 65 // being closed by the OS or by DesktopWindowTreeHost::OnHostClosed() rather | |
| 66 // than by Widget::Close, and that needs to be handled. Widget::CloseNow() is | |
| 67 // a close approximation of this. | |
| 68 bubble()->GetView()->GetWidget()->CloseNow(); | |
|
msw
2017/05/03 18:48:34
aside: you could also potentially delete the bubbl
tapted
2017/05/04 06:42:07
That works for NativeWidgetAura, and views::Platfo
| |
| 69 EXPECT_FALSE(bubble()); | |
| 70 | |
| 71 // Verify that teardown is really happening via OnWidgetDestroyed() rather | |
| 72 // than the usual path via the ExclusiveAccessBubbleViews destructor. Since | |
| 73 // the destructor always first removes ExclusiveAccessBubbleViews as an | |
| 74 // observer before starting the close, checking in OnWidgetDestroyed that it's | |
| 75 // still observing achieves this. | |
| 76 EXPECT_TRUE(was_observing_in_destroying_); | |
| 77 EXPECT_TRUE(was_destroying_); | |
| 78 } | |
| OLD | NEW |