Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/test/test_timeouts.h" | |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
| 18 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" | 20 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h" |
| 19 #include "chrome/browser/ui/location_bar/location_bar.h" | 21 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/view_ids.h" | 23 #include "chrome/browser/ui/view_ids.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 233 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 232 | 234 |
| 233 chrome::FocusLocationBar(browser()); | 235 chrome::FocusLocationBar(browser()); |
| 234 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 236 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 235 // Hide the window, show it again, the focus should not have changed. | 237 // Hide the window, show it again, the focus should not have changed. |
| 236 ui_test_utils::HideNativeWindow(window); | 238 ui_test_utils::HideNativeWindow(window); |
| 237 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | 239 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
| 238 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 240 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 239 } | 241 } |
| 240 | 242 |
| 243 // This test is only for Linux Desktop. | |
| 244 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 245 #define MAYBE_BrowserDialogModalTest BrowserDialogModalTest | |
| 246 #else | |
| 247 #define MAYBE_BrowserDialogModalTest DISABLED_BrowserDialogModalTest | |
| 248 #endif | |
| 249 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_BrowserDialogModalTest) { | |
| 250 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 251 const GURL url = embedded_test_server()->GetURL(kSimplePage); | |
| 252 ui_test_utils::NavigateToURL(browser(), url); | |
| 253 ASSERT_TRUE(browser()->window()->IsActive()); | |
| 254 | |
| 255 browser()->OpenFile(); | |
| 256 | |
| 257 // Insert a delay to wait until the file-picker is opened and gets focus. | |
| 258 base::RunLoop run_loop; | |
| 259 base::MessageLoop::current()->PostDelayedTask( | |
| 260 FROM_HERE, run_loop.QuitClosure(), | |
| 261 base::TimeDelta::FromMilliseconds(1000)); | |
|
msw
2015/09/11 00:13:57
Hmm, hardcoded timeouts aren't good either; now th
joone
2015/09/11 23:37:12
The timeout was removed and a WidgetObserver was a
| |
| 262 run_loop.Run(); | |
| 263 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 264 | |
| 265 ClickOnView(VIEW_ID_TAB_CONTAINER); | |
| 266 // The window should not get focus due to modal dialog. | |
| 267 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 268 | |
| 269 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 270 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 271 | |
| 272 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
| 273 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | |
| 274 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 275 | |
| 276 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 277 browser(), ui::VKEY_TAB, false, false, true, false)); | |
| 278 EXPECT_FALSE(browser()->window()->IsActive()); | |
| 279 } | |
| 280 | |
| 241 // Tabs remember focus. | 281 // Tabs remember focus. |
| 242 // Disabled, http://crbug.com/62542. | 282 // Disabled, http://crbug.com/62542. |
| 243 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { | 283 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { |
| 244 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 284 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 245 const GURL url = embedded_test_server()->GetURL(kSimplePage); | 285 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 246 ui_test_utils::NavigateToURL(browser(), url); | 286 ui_test_utils::NavigateToURL(browser(), url); |
| 247 | 287 |
| 248 // Create several tabs. | 288 // Create several tabs. |
| 249 for (int i = 0; i < 4; ++i) { | 289 for (int i = 0; i < 4; ++i) { |
| 250 chrome::AddSelectedTabWithURL(browser(), url, | 290 chrome::AddSelectedTabWithURL(browser(), url, |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 742 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 703 content::NotificationService::AllSources()); | 743 content::NotificationService::AllSources()); |
| 704 chrome::GoForward(browser(), CURRENT_TAB); | 744 chrome::GoForward(browser(), CURRENT_TAB); |
| 705 forward_nav_observer.Wait(); | 745 forward_nav_observer.Wait(); |
| 706 } | 746 } |
| 707 | 747 |
| 708 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 748 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 709 } | 749 } |
| 710 | 750 |
| 711 } // namespace | 751 } // namespace |
| OLD | NEW |