Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Unified Diff: chrome/browser/ui/browser_focus_uitest.cc

Issue 1233913009: Make File-Picker modal on Linux (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a WidgetObserver to know when the browser window becomes inactive Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser_focus_uitest.cc
diff --git a/chrome/browser/ui/browser_focus_uitest.cc b/chrome/browser/ui/browser_focus_uitest.cc
index e415dae2dfafcb010e28ebd96f637a53e9e276b1..a899b898e7c144e1a5fef92ff9b7b69a8da5d0a7 100644
--- a/chrome/browser/ui/browser_focus_uitest.cc
+++ b/chrome/browser/ui/browser_focus_uitest.cc
@@ -7,6 +7,7 @@
#include "base/format_macros.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
+#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
@@ -36,6 +37,8 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "ui/views/widget/widget.h"
msw 2015/09/14 16:56:16 c/b/ui/ can't always depend on views code; move th
msw 2015/09/14 18:15:27 Ping; I'm not sure if you saw this comment.
joone 2015/09/14 18:23:39 Okay, I will move this test to browser_view_focus_
joone 2015/09/14 19:15:30 Done.
+#include "ui/views/widget/widget_observer.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
@@ -188,6 +191,33 @@ class TestInterstitialPage : public content::InterstitialPageDelegate {
DISALLOW_COPY_AND_ASSIGN(TestInterstitialPage);
};
+// Spins a run loop until a Widget becomes inactive.
+class WidgetActivationWaiter : public views::WidgetObserver {
joone 2015/09/11 23:41:50 The WidgetActivationWaiter class was copied from u
+ public:
+ explicit WidgetActivationWaiter(views::Widget* widget) : observed_(false) {
+ widget->AddObserver(this);
+ }
+
+ void Wait() {
+ if (!observed_)
+ run_loop_.Run();
+ }
+
+ void OnWidgetActivationChanged(views::Widget* widget, bool active) override {
+ EXPECT_FALSE(active);
+ observed_ = true;
+ widget->RemoveObserver(this);
+ if (run_loop_.running())
+ run_loop_.Quit();
+ }
+
+ private:
+ base::RunLoop run_loop_;
+ bool observed_;
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetActivationWaiter);
+};
+
// Flaky on Mac (http://crbug.com/67301) and Windows
// (http://crbug.com/523255).
#if defined(OS_MACOSX) || defined(OS_WIN)
@@ -238,6 +268,44 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) {
ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX));
}
+// This test is only for Linux Desktop.
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+#define MAYBE_BrowserDialogModalTest BrowserDialogModalTest
+#else
+#define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest
+#endif
+IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_BrowserDialogModalTest) {
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ const GURL url = embedded_test_server()->GetURL(kSimplePage);
+ ui_test_utils::NavigateToURL(browser(), url);
+ ASSERT_TRUE(browser()->window()->IsActive());
+
+ browser()->OpenFile();
+
+ gfx::NativeWindow window = browser()->window()->GetNativeWindow();
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
+ ASSERT_NE(nullptr, widget);
+
+ // Insert a delay to wait until the browser window becomes inactive.
msw 2015/09/14 16:56:16 Update this comment.
joone 2015/09/14 18:14:17 Done.
+ WidgetActivationWaiter waiter(widget);
+ waiter.Wait();
+ EXPECT_FALSE(browser()->window()->IsActive());
+
+ ClickOnView(VIEW_ID_TAB_CONTAINER);
+ // The window should not get focus due to modal dialog.
+ EXPECT_FALSE(browser()->window()->IsActive());
+
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ EXPECT_FALSE(browser()->window()->IsActive());
+
+ ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
+ EXPECT_FALSE(browser()->window()->IsActive());
+
+ ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
+ browser(), ui::VKEY_TAB, false, false, true, false));
+ EXPECT_FALSE(browser()->window()->IsActive());
+}
+
// Tabs remember focus.
// Disabled, http://crbug.com/62542.
IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) {
« no previous file with comments | « no previous file | chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698