Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | |
| 7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 10 #include "chrome/browser/ui/browser_tabstrip.h" | 11 #include "chrome/browser/ui/browser_tabstrip.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/interactive_test_utils.h" | 15 #include "chrome/test/base/interactive_test_utils.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "ui/views/focus/focus_manager.h" | 18 #include "ui/views/focus/focus_manager.h" |
| 18 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | |
| 21 #include "ui/views/widget/widget_observer.h" | |
| 19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 20 | 23 |
| 21 const char kSimplePage[] = "/focus/page_with_focus.html"; | 24 const char kSimplePage[] = "/focus/page_with_focus.html"; |
| 22 | 25 |
| 23 class BrowserViewFocusTest : public InProcessBrowserTest { | 26 class BrowserViewFocusTest : public InProcessBrowserTest { |
| 24 public: | 27 public: |
| 25 bool IsViewFocused(ViewID vid) { | 28 bool IsViewFocused(ViewID vid) { |
| 26 return ui_test_utils::IsViewFocused(browser(), vid); | 29 return ui_test_utils::IsViewFocused(browser(), vid); |
| 27 } | 30 } |
| 31 | |
| 32 void ClickOnView(ViewID vid) { | |
| 33 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.
| |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // Spins a run loop until a Widget becomes inactive. | |
| 38 class WidgetActivationWaiter : public views::WidgetObserver { | |
| 39 public: | |
| 40 explicit WidgetActivationWaiter(views::Widget* widget) : observed_(false) { | |
| 41 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.
| |
| 42 } | |
| 43 | |
| 44 void Wait() { | |
| 45 if (!observed_) | |
| 46 run_loop_.Run(); | |
| 47 } | |
| 48 | |
| 49 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { | |
| 50 EXPECT_FALSE(active); | |
| 51 observed_ = true; | |
| 52 widget->RemoveObserver(this); | |
| 53 if (run_loop_.running()) | |
| 54 run_loop_.Quit(); | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 base::RunLoop run_loop_; | |
| 59 bool observed_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); | |
| 28 }; | 62 }; |
| 29 | 63 |
| 30 // Flaky, http://crbug.com/69034. | 64 // Flaky, http://crbug.com/69034. |
| 31 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { | 65 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
| 32 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 66 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 33 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 67 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 34 | 68 |
| 35 // First we navigate to our test page. | 69 // First we navigate to our test page. |
| 36 GURL url = embedded_test_server()->GetURL(kSimplePage); | 70 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 37 ui_test_utils::NavigateToURL(browser(), url); | 71 ui_test_utils::NavigateToURL(browser(), url); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 120 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 87 ASSERT_TRUE(widget); | 121 ASSERT_TRUE(widget); |
| 88 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); | 122 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); |
| 89 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), | 123 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
| 90 focus_manager2->GetFocusedView()); | 124 focus_manager2->GetFocusedView()); |
| 91 | 125 |
| 92 // Close the 2nd browser to avoid a DCHECK(). | 126 // Close the 2nd browser to avoid a DCHECK(). |
| 93 browser_view2->Close(); | 127 browser_view2->Close(); |
| 94 #endif | 128 #endif |
| 95 } | 129 } |
| 130 | |
| 131 // 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.
| |
| 132 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 133 #define MAYBE_BrowserDialogModalTest BrowserDialogModalTest | |
| 134 #else | |
| 135 #define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest | |
| 136 #endif | |
| 137 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserDialogModalTest) { | |
| 138 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 139 const GURL url = embedded_test_server()->GetURL(kSimplePage); | |
| 140 ui_test_utils::NavigateToURL(browser(), url); | |
| 141 ASSERT_TRUE(browser()->window()->IsActive()); | |
| 142 | |
| 143 browser()->OpenFile(); | |
| 144 | |
| 145 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
| 146 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
| 147 ASSERT_NE(nullptr, widget); | |
| 148 | |
| 149 // Run a nested loop until the browser window becomes inactive. | |
| 150 WidgetActivationWaiter waiter(widget); | |
| 151 waiter.Wait(); | |
| 152 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 153 | |
| 154 ClickOnView(VIEW_ID_TAB_CONTAINER); | |
| 155 // The window should not get focus due to modal dialog. | |
| 156 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 157 | |
| 158 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 159 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 160 | |
| 161 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | |
| 162 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 163 | |
| 164 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 165 browser(), ui::VKEY_TAB, false, false, true, false)); | |
| 166 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 167 } | |
| OLD | NEW |