| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.h" | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/browser_window.h" | |
| 10 #include "chrome/browser/ui/chrome_select_file_policy.h" | |
| 11 #include "chrome/browser/ui/view_ids.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/interactive_test_utils.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 16 #include "ui/shell_dialogs/select_file_dialog.h" | |
| 17 #include "ui/views/test/widget_test.h" | |
| 18 #include "ui/views/widget/widget.h" | |
| 19 | |
| 20 using BrowserSelectFileDialogTest = InProcessBrowserTest; | |
| 21 | |
| 22 namespace libgtk2ui { | |
| 23 | |
| 24 // FilePicker opens a GtkFileChooser. | |
| 25 class FilePicker : public ui::SelectFileDialog::Listener { | |
| 26 public: | |
| 27 explicit FilePicker(BrowserWindow* window) { | |
| 28 select_file_dialog_ = ui::SelectFileDialog::Create( | |
| 29 this, new ChromeSelectFilePolicy(nullptr)); | |
| 30 | |
| 31 gfx::NativeWindow parent_window = window->GetNativeWindow(); | |
| 32 ui::SelectFileDialog::FileTypeInfo file_types; | |
| 33 file_types.allowed_paths = ui::SelectFileDialog::FileTypeInfo::ANY_PATH; | |
| 34 const base::FilePath file_path; | |
| 35 select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, | |
| 36 base::string16(), | |
| 37 file_path, | |
| 38 &file_types, | |
| 39 0, | |
| 40 base::FilePath::StringType(), | |
| 41 parent_window, | |
| 42 nullptr); | |
| 43 } | |
| 44 | |
| 45 ~FilePicker() override { | |
| 46 select_file_dialog_->ListenerDestroyed(); | |
| 47 } | |
| 48 | |
| 49 void Close() { | |
| 50 SelectFileDialogImplGTK* file_dialog = | |
| 51 static_cast<SelectFileDialogImplGTK*>(select_file_dialog_.get()); | |
| 52 | |
| 53 | |
| 54 while (!file_dialog->dialogs_.empty()) | |
| 55 gtk_widget_destroy(*(file_dialog->dialogs_.begin())); | |
| 56 } | |
| 57 | |
| 58 // SelectFileDialog::Listener implementation. | |
| 59 void FileSelected(const base::FilePath& path, | |
| 60 int index, | |
| 61 void* params) override {} | |
| 62 private: | |
| 63 // Dialog box used for opening and saving files. | |
| 64 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(FilePicker); | |
| 67 }; | |
| 68 | |
| 69 } // namespace libgtk2ui | |
| 70 | |
| 71 // Test that the file-picker is modal. | |
| 72 IN_PROC_BROWSER_TEST_F(BrowserSelectFileDialogTest, ModalTest) { | |
| 73 // Bring the native window to the foreground. Returns true on success. | |
| 74 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 75 ASSERT_TRUE(browser()->window()->IsActive()); | |
| 76 | |
| 77 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 | |
| 78 ANNOTATE_SCOPED_MEMORY_LEAK; | |
| 79 libgtk2ui::FilePicker file_picker(browser()->window()); | |
| 80 | |
| 81 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
| 82 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
| 83 ASSERT_NE(nullptr, widget); | |
| 84 | |
| 85 // Run a nested loop until the browser window becomes inactive | |
| 86 // so that the file-picker can be active. | |
| 87 views::test::WidgetActivationWaiter waiter_inactive(widget, false); | |
| 88 waiter_inactive.Wait(); | |
| 89 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 90 | |
| 91 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | |
| 92 // The window should not get focus due to modal dialog. | |
| 93 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 94 | |
| 95 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 96 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 97 | |
| 98 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | |
| 99 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 100 | |
| 101 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 102 browser(), ui::VKEY_TAB, false, false, true, false)); | |
| 103 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 104 | |
| 105 file_picker.Close(); | |
| 106 | |
| 107 // Run a nested loop until the browser window becomes active. | |
| 108 views::test::WidgetActivationWaiter wait_active(widget, true); | |
| 109 wait_active.Wait(); | |
| 110 | |
| 111 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | |
| 112 EXPECT_TRUE(browser()->window()->IsActive()); | |
| 113 } | |
| OLD | NEW |