Index: chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
diff --git a/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc b/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
index 3d0aaf888fd2ff89b2c129f0fc9f9053fbfa294b..89f51152f61d588271c72e2800b4525ed947fadd 100644 |
--- a/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
+++ b/chrome/browser/ui/views/frame/browser_view_focus_uitest.cc |
@@ -4,18 +4,23 @@ |
#include "chrome/browser/ui/views/frame/browser_view.h" |
+#include "base/run_loop.h" |
#include "build/build_config.h" |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_commands.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/browser/ui/browser_window.h" |
+#include "chrome/browser/ui/chrome_select_file_policy.h" |
#include "chrome/browser/ui/view_ids.h" |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/interactive_test_utils.h" |
#include "chrome/test/base/ui_test_utils.h" |
#include "net/test/embedded_test_server/embedded_test_server.h" |
+#include "ui/shell_dialogs/select_file_dialog.h" |
#include "ui/views/focus/focus_manager.h" |
#include "ui/views/view.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/widget/widget_observer.h" |
#include "url/gurl.h" |
const char kSimplePage[] = "/focus/page_with_focus.html"; |
@@ -27,6 +32,78 @@ class BrowserViewFocusTest : public InProcessBrowserTest { |
} |
}; |
+// Spins a run loop until a Widget's activation reaches the desired state. |
+class WidgetActivationWaiter : public views::WidgetObserver { |
+ public: |
+ explicit WidgetActivationWaiter(views::Widget* widget, bool active) |
+ : observed_(false), active_(active) { |
+ widget->AddObserver(this); |
+ EXPECT_NE(active, widget->IsActive()); |
+ } |
+ |
+ void Wait() { |
+ if (!observed_) |
+ run_loop_.Run(); |
+ } |
+ |
+ void OnWidgetActivationChanged(views::Widget* widget, bool active) override { |
+ if (active_ != active) |
+ return; |
+ |
+ observed_ = true; |
+ widget->RemoveObserver(this); |
+ if (run_loop_.running()) |
+ run_loop_.Quit(); |
+ } |
+ |
+ private: |
+ base::RunLoop run_loop_; |
+ bool observed_; |
+ bool active_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter); |
+}; |
+ |
+class FilePicker : public ui::SelectFileDialog::Listener { |
+ public: |
+ explicit FilePicker(BrowserWindow* window) { |
+ select_file_dialog_ = ui::SelectFileDialog::Create( |
+ this, new ChromeSelectFilePolicy(NULL)); |
+ |
+ gfx::NativeWindow parent_window = window->GetNativeWindow(); |
+ ui::SelectFileDialog::FileTypeInfo file_types; |
+ file_types.support_drive = true; |
+ const base::FilePath file_path; |
+ select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
+ base::string16(), |
+ file_path, |
+ &file_types, |
+ 0, |
+ base::FilePath::StringType(), |
+ parent_window, |
+ NULL); |
+ } |
+ |
+ ~FilePicker() override { |
+ if (select_file_dialog_.get()) |
+ select_file_dialog_->ListenerDestroyed(); |
+ } |
+ |
+ void Close() { |
+ select_file_dialog_->Close(); |
+ } |
+ |
+ // SelectFileDialog::Listener implementation. |
+ void FileSelected(const base::FilePath& path, |
+ int index, |
+ void* params) override {} |
+ private: |
+ // Dialog box used for opening and saving files. |
+ scoped_refptr<ui::SelectFileDialog> select_file_dialog_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FilePicker); |
+}; |
+ |
// Flaky, http://crbug.com/69034. |
IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
@@ -93,3 +170,36 @@ IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, DISABLED_BrowsersRememberFocus) { |
browser_view2->Close(); |
#endif |
} |
+ |
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
+#define MAYBE_BrowserFileDialogTest BrowserFileDialogTest |
+#else |
+#define MAYBE_BrowserFileDialogTest DISABLED_BrowserFileDialogTest |
+#endif |
+IN_PROC_BROWSER_TEST_F(BrowserViewFocusTest, MAYBE_BrowserFileDialogTest) { |
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
+ |
+ const GURL url = embedded_test_server()->GetURL(kSimplePage); |
+ ui_test_utils::NavigateToURL(browser(), url); |
+ ASSERT_TRUE(browser()->window()->IsActive()); |
+ |
+ // Leaks in GtkFileChooserDialog. http://crbug.com/537468 |
+ ANNOTATE_SCOPED_MEMORY_LEAK; |
+ FilePicker file_picker(browser()->window()); |
+ |
+ gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
+ ASSERT_NE(nullptr, widget); |
+ |
+ // Run a nested loop until the browser window becomes inactive. |
+ WidgetActivationWaiter wait_inactive(widget, false); |
+ wait_inactive.Wait(); |
+ EXPECT_FALSE(browser()->window()->IsActive()); |
+ file_picker.Close(); |
+ |
+ // Run a nested loop until the browser window becomes active. |
+ WidgetActivationWaiter wait_active(widget, true); |
+ wait_active.Wait(); |
+ EXPECT_TRUE(browser()->window()->IsActive()); |
+} |