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 "base/command_line.h" |
5 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
6 #include "chrome/browser/browser_list.h" | 7 #include "chrome/browser/browser_list.h" |
7 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
8 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
9 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
10 #include "chrome/browser/tab_contents/tab_contents_view.h" | 11 #include "chrome/browser/tab_contents/tab_contents_view.h" |
11 #include "chrome/browser/tabs/tab_strip_model.h" | 12 #include "chrome/browser/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/in_process_browser_test.h" | 15 #include "chrome/test/in_process_browser_test.h" |
14 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
15 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 class BrowserNavigatorTest : public InProcessBrowserTest { | 21 class BrowserNavigatorTest : public InProcessBrowserTest { |
20 protected: | 22 protected: |
21 GURL GetGoogleURL() const { | 23 GURL GetGoogleURL() const { |
22 return GURL("http://www.google.com/"); | 24 return GURL("http://www.google.com/"); |
(...skipping 27 matching lines...) Expand all Loading... |
50 GURL old_url = browser()->GetSelectedTabContents()->GetURL(); | 52 GURL old_url = browser()->GetSelectedTabContents()->GetURL(); |
51 browser::NavigateParams p(MakeNavigateParams()); | 53 browser::NavigateParams p(MakeNavigateParams()); |
52 p.disposition = disposition; | 54 p.disposition = disposition; |
53 browser::Navigate(&p); | 55 browser::Navigate(&p); |
54 | 56 |
55 // Nothing should have happened as a result of Navigate(); | 57 // Nothing should have happened as a result of Navigate(); |
56 EXPECT_EQ(1, browser()->tab_count()); | 58 EXPECT_EQ(1, browser()->tab_count()); |
57 EXPECT_EQ(1u, BrowserList::size()); | 59 EXPECT_EQ(1u, BrowserList::size()); |
58 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL()); | 60 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL()); |
59 } | 61 } |
| 62 |
| 63 // TODO(jhawkins): Remove once tabbed options are enabled by default. |
| 64 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 65 command_line->AppendSwitch(switches::kEnableTabbedOptions); |
| 66 } |
60 }; | 67 }; |
61 | 68 |
62 // This test verifies that when a navigation occurs within a tab, the tab count | 69 // This test verifies that when a navigation occurs within a tab, the tab count |
63 // of the Browser remains the same and the current tab bears the loaded URL. | 70 // of the Browser remains the same and the current tab bears the loaded URL. |
64 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { | 71 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { |
65 browser::NavigateParams p(MakeNavigateParams()); | 72 browser::NavigateParams p(MakeNavigateParams()); |
66 browser::Navigate(&p); | 73 browser::Navigate(&p); |
67 ui_test_utils::WaitForNavigationInCurrentTab(browser()); | 74 ui_test_utils::WaitForNavigationInCurrentTab(browser()); |
68 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL()); | 75 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL()); |
69 // We should have one window with one tab. | 76 // We should have one window with one tab. |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 EXPECT_NE(browser(), p.browser); | 463 EXPECT_NE(browser(), p.browser); |
457 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); | 464 EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); |
458 | 465 |
459 // We should now have two windows, the browser() provided by the framework and | 466 // We should now have two windows, the browser() provided by the framework and |
460 // the new normal window. | 467 // the new normal window. |
461 EXPECT_EQ(2u, BrowserList::size()); | 468 EXPECT_EQ(2u, BrowserList::size()); |
462 EXPECT_EQ(1, browser()->tab_count()); | 469 EXPECT_EQ(1, browser()->tab_count()); |
463 EXPECT_EQ(1, p.browser->tab_count()); | 470 EXPECT_EQ(1, p.browser->tab_count()); |
464 } | 471 } |
465 | 472 |
| 473 // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 474 // and |ignore_tabs| = true opens a new tab navigated to the specified URL if no |
| 475 // previous tab with that URL (minus the path) exists. |
| 476 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 477 Disposition_SingletonTabNew_IgnorePath) { |
| 478 GURL url("http://www.google.com/"); |
| 479 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 480 |
| 481 // We should have one browser with 2 tabs, the 2nd selected. |
| 482 EXPECT_EQ(1u, BrowserList::size()); |
| 483 EXPECT_EQ(1, browser()->selected_index()); |
| 484 |
| 485 // Navigate to a new singleton tab with a sub-page. |
| 486 browser::NavigateParams p(MakeNavigateParams()); |
| 487 p.disposition = SINGLETON_TAB; |
| 488 p.url = GURL("chrome://settings/advanced"); |
| 489 p.show_window = true; |
| 490 browser::Navigate(&p); |
| 491 |
| 492 // The last tab should now be selected and navigated to the sub-page of the |
| 493 // URL. |
| 494 EXPECT_EQ(browser(), p.browser); |
| 495 EXPECT_EQ(3, browser()->tab_count()); |
| 496 EXPECT_EQ(2, browser()->selected_index()); |
| 497 EXPECT_EQ(GURL("chrome://settings/advanced"), |
| 498 browser()->GetSelectedTabContents()->GetURL()); |
| 499 } |
| 500 |
| 501 // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 502 // and |ignore_tabs| = true opens an existing tab with the matching URL (minus |
| 503 // the path) which is navigated to the specified URL. |
| 504 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 505 Disposition_SingletonTabExisting_IgnorePath) { |
| 506 GURL singleton_url1("chrome://settings"); |
| 507 GURL url("http://www.google.com/"); |
| 508 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK); |
| 509 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 510 |
| 511 // We should have one browser with 3 tabs, the 3rd selected. |
| 512 EXPECT_EQ(1u, BrowserList::size()); |
| 513 EXPECT_EQ(2, browser()->selected_index()); |
| 514 |
| 515 // Navigate to singleton_url1. |
| 516 browser::NavigateParams p(MakeNavigateParams()); |
| 517 p.disposition = SINGLETON_TAB; |
| 518 p.url = GURL("chrome://settings/advanced"); |
| 519 p.show_window = true; |
| 520 browser::Navigate(&p); |
| 521 |
| 522 // The middle tab should now be selected and navigated to the sub-page of the |
| 523 // URL. |
| 524 EXPECT_EQ(browser(), p.browser); |
| 525 EXPECT_EQ(3, browser()->tab_count()); |
| 526 EXPECT_EQ(1, browser()->selected_index()); |
| 527 EXPECT_EQ(GURL("chrome://settings/advanced"), |
| 528 browser()->GetSelectedTabContents()->GetURL()); |
| 529 } |
| 530 |
| 531 // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 532 // and |ignore_tabs| = true opens an existing tab with the matching URL (minus |
| 533 // the path) which is navigated to the specified URL. |
| 534 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 535 Disposition_SingletonTabExistingSubPath_IgnorePath) { |
| 536 GURL singleton_url1("chrome://settings/advanced"); |
| 537 GURL url("http://www.google.com/"); |
| 538 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK); |
| 539 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 540 |
| 541 // We should have one browser with 3 tabs, the 3rd selected. |
| 542 EXPECT_EQ(1u, BrowserList::size()); |
| 543 EXPECT_EQ(2, browser()->selected_index()); |
| 544 |
| 545 // Navigate to singleton_url1. |
| 546 browser::NavigateParams p(MakeNavigateParams()); |
| 547 p.disposition = SINGLETON_TAB; |
| 548 p.url = GURL("chrome://settings/personal"); |
| 549 p.show_window = true; |
| 550 browser::Navigate(&p); |
| 551 |
| 552 // The middle tab should now be selected and navigated to the sub-page of the |
| 553 // URL. |
| 554 EXPECT_EQ(browser(), p.browser); |
| 555 EXPECT_EQ(3, browser()->tab_count()); |
| 556 EXPECT_EQ(1, browser()->selected_index()); |
| 557 EXPECT_EQ(GURL("chrome://settings/personal"), |
| 558 browser()->GetSelectedTabContents()->GetURL()); |
| 559 } |
466 | 560 |
467 } // namespace | 561 } // namespace |
OLD | NEW |