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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 ASSERT_TRUE(IsViewFocused(vid)); | 324 ASSERT_TRUE(IsViewFocused(vid)); |
| 325 | 325 |
| 326 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 326 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 327 browser(), ui::VKEY_TAB, true, true, false, false)); | 327 browser(), ui::VKEY_TAB, true, true, false, false)); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 // Tabs remember focus with find-in-page box. | 332 // Tabs remember focus with find-in-page box. |
| 333 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocusFindInPage) { | 333 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocusFindInPage) { |
| 334 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 335 ui_test_utils::BrowserActivationWaiter waiter(browser()); | |
| 336 waiter.WaitForActivation(); | |
| 337 const GURL url = embedded_test_server()->GetURL(kSimplePage); | 334 const GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 338 ui_test_utils::NavigateToURL(browser(), url); | 335 ui_test_utils::NavigateToURL(browser(), url); |
| 339 | 336 |
| 340 chrome::Find(browser()); | 337 chrome::Find(browser()); |
| 341 ui_test_utils::FindInPage( | 338 ui_test_utils::FindInPage( |
| 342 browser()->tab_strip_model()->GetActiveWebContents(), | 339 browser()->tab_strip_model()->GetActiveWebContents(), |
| 343 base::ASCIIToUTF16("a"), true, false, NULL, NULL); | 340 base::ASCIIToUTF16("a"), true, false, NULL, NULL); |
| 344 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 341 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 345 | 342 |
| 346 // Focus the location bar. | 343 // Focus the location bar. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 ASSERT_TRUE(content::ExecuteScript( | 409 ASSERT_TRUE(content::ExecuteScript( |
| 413 unfocused_browser->tab_strip_model()->GetActiveWebContents(), | 410 unfocused_browser->tab_strip_model()->GetActiveWebContents(), |
| 414 "stealFocus();")); | 411 "stealFocus();")); |
| 415 | 412 |
| 416 // Make sure the first browser is still active. | 413 // Make sure the first browser is still active. |
| 417 EXPECT_TRUE(focused_browser->window()->IsActive()); | 414 EXPECT_TRUE(focused_browser->window()->IsActive()); |
| 418 } | 415 } |
| 419 | 416 |
| 420 // Page cannot steal focus when focus is on location bar. | 417 // Page cannot steal focus when focus is on location bar. |
| 421 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { | 418 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
| 422 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 423 ui_test_utils::BrowserActivationWaiter waiter(browser()); | |
| 424 waiter.WaitForActivation(); | |
| 425 | |
| 426 // Open the page that steals focus. | 419 // Open the page that steals focus. |
| 427 const GURL url = embedded_test_server()->GetURL(kStealFocusPage); | 420 const GURL url = embedded_test_server()->GetURL(kStealFocusPage); |
| 428 ui_test_utils::NavigateToURL(browser(), url); | 421 ui_test_utils::NavigateToURL(browser(), url); |
| 429 | 422 |
| 430 chrome::FocusLocationBar(browser()); | 423 chrome::FocusLocationBar(browser()); |
| 431 | 424 |
| 432 ASSERT_TRUE(content::ExecuteScript( | 425 ASSERT_TRUE(content::ExecuteScript( |
| 433 browser()->tab_strip_model()->GetActiveWebContents(), | 426 browser()->tab_strip_model()->GetActiveWebContents(), |
| 434 "stealFocus();")); | 427 "stealFocus();")); |
| 435 | 428 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 // Open about:blank, focus should be on the location bar. | 548 // Open about:blank, focus should be on the location bar. |
| 556 chrome::AddSelectedTabWithURL( | 549 chrome::AddSelectedTabWithURL( |
| 557 browser(), GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_LINK); | 550 browser(), GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_LINK); |
| 558 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 551 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
| 559 browser()->tab_strip_model()->GetActiveWebContents())); | 552 browser()->tab_strip_model()->GetActiveWebContents())); |
| 560 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 553 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 561 } | 554 } |
| 562 | 555 |
| 563 // Tests that focus goes where expected when using reload. | 556 // Tests that focus goes where expected when using reload. |
| 564 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { | 557 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
| 565 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 566 ui_test_utils::BrowserActivationWaiter waiter(browser()); | |
| 567 waiter.WaitForActivation(); | |
| 568 | |
| 569 // Open the new tab, reload. | 558 // Open the new tab, reload. |
| 570 { | 559 { |
| 571 content::WindowedNotificationObserver observer( | 560 content::WindowedNotificationObserver observer( |
| 572 content::NOTIFICATION_LOAD_STOP, | 561 content::NOTIFICATION_LOAD_STOP, |
| 573 content::NotificationService::AllSources()); | 562 content::NotificationService::AllSources()); |
| 574 chrome::NewTab(browser()); | 563 chrome::NewTab(browser()); |
| 575 observer.Wait(); | 564 observer.Wait(); |
| 576 } | 565 } |
| 577 content::RunAllPendingInMessageLoop(); | 566 content::RunAllPendingInMessageLoop(); |
| 578 | 567 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 667 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 679 } | 668 } |
| 680 | 669 |
| 681 // Flaky on Windows (http://crbug.com/665296). | 670 // Flaky on Windows (http://crbug.com/665296). |
| 682 #if defined(OS_WIN) | 671 #if defined(OS_WIN) |
| 683 #define MAYBE_FocusOnNavigate DISABLED_FocusOnNavigate | 672 #define MAYBE_FocusOnNavigate DISABLED_FocusOnNavigate |
| 684 #else | 673 #else |
| 685 #define MAYBE_FocusOnNavigate FocusOnNavigate | 674 #define MAYBE_FocusOnNavigate FocusOnNavigate |
| 686 #endif | 675 #endif |
| 687 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusOnNavigate) { | 676 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusOnNavigate) { |
| 677 // Needed on Mac. | |
|
Qiang(Joe) Xu
2016/11/15 22:42:29
I didn't remove this, as it was there before: http
| |
| 688 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 678 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 689 ui_test_utils::BrowserActivationWaiter waiter(browser()); | |
| 690 waiter.WaitForActivation(); | |
| 691 | |
| 692 // Load the NTP. | 679 // Load the NTP. |
| 693 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 680 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 694 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 681 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 695 | 682 |
| 696 // Navigate to another page. | 683 // Navigate to another page. |
| 697 const base::FilePath::CharType* kEmptyFile = FILE_PATH_LITERAL("empty.html"); | 684 const base::FilePath::CharType* kEmptyFile = FILE_PATH_LITERAL("empty.html"); |
| 698 GURL file_url(ui_test_utils::GetTestUrl(base::FilePath( | 685 GURL file_url(ui_test_utils::GetTestUrl(base::FilePath( |
| 699 base::FilePath::kCurrentDirectory), base::FilePath(kEmptyFile))); | 686 base::FilePath::kCurrentDirectory), base::FilePath(kEmptyFile))); |
| 700 ui_test_utils::NavigateToURL(browser(), file_url); | 687 ui_test_utils::NavigateToURL(browser(), file_url); |
| 701 | 688 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 744 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); | 731 ASSERT_TRUE(content::ExecuteScript(web_contents, spoof)); |
| 745 EXPECT_EQ(url1, web_contents->GetVisibleURL()); | 732 EXPECT_EQ(url1, web_contents->GetVisibleURL()); |
| 746 // After running the spoof code, |GetActiveWebContents| returns the new tab, | 733 // After running the spoof code, |GetActiveWebContents| returns the new tab, |
| 747 // not the same as |web_contents|. | 734 // not the same as |web_contents|. |
| 748 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 735 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
| 749 browser()->tab_strip_model()->GetActiveWebContents())); | 736 browser()->tab_strip_model()->GetActiveWebContents())); |
| 750 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 737 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 751 } | 738 } |
| 752 | 739 |
| 753 } // namespace | 740 } // namespace |
| OLD | NEW |