Chromium Code Reviews| Index: chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
| diff --git a/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc b/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
| index 3d0aaf888fd2ff89b2c129f0fc9f9053fbfa294b..ef7275e400760d8d26573f227b9ec7ce0353b660 100644 |
| --- a/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
| +++ b/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| +#include "base/run_loop.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_commands.h" |
| @@ -16,6 +17,8 @@ |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "ui/views/focus/focus_manager.h" |
| #include "ui/views/view.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "ui/views/widget/widget_observer.h" |
| #include "url/gurl.h" |
| const char kSimplePage[] = "/focus/page_with_focus.html"; |
| @@ -25,6 +28,37 @@ class BrowserViewFocusTest : public InProcessBrowserTest { |
| bool IsViewFocused(ViewID vid) { |
| return ui_test_utils::IsViewFocused(browser(), vid); |
| } |
| + |
| + void ClickOnView(ViewID vid) { |
| + ui_test_utils::ClickOnView(browser(), vid); |
|
msw
2015/09/14 23:04:59
nit: InProcessBrowserTest::browser() is protected,
joone
2015/09/15 22:54:53
Done.
|
| + } |
| +}; |
| + |
| +// Spins a run loop until a Widget becomes inactive. |
| +class WidgetActivationWaiter : public views::WidgetObserver { |
| + public: |
| + explicit WidgetActivationWaiter(views::Widget* widget) : observed_(false) { |
| + widget->AddObserver(this); |
|
msw
2015/09/14 23:04:59
nit: add this expectation here: EXPECT_TRUE(widget
joone
2015/09/15 22:54:53
Done.
|
| + } |
| + |
| + void Wait() { |
| + if (!observed_) |
| + run_loop_.Run(); |
| + } |
| + |
| + void OnWidgetActivationChanged(views::Widget* widget, bool active) override { |
| + EXPECT_FALSE(active); |
| + observed_ = true; |
| + widget->RemoveObserver(this); |
| + if (run_loop_.running()) |
| + run_loop_.Quit(); |
| + } |
| + |
| + private: |
| + base::RunLoop run_loop_; |
| + bool observed_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); |
| }; |
| // Flaky, http://crbug.com/69034. |
| @@ -93,3 +127,41 @@ IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
| browser_view2->Close(); |
| #endif |
| } |
| + |
| +// This test is only for Linux Desktop. |
|
msw
2015/09/14 23:04:58
nit: as a follow-up should we try to enable this o
joone
2015/09/15 22:54:52
Sure, I will try to do.
|
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| +#define MAYBE_BrowserDialogModalTest BrowserDialogModalTest |
| +#else |
| +#define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest |
| +#endif |
| +IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserDialogModalTest) { |
| + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| + const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + ASSERT_TRUE(browser()->window()->IsActive()); |
| + |
| + browser()->OpenFile(); |
| + |
| + gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| + views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| + ASSERT_NE(nullptr, widget); |
| + |
| + // Run a nested loop until the browser window becomes inactive. |
| + WidgetActivationWaiter waiter(widget); |
| + waiter.Wait(); |
| + EXPECT_FALSE(browser()->window()->IsActive()); |
| + |
| + ClickOnView(VIEW_ID_TAB_CONTAINER); |
| + // The window should not get focus due to modal dialog. |
| + EXPECT_FALSE(browser()->window()->IsActive()); |
| + |
| + ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| + EXPECT_FALSE(browser()->window()->IsActive()); |
| + |
| + ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
| + EXPECT_FALSE(browser()->window()->IsActive()); |
| + |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| + browser(), ui::VKEY_TAB, false, false, true, false)); |
| + EXPECT_FALSE(browser()->window()->IsActive()); |
| +} |