OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 BringBrowserWindowToFront(); | 254 BringBrowserWindowToFront(); |
255 net::HTTPTestServer* server = StartHTTPServer(); | 255 net::HTTPTestServer* server = StartHTTPServer(); |
256 ASSERT_TRUE(server); | 256 ASSERT_TRUE(server); |
257 | 257 |
258 // First we navigate to our test page. | 258 // First we navigate to our test page. |
259 GURL url = server->TestServerPage(kSimplePage); | 259 GURL url = server->TestServerPage(kSimplePage); |
260 ui_test_utils::NavigateToURL(browser(), url); | 260 ui_test_utils::NavigateToURL(browser(), url); |
261 | 261 |
262 // Create several tabs. | 262 // Create several tabs. |
263 for (int i = 0; i < 4; ++i) { | 263 for (int i = 0; i < 4; ++i) { |
| 264 Browser* browser_used = NULL; |
264 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 265 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
265 TabStripModel::ADD_SELECTED, NULL, std::string()); | 266 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 267 &browser_used); |
| 268 EXPECT_EQ(browser(), browser_used); |
266 } | 269 } |
267 | 270 |
268 // Alternate focus for the tab. | 271 // Alternate focus for the tab. |
269 const bool kFocusPage[3][5] = { | 272 const bool kFocusPage[3][5] = { |
270 { true, true, true, true, false }, | 273 { true, true, true, true, false }, |
271 { false, false, false, false, false }, | 274 { false, false, false, false, false }, |
272 { false, true, false, true, false } | 275 { false, true, false, true, false } |
273 }; | 276 }; |
274 | 277 |
275 for (int i = 1; i < 3; i++) { | 278 for (int i = 1; i < 3; i++) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 340 |
338 browser()->Find(); | 341 browser()->Find(); |
339 ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), | 342 ui_test_utils::FindInPage(browser()->GetSelectedTabContents(), |
340 ASCIIToUTF16("a"), true, false, NULL); | 343 ASCIIToUTF16("a"), true, false, NULL); |
341 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); | 344 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); |
342 | 345 |
343 // Focus the location bar. | 346 // Focus the location bar. |
344 browser()->FocusLocationBar(); | 347 browser()->FocusLocationBar(); |
345 | 348 |
346 // Create a 2nd tab. | 349 // Create a 2nd tab. |
| 350 Browser* browser_used = NULL; |
347 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, | 351 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, -1, |
348 TabStripModel::ADD_SELECTED, NULL, std::string()); | 352 TabStripModel::ADD_SELECTED, NULL, std::string(), |
| 353 &browser_used); |
| 354 EXPECT_EQ(browser(), browser_used); |
349 | 355 |
350 // Focus should be on the recently opened tab page. | 356 // Focus should be on the recently opened tab page. |
351 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 357 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
352 | 358 |
353 // Select 1st tab, focus should still be on the location-bar. | 359 // Select 1st tab, focus should still be on the location-bar. |
354 // (bug http://crbug.com/23296) | 360 // (bug http://crbug.com/23296) |
355 browser()->SelectTabContentsAt(0, true); | 361 browser()->SelectTabContentsAt(0, true); |
356 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 362 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
357 | 363 |
358 // Now open the find box again, switch to another tab and come back, the focus | 364 // Now open the find box again, switch to another tab and come back, the focus |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 browser()->NewTab(); | 764 browser()->NewTab(); |
759 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 765 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
760 | 766 |
761 // Open the download tab, focus should be on the tab contents. | 767 // Open the download tab, focus should be on the tab contents. |
762 browser()->ShowDownloadsTab(); | 768 browser()->ShowDownloadsTab(); |
763 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 769 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
764 | 770 |
765 // Open about:blank, focus should be on the location bar. | 771 // Open about:blank, focus should be on the location bar. |
766 browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK, | 772 browser()->AddTabWithURL(GURL("about:blank"), GURL(), PageTransition::LINK, |
767 -1, TabStripModel::ADD_SELECTED, NULL, | 773 -1, TabStripModel::ADD_SELECTED, NULL, |
768 std::string()); | 774 std::string(), |
| 775 NULL); |
769 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 776 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
770 } | 777 } |
771 | 778 |
772 // Tests that focus goes where expected when using reload. | 779 // Tests that focus goes where expected when using reload. |
773 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { | 780 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { |
774 BringBrowserWindowToFront(); | 781 BringBrowserWindowToFront(); |
775 net::HTTPTestServer* server = StartHTTPServer(); | 782 net::HTTPTestServer* server = StartHTTPServer(); |
776 ASSERT_TRUE(server); | 783 ASSERT_TRUE(server); |
777 | 784 |
778 // Open the new tab, reload. | 785 // Open the new tab, reload. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 822 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
816 browser()->Reload(CURRENT_TAB); | 823 browser()->Reload(CURRENT_TAB); |
817 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 824 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
818 | 825 |
819 // Focus should now be on the tab contents. | 826 // Focus should now be on the tab contents. |
820 browser()->ShowDownloadsTab(); | 827 browser()->ShowDownloadsTab(); |
821 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 828 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
822 } | 829 } |
823 | 830 |
824 } // namespace | 831 } // namespace |
OLD | NEW |