| 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" | 5 #include "chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/chrome_select_file_policy.h" | 10 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 12 #include "chrome/browser/ui/view_ids.h" | 11 #include "chrome/browser/ui/view_ids.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/interactive_test_utils.h" | 13 #include "chrome/test/base/interactive_test_utils.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "ui/shell_dialogs/select_file_dialog.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" | 18 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/widget/widget_observer.h" | |
| 20 | 19 |
| 21 using BrowserSelectFileDialogTest = InProcessBrowserTest; | 20 using BrowserSelectFileDialogTest = InProcessBrowserTest; |
| 22 | 21 |
| 23 // Spins a run loop until a Widget's activation reaches the desired state. | |
| 24 class WidgetActivationWaiter : public views::WidgetObserver { | |
| 25 public: | |
| 26 WidgetActivationWaiter(views::Widget* widget, bool active) | |
| 27 : observed_(false), active_(active) { | |
| 28 widget->AddObserver(this); | |
| 29 EXPECT_NE(active, widget->IsActive()); | |
| 30 } | |
| 31 | |
| 32 void Wait() { | |
| 33 if (!observed_) | |
| 34 run_loop_.Run(); | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 // views::WidgetObserver: | |
| 39 void OnWidgetActivationChanged(views::Widget* widget, bool active) override { | |
| 40 if (active_ != active) | |
| 41 return; | |
| 42 | |
| 43 observed_ = true; | |
| 44 widget->RemoveObserver(this); | |
| 45 if (run_loop_.running()) | |
| 46 run_loop_.Quit(); | |
| 47 } | |
| 48 | |
| 49 base::RunLoop run_loop_; | |
| 50 bool observed_; | |
| 51 bool active_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); | |
| 54 }; | |
| 55 | |
| 56 namespace libgtk2ui { | 22 namespace libgtk2ui { |
| 57 | 23 |
| 58 // FilePicker opens a GtkFileChooser. | 24 // FilePicker opens a GtkFileChooser. |
| 59 class FilePicker : public ui::SelectFileDialog::Listener { | 25 class FilePicker : public ui::SelectFileDialog::Listener { |
| 60 public: | 26 public: |
| 61 explicit FilePicker(BrowserWindow* window) { | 27 explicit FilePicker(BrowserWindow* window) { |
| 62 select_file_dialog_ = ui::SelectFileDialog::Create( | 28 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 63 this, new ChromeSelectFilePolicy(nullptr)); | 29 this, new ChromeSelectFilePolicy(nullptr)); |
| 64 | 30 |
| 65 gfx::NativeWindow parent_window = window->GetNativeWindow(); | 31 gfx::NativeWindow parent_window = window->GetNativeWindow(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 | 77 // Leaks in GtkFileChooserDialog. http://crbug.com/537468 |
| 112 ANNOTATE_SCOPED_MEMORY_LEAK; | 78 ANNOTATE_SCOPED_MEMORY_LEAK; |
| 113 libgtk2ui::FilePicker file_picker(browser()->window()); | 79 libgtk2ui::FilePicker file_picker(browser()->window()); |
| 114 | 80 |
| 115 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 81 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 116 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 82 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 117 ASSERT_NE(nullptr, widget); | 83 ASSERT_NE(nullptr, widget); |
| 118 | 84 |
| 119 // Run a nested loop until the browser window becomes inactive | 85 // Run a nested loop until the browser window becomes inactive |
| 120 // so that the file-picker can be active. | 86 // so that the file-picker can be active. |
| 121 WidgetActivationWaiter waiter_inactive(widget, false); | 87 views::test::WidgetActivationWaiter waiter_inactive(widget, false); |
| 122 waiter_inactive.Wait(); | 88 waiter_inactive.Wait(); |
| 123 EXPECT_FALSE(browser()->window()->IsActive()); | 89 EXPECT_FALSE(browser()->window()->IsActive()); |
| 124 | 90 |
| 125 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 91 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 126 // The window should not get focus due to modal dialog. | 92 // The window should not get focus due to modal dialog. |
| 127 EXPECT_FALSE(browser()->window()->IsActive()); | 93 EXPECT_FALSE(browser()->window()->IsActive()); |
| 128 | 94 |
| 129 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 95 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 130 EXPECT_FALSE(browser()->window()->IsActive()); | 96 EXPECT_FALSE(browser()->window()->IsActive()); |
| 131 | 97 |
| 132 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | 98 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
| 133 EXPECT_FALSE(browser()->window()->IsActive()); | 99 EXPECT_FALSE(browser()->window()->IsActive()); |
| 134 | 100 |
| 135 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 101 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 136 browser(), ui::VKEY_TAB, false, false, true, false)); | 102 browser(), ui::VKEY_TAB, false, false, true, false)); |
| 137 EXPECT_FALSE(browser()->window()->IsActive()); | 103 EXPECT_FALSE(browser()->window()->IsActive()); |
| 138 | 104 |
| 139 file_picker.Close(); | 105 file_picker.Close(); |
| 140 | 106 |
| 141 // Run a nested loop until the browser window becomes active. | 107 // Run a nested loop until the browser window becomes active. |
| 142 WidgetActivationWaiter wait_active(widget, true); | 108 views::test::WidgetActivationWaiter wait_active(widget, true); |
| 143 wait_active.Wait(); | 109 wait_active.Wait(); |
| 144 | 110 |
| 145 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 111 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 146 EXPECT_TRUE(browser()->window()->IsActive()); | 112 EXPECT_TRUE(browser()->window()->IsActive()); |
| 147 } | 113 } |
| OLD | NEW |