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" |
| 18 #include "ui/shell_dialogs/select_file_dialog.h" |
17 #include "ui/views/focus/focus_manager.h" | 19 #include "ui/views/focus/focus_manager.h" |
18 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_observer.h" |
19 #include "url/gurl.h" | 23 #include "url/gurl.h" |
20 | 24 |
21 const char kSimplePage[] = "/focus/page_with_focus.html"; | 25 const char kSimplePage[] = "/focus/page_with_focus.html"; |
22 | 26 |
23 class BrowserViewFocusTest : public InProcessBrowserTest { | 27 class BrowserViewFocusTest : public InProcessBrowserTest { |
24 public: | 28 public: |
25 bool IsViewFocused(ViewID vid) { | 29 bool IsViewFocused(ViewID vid) { |
26 return ui_test_utils::IsViewFocused(browser(), vid); | 30 return ui_test_utils::IsViewFocused(browser(), vid); |
27 } | 31 } |
28 }; | 32 }; |
29 | 33 |
| 34 // Spins a run loop until a Widget's activation reaches the desired state. |
| 35 class WidgetActivationWaiter : public views::WidgetObserver { |
| 36 public: |
| 37 explicit WidgetActivationWaiter(views::Widget* widget, bool active) |
| 38 : observed_(false), active_(active) { |
| 39 widget->AddObserver(this); |
| 40 EXPECT_NE(active, widget->IsActive()); |
| 41 } |
| 42 |
| 43 void Wait() { |
| 44 if (!observed_) |
| 45 run_loop_.Run(); |
| 46 } |
| 47 |
| 48 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { |
| 49 if (active_ != active) |
| 50 return; |
| 51 |
| 52 observed_ = true; |
| 53 widget->RemoveObserver(this); |
| 54 if (run_loop_.running()) |
| 55 run_loop_.Quit(); |
| 56 } |
| 57 |
| 58 private: |
| 59 base::RunLoop run_loop_; |
| 60 bool observed_; |
| 61 bool active_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); |
| 64 }; |
| 65 |
30 // Flaky, http://crbug.com/69034. | 66 // Flaky, http://crbug.com/69034. |
31 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { | 67 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
32 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 68 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
33 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 69 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
34 | 70 |
35 // First we navigate to our test page. | 71 // First we navigate to our test page. |
36 GURL url = embedded_test_server()->GetURL(kSimplePage); | 72 GURL url = embedded_test_server()->GetURL(kSimplePage); |
37 ui_test_utils::NavigateToURL(browser(), url); | 73 ui_test_utils::NavigateToURL(browser(), url); |
38 | 74 |
39 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 75 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); | 122 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
87 ASSERT_TRUE(widget); | 123 ASSERT_TRUE(widget); |
88 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); | 124 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); |
89 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), | 125 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
90 focus_manager2->GetFocusedView()); | 126 focus_manager2->GetFocusedView()); |
91 | 127 |
92 // Close the 2nd browser to avoid a DCHECK(). | 128 // Close the 2nd browser to avoid a DCHECK(). |
93 browser_view2->Close(); | 129 browser_view2->Close(); |
94 #endif | 130 #endif |
95 } | 131 } |
| 132 |
| 133 // There are memory leaks in GtkFileChooserDialog, which was |
| 134 // added to build/sanitizers/lsan_suppressions.cc as an encompassing entry. |
| 135 // http://crbug.com/537468. |
| 136 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 137 #define MAYBE_BrowserFileDialogTest BrowserFileDialogTest |
| 138 #else |
| 139 #define MAYBE_BrowserFileDialogTest DISABLED_BrowserFileDialogTest |
| 140 #endif |
| 141 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserFileDialogTest) { |
| 142 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 143 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 144 |
| 145 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 146 ui_test_utils::NavigateToURL(browser(), url); |
| 147 ASSERT_TRUE(browser()->window()->IsActive()); |
| 148 |
| 149 ui::SelectFileDialog* file_dialog = browser()->OpenFile(); |
| 150 |
| 151 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 152 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 153 ASSERT_NE(nullptr, widget); |
| 154 |
| 155 // Run a nested loop until the browser window becomes inactive. |
| 156 WidgetActivationWaiter wait_inactive(widget, false); |
| 157 wait_inactive.Wait(); |
| 158 EXPECT_FALSE(browser()->window()->IsActive()); |
| 159 file_dialog->Close(); |
| 160 |
| 161 // Run a nested loop until the browser window becomes active. |
| 162 WidgetActivationWaiter wait_active(widget, true); |
| 163 wait_active.Wait(); |
| 164 EXPECT_TRUE(browser()->window()->IsActive()); |
| 165 } |
OLD | NEW |