OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/libgtk2ui/select_file_dialog_impl_gtk2.h" | |
6 | |
7 #include "base/macros.h" | 5 #include "base/macros.h" |
8 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_window.h" | 7 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/chrome_select_file_policy.h" | 8 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 9 #include "chrome/browser/ui/libgtkui/select_file_dialog_impl_gtk2.h" |
11 #include "chrome/browser/ui/view_ids.h" | 10 #include "chrome/browser/ui/view_ids.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "chrome/test/base/interactive_test_utils.h" | 12 #include "chrome/test/base/interactive_test_utils.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
15 #include "net/test/embedded_test_server/embedded_test_server.h" | 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
16 #include "ui/shell_dialogs/select_file_dialog.h" | 15 #include "ui/shell_dialogs/select_file_dialog.h" |
17 #include "ui/views/test/widget_test.h" | 16 #include "ui/views/test/widget_test.h" |
18 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
19 | 18 |
20 using BrowserSelectFileDialogTest = InProcessBrowserTest; | 19 using BrowserSelectFileDialogTest = InProcessBrowserTest; |
21 | 20 |
22 namespace libgtk2ui { | 21 namespace libgtkui { |
23 | 22 |
24 // FilePicker opens a GtkFileChooser. | 23 // FilePicker opens a GtkFileChooser. |
25 class FilePicker : public ui::SelectFileDialog::Listener { | 24 class FilePicker : public ui::SelectFileDialog::Listener { |
26 public: | 25 public: |
27 explicit FilePicker(BrowserWindow* window) { | 26 explicit FilePicker(BrowserWindow* window) { |
28 select_file_dialog_ = ui::SelectFileDialog::Create( | 27 select_file_dialog_ = ui::SelectFileDialog::Create( |
29 this, new ChromeSelectFilePolicy(nullptr)); | 28 this, new ChromeSelectFilePolicy(nullptr)); |
30 | 29 |
31 gfx::NativeWindow parent_window = window->GetNativeWindow(); | 30 gfx::NativeWindow parent_window = window->GetNativeWindow(); |
32 ui::SelectFileDialog::FileTypeInfo file_types; | 31 ui::SelectFileDialog::FileTypeInfo file_types; |
(...skipping 26 matching lines...) Expand all Loading... |
59 void FileSelected(const base::FilePath& path, | 58 void FileSelected(const base::FilePath& path, |
60 int index, | 59 int index, |
61 void* params) override {} | 60 void* params) override {} |
62 private: | 61 private: |
63 // Dialog box used for opening and saving files. | 62 // Dialog box used for opening and saving files. |
64 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | 63 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
65 | 64 |
66 DISALLOW_COPY_AND_ASSIGN(FilePicker); | 65 DISALLOW_COPY_AND_ASSIGN(FilePicker); |
67 }; | 66 }; |
68 | 67 |
69 } // namespace libgtk2ui | 68 } // namespace libgtkui |
70 | 69 |
71 // Test that the file-picker is modal. | 70 // Test that the file-picker is modal. |
72 IN_PROC_BROWSER_TEST_F(BrowserSelectFileDialogTest, ModalTest) { | 71 IN_PROC_BROWSER_TEST_F(BrowserSelectFileDialogTest, ModalTest) { |
73 // Bring the native window to the foreground. Returns true on success. | 72 // Bring the native window to the foreground. Returns true on success. |
74 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 73 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
75 ASSERT_TRUE(browser()->window()->IsActive()); | 74 ASSERT_TRUE(browser()->window()->IsActive()); |
76 | 75 |
77 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 | 76 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 |
78 ANNOTATE_SCOPED_MEMORY_LEAK; | 77 ANNOTATE_SCOPED_MEMORY_LEAK; |
79 libgtk2ui::FilePicker file_picker(browser()->window()); | 78 libgtkui::FilePicker file_picker(browser()->window()); |
80 | 79 |
81 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 80 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
82 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 81 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
83 ASSERT_NE(nullptr, widget); | 82 ASSERT_NE(nullptr, widget); |
84 | 83 |
85 // Run a nested loop until the browser window becomes inactive | 84 // Run a nested loop until the browser window becomes inactive |
86 // so that the file-picker can be active. | 85 // so that the file-picker can be active. |
87 views::test::WidgetActivationWaiter waiter_inactive(widget, false); | 86 views::test::WidgetActivationWaiter waiter_inactive(widget, false); |
88 waiter_inactive.Wait(); | 87 waiter_inactive.Wait(); |
89 EXPECT_FALSE(browser()->window()->IsActive()); | 88 EXPECT_FALSE(browser()->window()->IsActive()); |
(...skipping 14 matching lines...) Expand all Loading... |
104 | 103 |
105 file_picker.Close(); | 104 file_picker.Close(); |
106 | 105 |
107 // Run a nested loop until the browser window becomes active. | 106 // Run a nested loop until the browser window becomes active. |
108 views::test::WidgetActivationWaiter wait_active(widget, true); | 107 views::test::WidgetActivationWaiter wait_active(widget, true); |
109 wait_active.Wait(); | 108 wait_active.Wait(); |
110 | 109 |
111 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 110 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
112 EXPECT_TRUE(browser()->window()->IsActive()); | 111 EXPECT_TRUE(browser()->window()->IsActive()); |
113 } | 112 } |
OLD | NEW |