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" |
| 13 #include "chrome/browser/ui/chrome_select_file_policy.h" |
12 #include "chrome/browser/ui/view_ids.h" | 14 #include "chrome/browser/ui/view_ids.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/interactive_test_utils.h" | 16 #include "chrome/test/base/interactive_test_utils.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
16 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 19 #include "ui/shell_dialogs/select_file_dialog.h" |
17 #include "ui/views/focus/focus_manager.h" | 20 #include "ui/views/focus/focus_manager.h" |
18 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 22 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/widget/widget_observer.h" |
19 #include "url/gurl.h" | 24 #include "url/gurl.h" |
20 | 25 |
21 const char kSimplePage[] = "/focus/page_with_focus.html"; | 26 const char kSimplePage[] = "/focus/page_with_focus.html"; |
22 | 27 |
23 class BrowserViewFocusTest : public InProcessBrowserTest { | 28 class BrowserViewFocusTest : public InProcessBrowserTest { |
24 public: | 29 public: |
25 bool IsViewFocused(ViewID vid) { | 30 bool IsViewFocused(ViewID vid) { |
26 return ui_test_utils::IsViewFocused(browser(), vid); | 31 return ui_test_utils::IsViewFocused(browser(), vid); |
27 } | 32 } |
28 }; | 33 }; |
29 | 34 |
| 35 // Spins a run loop until a Widget's activation reaches the desired state. |
| 36 class WidgetActivationWaiter : public views::WidgetObserver { |
| 37 public: |
| 38 explicit WidgetActivationWaiter(views::Widget* widget, bool active) |
| 39 : observed_(false), active_(active) { |
| 40 widget->AddObserver(this); |
| 41 EXPECT_NE(active, widget->IsActive()); |
| 42 } |
| 43 |
| 44 void Wait() { |
| 45 if (!observed_) |
| 46 run_loop_.Run(); |
| 47 } |
| 48 |
| 49 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { |
| 50 if (active_ != active) |
| 51 return; |
| 52 |
| 53 observed_ = true; |
| 54 widget->RemoveObserver(this); |
| 55 if (run_loop_.running()) |
| 56 run_loop_.Quit(); |
| 57 } |
| 58 |
| 59 private: |
| 60 base::RunLoop run_loop_; |
| 61 bool observed_; |
| 62 bool active_; |
| 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); |
| 65 }; |
| 66 |
| 67 class FilePicker : public ui::SelectFileDialog::Listener { |
| 68 public: |
| 69 explicit FilePicker(BrowserWindow* window) { |
| 70 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 71 this, new ChromeSelectFilePolicy(NULL)); |
| 72 |
| 73 gfx::NativeWindow parent_window = window->GetNativeWindow(); |
| 74 ui::SelectFileDialog::FileTypeInfo file_types; |
| 75 file_types.support_drive = true; |
| 76 const base::FilePath file_path; |
| 77 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 78 base::string16(), |
| 79 file_path, |
| 80 &file_types, |
| 81 0, |
| 82 base::FilePath::StringType(), |
| 83 parent_window, |
| 84 NULL); |
| 85 } |
| 86 |
| 87 ~FilePicker() override { |
| 88 if (select_file_dialog_.get()) |
| 89 select_file_dialog_->ListenerDestroyed(); |
| 90 } |
| 91 |
| 92 void Close() { |
| 93 select_file_dialog_->Close(); |
| 94 } |
| 95 |
| 96 // SelectFileDialog::Listener implementation. |
| 97 void FileSelected(const base::FilePath& path, |
| 98 int index, |
| 99 void* params) override {} |
| 100 private: |
| 101 // Dialog box used for opening and saving files. |
| 102 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(FilePicker); |
| 105 }; |
| 106 |
30 // Flaky, http://crbug.com/69034. | 107 // Flaky, http://crbug.com/69034. |
31 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { | 108 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
32 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 109 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
33 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 110 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
34 | 111 |
35 // First we navigate to our test page. | 112 // First we navigate to our test page. |
36 GURL url = embedded_test_server()->GetURL(kSimplePage); | 113 GURL url = embedded_test_server()->GetURL(kSimplePage); |
37 ui_test_utils::NavigateToURL(browser(), url); | 114 ui_test_utils::NavigateToURL(browser(), url); |
38 | 115 |
39 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 116 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); | 163 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
87 ASSERT_TRUE(widget); | 164 ASSERT_TRUE(widget); |
88 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); | 165 EXPECT_EQ(nullptr, widget->GetFocusManager()->GetFocusedView()); |
89 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), | 166 EXPECT_EQ(browser_view2->GetTabContentsContainerView(), |
90 focus_manager2->GetFocusedView()); | 167 focus_manager2->GetFocusedView()); |
91 | 168 |
92 // Close the 2nd browser to avoid a DCHECK(). | 169 // Close the 2nd browser to avoid a DCHECK(). |
93 browser_view2->Close(); | 170 browser_view2->Close(); |
94 #endif | 171 #endif |
95 } | 172 } |
| 173 |
| 174 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 175 #define MAYBE_BrowserFileDialogTest BrowserFileDialogTest |
| 176 #else |
| 177 #define MAYBE_BrowserFileDialogTest DISABLED_BrowserFileDialogTest |
| 178 #endif |
| 179 IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserFileDialogTest) { |
| 180 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 181 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 182 |
| 183 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 184 ui_test_utils::NavigateToURL(browser(), url); |
| 185 ASSERT_TRUE(browser()->window()->IsActive()); |
| 186 |
| 187 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 |
| 188 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 189 FilePicker file_picker(browser()->window()); |
| 190 |
| 191 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 192 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 193 ASSERT_NE(nullptr, widget); |
| 194 |
| 195 // Run a nested loop until the browser window becomes inactive. |
| 196 WidgetActivationWaiter wait_inactive(widget, false); |
| 197 wait_inactive.Wait(); |
| 198 EXPECT_FALSE(browser()->window()->IsActive()); |
| 199 file_picker.Close(); |
| 200 |
| 201 // Run a nested loop until the browser window becomes active. |
| 202 WidgetActivationWaiter wait_active(widget, true); |
| 203 wait_active.Wait(); |
| 204 EXPECT_TRUE(browser()->window()->IsActive()); |
| 205 } |
OLD | NEW |