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 } |
28 }; | 31 }; |
29 | 32 |
| 33 // Spins a run loop until a Widget becomes inactive. |
| 34 class WidgetActivationWaiter : public views::WidgetObserver { |
| 35 public: |
| 36 explicit WidgetActivationWaiter(views::Widget* widget) : observed_(false) { |
| 37 widget->AddObserver(this); |
| 38 EXPECT_TRUE(widget->IsActive()); |
| 39 } |
| 40 |
| 41 void Wait() { |
| 42 if (!observed_) |
| 43 run_loop_.Run(); |
| 44 } |
| 45 |
| 46 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { |
| 47 EXPECT_FALSE(active); |
| 48 observed_ = true; |
| 49 widget->RemoveObserver(this); |
| 50 if (run_loop_.running()) |
| 51 run_loop_.Quit(); |
| 52 } |
| 53 |
| 54 private: |
| 55 base::RunLoop run_loop_; |
| 56 bool observed_; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); |
| 59 }; |
| 60 |
30 // Flaky, http://crbug.com/69034. | 61 // Flaky, http://crbug.com/69034. |
31 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { | 62 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
32 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 63 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
33 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 64 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
34 | 65 |
35 // First we navigate to our test page. | 66 // First we navigate to our test page. |
36 GURL url = embedded_test_server()->GetURL(kSimplePage); | 67 GURL url = embedded_test_server()->GetURL(kSimplePage); |
37 ui_test_utils::NavigateToURL(browser(), url); | 68 ui_test_utils::NavigateToURL(browser(), url); |
38 | 69 |
39 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 70 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 117 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
87 ASSERT_TRUE(widget); | 118 ASSERT_TRUE(widget); |
88 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); | 119 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); |
89 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), | 120 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
90 focus_manager2->GetFocusedView()); | 121 focus_manager2->GetFocusedView()); |
91 | 122 |
92 // Close the 2nd browser to avoid a DCHECK(). | 123 // Close the 2nd browser to avoid a DCHECK(). |
93 browser_view2->Close(); | 124 browser_view2->Close(); |
94 #endif | 125 #endif |
95 } | 126 } |
| 127 |
| 128 // This test is only for Linux Desktop. |
| 129 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 130 #define MAYBE_BrowserDialogModalTest BrowserDialogModalTest |
| 131 #else |
| 132 #define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest |
| 133 #endif |
| 134 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserDialogModalTest) { |
| 135 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 136 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 137 |
| 138 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 139 ui_test_utils::NavigateToURL(browser(), url); |
| 140 ASSERT_TRUE(browser()->window()->IsActive()); |
| 141 |
| 142 browser()->OpenFile(); |
| 143 |
| 144 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 145 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 146 ASSERT_NE(nullptr, widget); |
| 147 |
| 148 // Run a nested loop until the browser window becomes inactive. |
| 149 WidgetActivationWaiter waiter(widget); |
| 150 waiter.Wait(); |
| 151 EXPECT_FALSE(browser()->window()->IsActive()); |
| 152 |
| 153 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 154 // The window should not get focus due to modal dialog. |
| 155 EXPECT_FALSE(browser()->window()->IsActive()); |
| 156 |
| 157 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 158 EXPECT_FALSE(browser()->window()->IsActive()); |
| 159 |
| 160 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
| 161 EXPECT_FALSE(browser()->window()->IsActive()); |
| 162 |
| 163 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 164 browser(), ui::VKEY_TAB, false, false, true, false)); |
| 165 EXPECT_FALSE(browser()->window()->IsActive()); |
| 166 |
| 167 browser()->CloseFileDialog(); |
| 168 |
| 169 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 170 EXPECT_TRUE(browser()->window()->IsActive()); |
| 171 } |
OLD | NEW |