| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/test/base/interactive_test_utils.h" | 30 #include "chrome/test/base/interactive_test_utils.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "content/public/browser/interstitial_page.h" | 32 #include "content/public/browser/interstitial_page.h" |
| 33 #include "content/public/browser/interstitial_page_delegate.h" | 33 #include "content/public/browser/interstitial_page_delegate.h" |
| 34 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
| 36 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 38 #include "content/public/browser/web_contents_view.h" | 38 #include "content/public/browser/web_contents_view.h" |
| 39 #include "content/public/test/browser_test_utils.h" | 39 #include "content/public/test/browser_test_utils.h" |
| 40 #include "net/test/spawned_test_server/spawned_test_server.h" | 40 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 41 | 41 |
| 42 #if defined(TOOLKIT_VIEWS) | 42 #if defined(TOOLKIT_VIEWS) |
| 43 #include "chrome/browser/ui/views/frame/browser_view.h" | 43 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 44 #include "ui/views/focus/focus_manager.h" | 44 #include "ui/views/focus/focus_manager.h" |
| 45 #include "ui/views/view.h" | 45 #include "ui/views/view.h" |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 49 #include <windows.h> | 49 #include <windows.h> |
| 50 #include <Psapi.h> | 50 #include <Psapi.h> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 | 80 |
| 81 namespace { | 81 namespace { |
| 82 | 82 |
| 83 // The delay waited in some cases where we don't have a notifications for an | 83 // The delay waited in some cases where we don't have a notifications for an |
| 84 // action we take. | 84 // action we take. |
| 85 const int kActionDelayMs = 500; | 85 const int kActionDelayMs = 500; |
| 86 | 86 |
| 87 // Maxiumum time to wait until the focus is moved to expected view. | 87 // Maxiumum time to wait until the focus is moved to expected view. |
| 88 const int kFocusChangeTimeoutMs = 500; | 88 const int kFocusChangeTimeoutMs = 500; |
| 89 | 89 |
| 90 const char kSimplePage[] = "files/focus/page_with_focus.html"; | 90 const char kSimplePage[] = "/focus/page_with_focus.html"; |
| 91 const char kStealFocusPage[] = "files/focus/page_steals_focus.html"; | 91 const char kStealFocusPage[] = "/focus/page_steals_focus.html"; |
| 92 const char kTypicalPage[] = "files/focus/typical_page.html"; | 92 const char kTypicalPage[] = "/focus/typical_page.html"; |
| 93 const char kTypicalPageName[] = "typical_page.html"; | 93 const char kTypicalPageName[] = "typical_page.html"; |
| 94 | 94 |
| 95 // Test to make sure Chrome is in the foreground as we start testing. This is | 95 // Test to make sure Chrome is in the foreground as we start testing. This is |
| 96 // required for tests that synthesize input to the Chrome window. | 96 // required for tests that synthesize input to the Chrome window. |
| 97 bool ChromeInForeground() { | 97 bool ChromeInForeground() { |
| 98 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 99 HWND window = ::GetForegroundWindow(); | 99 HWND window = ::GetForegroundWindow(); |
| 100 std::wstring caption; | 100 std::wstring caption; |
| 101 std::wstring filename; | 101 std::wstring filename; |
| 102 int len = ::GetWindowTextLength(window) + 1; | 102 int len = ::GetWindowTextLength(window) + 1; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 ClickOnView(VIEW_ID_TAB_CONTAINER); | 231 ClickOnView(VIEW_ID_TAB_CONTAINER); |
| 232 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 232 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 233 | 233 |
| 234 ClickOnView(VIEW_ID_OMNIBOX); | 234 ClickOnView(VIEW_ID_OMNIBOX); |
| 235 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 235 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Flaky, http://crbug.com/69034. | 238 // Flaky, http://crbug.com/69034. |
| 239 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { | 239 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { |
| 240 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 240 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 241 ASSERT_TRUE(test_server()->Start()); | 241 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 242 | 242 |
| 243 // First we navigate to our test page. | 243 // First we navigate to our test page. |
| 244 GURL url = test_server()->GetURL(kSimplePage); | 244 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 245 ui_test_utils::NavigateToURL(browser(), url); | 245 ui_test_utils::NavigateToURL(browser(), url); |
| 246 | 246 |
| 247 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 247 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| 248 | 248 |
| 249 // The focus should be on the Tab contents. | 249 // The focus should be on the Tab contents. |
| 250 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 250 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 251 // Now hide the window, show it again, the focus should not have changed. | 251 // Now hide the window, show it again, the focus should not have changed. |
| 252 ui_test_utils::HideNativeWindow(window); | 252 ui_test_utils::HideNativeWindow(window); |
| 253 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); | 253 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); |
| 254 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 254 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 // Close the 2nd browser to avoid a DCHECK(). | 301 // Close the 2nd browser to avoid a DCHECK(). |
| 302 browser_view2->Close(); | 302 browser_view2->Close(); |
| 303 #endif | 303 #endif |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Tabs remember focus. | 306 // Tabs remember focus. |
| 307 // Disabled, http://crbug.com/62542. | 307 // Disabled, http://crbug.com/62542. |
| 308 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { | 308 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { |
| 309 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 309 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 310 ASSERT_TRUE(test_server()->Start()); | 310 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 311 | 311 |
| 312 // First we navigate to our test page. | 312 // First we navigate to our test page. |
| 313 GURL url = test_server()->GetURL(kSimplePage); | 313 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 314 ui_test_utils::NavigateToURL(browser(), url); | 314 ui_test_utils::NavigateToURL(browser(), url); |
| 315 | 315 |
| 316 // Create several tabs. | 316 // Create several tabs. |
| 317 for (int i = 0; i < 4; ++i) { | 317 for (int i = 0; i < 4; ++i) { |
| 318 chrome::AddSelectedTabWithURL(browser(), url, | 318 chrome::AddSelectedTabWithURL(browser(), url, |
| 319 content::PAGE_TRANSITION_TYPED); | 319 content::PAGE_TRANSITION_TYPED); |
| 320 } | 320 } |
| 321 | 321 |
| 322 // Alternate focus for the tab. | 322 // Alternate focus for the tab. |
| 323 const bool kFocusPage[3][5] = { | 323 const bool kFocusPage[3][5] = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 369 |
| 370 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 370 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 371 browser(), ui::VKEY_TAB, true, true, false, false)); | 371 browser(), ui::VKEY_TAB, true, true, false, false)); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 // Tabs remember focus with find-in-page box. | 376 // Tabs remember focus with find-in-page box. |
| 377 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { | 377 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { |
| 378 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 378 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 379 ASSERT_TRUE(test_server()->Start()); | 379 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 380 | 380 |
| 381 // First we navigate to our test page. | 381 // First we navigate to our test page. |
| 382 GURL url = test_server()->GetURL(kSimplePage); | 382 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 383 ui_test_utils::NavigateToURL(browser(), url); | 383 ui_test_utils::NavigateToURL(browser(), url); |
| 384 | 384 |
| 385 chrome::Find(browser()); | 385 chrome::Find(browser()); |
| 386 ui_test_utils::FindInPage( | 386 ui_test_utils::FindInPage( |
| 387 browser()->tab_strip_model()->GetActiveWebContents(), | 387 browser()->tab_strip_model()->GetActiveWebContents(), |
| 388 ASCIIToUTF16("a"), true, false, NULL, NULL); | 388 ASCIIToUTF16("a"), true, false, NULL, NULL); |
| 389 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 389 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 390 | 390 |
| 391 // Focus the location bar. | 391 // Focus the location bar. |
| 392 chrome::FocusLocationBar(browser()); | 392 chrome::FocusLocationBar(browser()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 410 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 410 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 411 browser()->tab_strip_model()->ActivateTabAt(0, true); | 411 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 412 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 412 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // Background window does not steal focus. | 415 // Background window does not steal focus. |
| 416 // Flaky, http://crbug.com/62538. | 416 // Flaky, http://crbug.com/62538. |
| 417 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, | 417 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, |
| 418 DISABLED_BackgroundBrowserDontStealFocus) { | 418 DISABLED_BackgroundBrowserDontStealFocus) { |
| 419 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 419 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 420 ASSERT_TRUE(test_server()->Start()); | 420 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 421 | 421 |
| 422 // Open a new browser window. | 422 // Open a new browser window. |
| 423 Browser* browser2 = | 423 Browser* browser2 = |
| 424 new Browser(Browser::CreateParams(browser()->profile(), | 424 new Browser(Browser::CreateParams(browser()->profile(), |
| 425 browser()->host_desktop_type())); | 425 browser()->host_desktop_type())); |
| 426 ASSERT_TRUE(browser2); | 426 ASSERT_TRUE(browser2); |
| 427 chrome::AddBlankTabAt(browser2, -1, true); | 427 chrome::AddBlankTabAt(browser2, -1, true); |
| 428 browser2->window()->Show(); | 428 browser2->window()->Show(); |
| 429 | 429 |
| 430 Browser* focused_browser = NULL; | 430 Browser* focused_browser = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 443 } | 443 } |
| 444 #elif defined(OS_WIN) | 444 #elif defined(OS_WIN) |
| 445 focused_browser = browser(); | 445 focused_browser = browser(); |
| 446 unfocused_browser = browser2; | 446 unfocused_browser = browser2; |
| 447 #elif defined(OS_MACOSX) | 447 #elif defined(OS_MACOSX) |
| 448 // On Mac, the newly created window always gets the focus. | 448 // On Mac, the newly created window always gets the focus. |
| 449 focused_browser = browser2; | 449 focused_browser = browser2; |
| 450 unfocused_browser = browser(); | 450 unfocused_browser = browser(); |
| 451 #endif | 451 #endif |
| 452 | 452 |
| 453 GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); | 453 GURL steal_focus_url = embedded_test_server()->GetURL(kStealFocusPage); |
| 454 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); | 454 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); |
| 455 | 455 |
| 456 // Activate the first browser. | 456 // Activate the first browser. |
| 457 focused_browser->window()->Activate(); | 457 focused_browser->window()->Activate(); |
| 458 | 458 |
| 459 ASSERT_TRUE(content::ExecuteScript( | 459 ASSERT_TRUE(content::ExecuteScript( |
| 460 unfocused_browser->tab_strip_model()->GetActiveWebContents(), | 460 unfocused_browser->tab_strip_model()->GetActiveWebContents(), |
| 461 "stealFocus();")); | 461 "stealFocus();")); |
| 462 | 462 |
| 463 // Make sure the first browser is still active. | 463 // Make sure the first browser is still active. |
| 464 EXPECT_TRUE(focused_browser->window()->IsActive()); | 464 EXPECT_TRUE(focused_browser->window()->IsActive()); |
| 465 } | 465 } |
| 466 | 466 |
| 467 // Page cannot steal focus when focus is on location bar. | 467 // Page cannot steal focus when focus is on location bar. |
| 468 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { | 468 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { |
| 469 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 469 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 470 ASSERT_TRUE(test_server()->Start()); | 470 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 471 | 471 |
| 472 // Open the page that steals focus. | 472 // Open the page that steals focus. |
| 473 GURL url = test_server()->GetURL(kStealFocusPage); | 473 GURL url = embedded_test_server()->GetURL(kStealFocusPage); |
| 474 ui_test_utils::NavigateToURL(browser(), url); | 474 ui_test_utils::NavigateToURL(browser(), url); |
| 475 | 475 |
| 476 chrome::FocusLocationBar(browser()); | 476 chrome::FocusLocationBar(browser()); |
| 477 | 477 |
| 478 ASSERT_TRUE(content::ExecuteScript( | 478 ASSERT_TRUE(content::ExecuteScript( |
| 479 browser()->tab_strip_model()->GetActiveWebContents(), | 479 browser()->tab_strip_model()->GetActiveWebContents(), |
| 480 "stealFocus();")); | 480 "stealFocus();")); |
| 481 | 481 |
| 482 // Make sure the location bar is still focused. | 482 // Make sure the location bar is still focused. |
| 483 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 483 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 484 } | 484 } |
| 485 | 485 |
| 486 // Focus traversal on a regular page. | 486 // Focus traversal on a regular page. |
| 487 // Note that this test relies on a notification from the renderer that the | 487 // Note that this test relies on a notification from the renderer that the |
| 488 // focus has changed in the page. The notification in the renderer may change | 488 // focus has changed in the page. The notification in the renderer may change |
| 489 // at which point this test would fail (see comment in | 489 // at which point this test would fail (see comment in |
| 490 // RenderWidget::didFocus()). | 490 // RenderWidget::didFocus()). |
| 491 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { | 491 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { |
| 492 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 492 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 493 ASSERT_TRUE(test_server()->Start()); | 493 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 494 | 494 |
| 495 // First we navigate to our test page. | 495 // First we navigate to our test page. |
| 496 GURL url = test_server()->GetURL(kTypicalPage); | 496 GURL url = embedded_test_server()->GetURL(kTypicalPage); |
| 497 ui_test_utils::NavigateToURL(browser(), url); | 497 ui_test_utils::NavigateToURL(browser(), url); |
| 498 | 498 |
| 499 chrome::FocusLocationBar(browser()); | 499 chrome::FocusLocationBar(browser()); |
| 500 | 500 |
| 501 const char* kTextElementID = "textEdit"; | 501 const char* kTextElementID = "textEdit"; |
| 502 const char* kExpElementIDs[] = { | 502 const char* kExpElementIDs[] = { |
| 503 "", // Initially no element in the page should be focused | 503 "", // Initially no element in the page should be focused |
| 504 // (the location bar is focused). | 504 // (the location bar is focused). |
| 505 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", | 505 kTextElementID, "searchButton", "luckyButton", "googleLink", "gmailLink", |
| 506 "gmapLink" | 506 "gmapLink" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 // At this point the renderer has sent us a message asking to advance the | 605 // At this point the renderer has sent us a message asking to advance the |
| 606 // focus (as the end of the focus loop was reached in the renderer). | 606 // focus (as the end of the focus loop was reached in the renderer). |
| 607 // We need to run the message loop to process it. | 607 // We need to run the message loop to process it. |
| 608 content::RunAllPendingInMessageLoop(); | 608 content::RunAllPendingInMessageLoop(); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 // Focus traversal while an interstitial is showing. | 612 // Focus traversal while an interstitial is showing. |
| 613 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { | 613 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { |
| 614 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 614 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 615 ASSERT_TRUE(test_server()->Start()); | 615 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 616 | 616 |
| 617 // First we navigate to our test page. | 617 // First we navigate to our test page. |
| 618 GURL url = test_server()->GetURL(kSimplePage); | 618 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 619 ui_test_utils::NavigateToURL(browser(), url); | 619 ui_test_utils::NavigateToURL(browser(), url); |
| 620 | 620 |
| 621 // Focus should be on the page. | 621 // Focus should be on the page. |
| 622 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 622 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 623 | 623 |
| 624 // Let's show an interstitial. | 624 // Let's show an interstitial. |
| 625 TestInterstitialPage* interstitial_page = new TestInterstitialPage( | 625 TestInterstitialPage* interstitial_page = new TestInterstitialPage( |
| 626 browser()->tab_strip_model()->GetActiveWebContents(), | 626 browser()->tab_strip_model()->GetActiveWebContents(), |
| 627 true, GURL("http://interstitial.com")); | 627 true, GURL("http://interstitial.com")); |
| 628 // Give some time for the interstitial to show. | 628 // Give some time for the interstitial to show. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 // focus (as the end of the focus loop was reached in the renderer). | 725 // focus (as the end of the focus loop was reached in the renderer). |
| 726 // We need to run the message loop to process it. | 726 // We need to run the message loop to process it. |
| 727 content::RunAllPendingInMessageLoop(); | 727 content::RunAllPendingInMessageLoop(); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 | 730 |
| 731 // Focus stays on page with interstitials. | 731 // Focus stays on page with interstitials. |
| 732 // http://crbug.com/81451 | 732 // http://crbug.com/81451 |
| 733 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_InterstitialFocus) { | 733 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_InterstitialFocus) { |
| 734 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 734 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 735 ASSERT_TRUE(test_server()->Start()); | 735 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 736 | 736 |
| 737 // First we navigate to our test page. | 737 // First we navigate to our test page. |
| 738 GURL url = test_server()->GetURL(kSimplePage); | 738 GURL url = embedded_test_server()->GetURL(kSimplePage); |
| 739 ui_test_utils::NavigateToURL(browser(), url); | 739 ui_test_utils::NavigateToURL(browser(), url); |
| 740 | 740 |
| 741 // Page should have focus. | 741 // Page should have focus. |
| 742 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 742 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 743 EXPECT_TRUE(browser()->tab_strip_model()->GetActiveWebContents()-> | 743 EXPECT_TRUE(browser()->tab_strip_model()->GetActiveWebContents()-> |
| 744 GetRenderViewHost()->GetView()->HasFocus()); | 744 GetRenderViewHost()->GetView()->HasFocus()); |
| 745 | 745 |
| 746 // Let's show an interstitial. | 746 // Let's show an interstitial. |
| 747 TestInterstitialPage* interstitial_page = new TestInterstitialPage( | 747 TestInterstitialPage* interstitial_page = new TestInterstitialPage( |
| 748 browser()->tab_strip_model()->GetActiveWebContents(), | 748 browser()->tab_strip_model()->GetActiveWebContents(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 762 interstitial_page->DontProceed(); | 762 interstitial_page->DontProceed(); |
| 763 | 763 |
| 764 // Focus should be back on the original page. | 764 // Focus should be back on the original page. |
| 765 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 765 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 766 } | 766 } |
| 767 | 767 |
| 768 // Make sure Find box can request focus, even when it is already open. | 768 // Make sure Find box can request focus, even when it is already open. |
| 769 // Disabled due to flakiness. http://crbug.com/67301. | 769 // Disabled due to flakiness. http://crbug.com/67301. |
| 770 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FindFocusTest) { | 770 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FindFocusTest) { |
| 771 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 771 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 772 ASSERT_TRUE(test_server()->Start()); | 772 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 773 | 773 |
| 774 // Open some page (any page that doesn't steal focus). | 774 // Open some page (any page that doesn't steal focus). |
| 775 GURL url = test_server()->GetURL(kTypicalPage); | 775 GURL url = embedded_test_server()->GetURL(kTypicalPage); |
| 776 ui_test_utils::NavigateToURL(browser(), url); | 776 ui_test_utils::NavigateToURL(browser(), url); |
| 777 | 777 |
| 778 EXPECT_TRUE(ChromeInForeground()); | 778 EXPECT_TRUE(ChromeInForeground()); |
| 779 | 779 |
| 780 #if defined(OS_MACOSX) | 780 #if defined(OS_MACOSX) |
| 781 // Press Cmd+F, which will make the Find box open and request focus. | 781 // Press Cmd+F, which will make the Find box open and request focus. |
| 782 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 782 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 783 browser(), ui::VKEY_F, false, false, false, true)); | 783 browser(), ui::VKEY_F, false, false, false, true)); |
| 784 #else | 784 #else |
| 785 // Press Ctrl+F, which will make the Find box open and request focus. | 785 // Press Ctrl+F, which will make the Find box open and request focus. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), | 846 chrome::AddSelectedTabWithURL(browser(), GURL(content::kAboutBlankURL), |
| 847 content::PAGE_TRANSITION_LINK); | 847 content::PAGE_TRANSITION_LINK); |
| 848 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( | 848 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop( |
| 849 browser()->tab_strip_model()->GetActiveWebContents())); | 849 browser()->tab_strip_model()->GetActiveWebContents())); |
| 850 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 850 EXPECT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 851 } | 851 } |
| 852 | 852 |
| 853 // Tests that focus goes where expected when using reload. | 853 // Tests that focus goes where expected when using reload. |
| 854 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { | 854 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
| 855 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 855 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 856 ASSERT_TRUE(test_server()->Start()); | 856 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 857 | 857 |
| 858 // Open the new tab, reload. | 858 // Open the new tab, reload. |
| 859 { | 859 { |
| 860 content::WindowedNotificationObserver observer( | 860 content::WindowedNotificationObserver observer( |
| 861 content::NOTIFICATION_LOAD_STOP, | 861 content::NOTIFICATION_LOAD_STOP, |
| 862 content::NotificationService::AllSources()); | 862 content::NotificationService::AllSources()); |
| 863 chrome::NewTab(browser()); | 863 chrome::NewTab(browser()); |
| 864 observer.Wait(); | 864 observer.Wait(); |
| 865 } | 865 } |
| 866 content::RunAllPendingInMessageLoop(); | 866 content::RunAllPendingInMessageLoop(); |
| 867 | 867 |
| 868 { | 868 { |
| 869 content::WindowedNotificationObserver observer( | 869 content::WindowedNotificationObserver observer( |
| 870 content::NOTIFICATION_LOAD_STOP, | 870 content::NOTIFICATION_LOAD_STOP, |
| 871 content::Source<NavigationController>( | 871 content::Source<NavigationController>( |
| 872 &browser()->tab_strip_model()->GetActiveWebContents()-> | 872 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 873 GetController())); | 873 GetController())); |
| 874 chrome::Reload(browser(), CURRENT_TAB); | 874 chrome::Reload(browser(), CURRENT_TAB); |
| 875 observer.Wait(); | 875 observer.Wait(); |
| 876 } | 876 } |
| 877 // Focus should stay on the location bar. | 877 // Focus should stay on the location bar. |
| 878 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 878 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 879 | 879 |
| 880 // Open a regular page, focus the location bar, reload. | 880 // Open a regular page, focus the location bar, reload. |
| 881 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); | 881 ui_test_utils::NavigateToURL(browser(), |
| 882 embedded_test_server()->GetURL(kSimplePage)); |
| 882 chrome::FocusLocationBar(browser()); | 883 chrome::FocusLocationBar(browser()); |
| 883 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); | 884 ASSERT_TRUE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 884 { | 885 { |
| 885 content::WindowedNotificationObserver observer( | 886 content::WindowedNotificationObserver observer( |
| 886 content::NOTIFICATION_LOAD_STOP, | 887 content::NOTIFICATION_LOAD_STOP, |
| 887 content::Source<NavigationController>( | 888 content::Source<NavigationController>( |
| 888 &browser()->tab_strip_model()->GetActiveWebContents()-> | 889 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 889 GetController())); | 890 GetController())); |
| 890 chrome::Reload(browser(), CURRENT_TAB); | 891 chrome::Reload(browser(), CURRENT_TAB); |
| 891 observer.Wait(); | 892 observer.Wait(); |
| 892 } | 893 } |
| 893 | 894 |
| 894 // Focus should now be on the tab contents. | 895 // Focus should now be on the tab contents. |
| 895 chrome::ShowDownloads(browser()); | 896 chrome::ShowDownloads(browser()); |
| 896 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); | 897 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); |
| 897 } | 898 } |
| 898 | 899 |
| 899 // Tests that focus goes where expected when using reload on a crashed tab. | 900 // Tests that focus goes where expected when using reload on a crashed tab. |
| 900 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { | 901 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { |
| 901 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 902 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 902 ASSERT_TRUE(test_server()->Start()); | 903 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 903 | 904 |
| 904 // Open a regular page, crash, reload. | 905 // Open a regular page, crash, reload. |
| 905 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); | 906 ui_test_utils::NavigateToURL(browser(), |
| 907 embedded_test_server()->GetURL(kSimplePage)); |
| 906 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); | 908 content::CrashTab(browser()->tab_strip_model()->GetActiveWebContents()); |
| 907 { | 909 { |
| 908 content::WindowedNotificationObserver observer( | 910 content::WindowedNotificationObserver observer( |
| 909 content::NOTIFICATION_LOAD_STOP, | 911 content::NOTIFICATION_LOAD_STOP, |
| 910 content::Source<NavigationController>( | 912 content::Source<NavigationController>( |
| 911 &browser()->tab_strip_model()->GetActiveWebContents()-> | 913 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 912 GetController())); | 914 GetController())); |
| 913 chrome::Reload(browser(), CURRENT_TAB); | 915 chrome::Reload(browser(), CURRENT_TAB); |
| 914 observer.Wait(); | 916 observer.Wait(); |
| 915 } | 917 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 990 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 989 content::NotificationService::AllSources()); | 991 content::NotificationService::AllSources()); |
| 990 chrome::GoForward(browser(), CURRENT_TAB); | 992 chrome::GoForward(browser(), CURRENT_TAB); |
| 991 forward_nav_observer.Wait(); | 993 forward_nav_observer.Wait(); |
| 992 } | 994 } |
| 993 | 995 |
| 994 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); | 996 EXPECT_FALSE(IsViewFocused(VIEW_ID_OMNIBOX)); |
| 995 } | 997 } |
| 996 | 998 |
| 997 } // namespace | 999 } // namespace |
| OLD | NEW |