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 "chrome/browser/browser_list.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/browser_window.h" | |
7 #include "chrome/browser/profile.h" | 6 #include "chrome/browser/profile.h" |
8 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
9 #include "chrome/browser/tab_contents/tab_contents_view.h" | 8 #include "chrome/browser/tab_contents/tab_contents_view.h" |
10 #include "chrome/browser/tabs/tab_strip_model.h" | 9 #include "chrome/browser/tabs/tab_strip_model.h" |
11 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
| 13 #include "chrome/browser/ui/browser_window.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_paths| = true opens a new tab navigated to the specified URL if n
o |
| 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(2, browser()->tab_count()); |
| 484 EXPECT_EQ(1, browser()->selected_index()); |
| 485 |
| 486 // Navigate to a new singleton tab with a sub-page. |
| 487 browser::NavigateParams p(MakeNavigateParams()); |
| 488 p.disposition = SINGLETON_TAB; |
| 489 p.url = GURL("chrome://settings/advanced"); |
| 490 p.show_window = true; |
| 491 p.ignore_path = true; |
| 492 browser::Navigate(&p); |
| 493 |
| 494 // The last tab should now be selected and navigated to the sub-page of the |
| 495 // URL. |
| 496 EXPECT_EQ(browser(), p.browser); |
| 497 EXPECT_EQ(3, browser()->tab_count()); |
| 498 EXPECT_EQ(2, browser()->selected_index()); |
| 499 EXPECT_EQ(GURL("chrome://settings/advanced"), |
| 500 browser()->GetSelectedTabContents()->GetURL()); |
| 501 } |
| 502 |
| 503 // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 504 // and |ignore_paths| = true opens an existing tab with the matching URL (minus |
| 505 // the path) which is navigated to the specified URL. |
| 506 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 507 Disposition_SingletonTabExisting_IgnorePath) { |
| 508 GURL singleton_url1("chrome://settings"); |
| 509 GURL url("http://www.google.com/"); |
| 510 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK); |
| 511 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 512 |
| 513 // We should have one browser with 3 tabs, the 3rd selected. |
| 514 EXPECT_EQ(1u, BrowserList::size()); |
| 515 EXPECT_EQ(3, browser()->tab_count()); |
| 516 EXPECT_EQ(2, browser()->selected_index()); |
| 517 |
| 518 // Navigate to singleton_url1. |
| 519 browser::NavigateParams p(MakeNavigateParams()); |
| 520 p.disposition = SINGLETON_TAB; |
| 521 p.url = GURL("chrome://settings/advanced"); |
| 522 p.show_window = true; |
| 523 p.ignore_path = true; |
| 524 browser::Navigate(&p); |
| 525 |
| 526 // The middle tab should now be selected and navigated to the sub-page of the |
| 527 // URL. |
| 528 EXPECT_EQ(browser(), p.browser); |
| 529 EXPECT_EQ(3, browser()->tab_count()); |
| 530 EXPECT_EQ(1, browser()->selected_index()); |
| 531 EXPECT_EQ(GURL("chrome://settings/advanced"), |
| 532 browser()->GetSelectedTabContents()->GetURL()); |
| 533 } |
| 534 |
| 535 // This test verifies that constructing params with disposition = SINGLETON_TAB |
| 536 // and |ignore_paths| = true opens an existing tab with the matching URL (minus |
| 537 // the path) which is navigated to the specified URL. |
| 538 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 539 Disposition_SingletonTabExistingSubPath_IgnorePath) { |
| 540 GURL singleton_url1("chrome://settings/advanced"); |
| 541 GURL url("http://www.google.com/"); |
| 542 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK); |
| 543 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); |
| 544 |
| 545 // We should have one browser with 3 tabs, the 3rd selected. |
| 546 EXPECT_EQ(1u, BrowserList::size()); |
| 547 EXPECT_EQ(3, browser()->tab_count()); |
| 548 EXPECT_EQ(2, browser()->selected_index()); |
| 549 |
| 550 // Navigate to singleton_url1. |
| 551 browser::NavigateParams p(MakeNavigateParams()); |
| 552 p.disposition = SINGLETON_TAB; |
| 553 p.url = GURL("chrome://settings/personal"); |
| 554 p.show_window = true; |
| 555 p.ignore_path = true; |
| 556 browser::Navigate(&p); |
| 557 |
| 558 // The middle tab should now be selected and navigated to the sub-page of the |
| 559 // URL. |
| 560 EXPECT_EQ(browser(), p.browser); |
| 561 EXPECT_EQ(3, browser()->tab_count()); |
| 562 EXPECT_EQ(1, browser()->selected_index()); |
| 563 EXPECT_EQ(GURL("chrome://settings/personal"), |
| 564 browser()->GetSelectedTabContents()->GetURL()); |
| 565 } |
466 | 566 |
467 } // namespace | 567 } // namespace |
OLD | NEW |