| Index: chrome/browser/ui/browser_navigator_browsertest.cc
|
| diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc
|
| index 3fdf22f023df6185f8741c2659885d45e5763aa0..53f613cba887c4e857c6cbee506d9aac80d49b3e 100644
|
| --- a/chrome/browser/ui/browser_navigator_browsertest.cc
|
| +++ b/chrome/browser/ui/browser_navigator_browsertest.cc
|
| @@ -2,81 +2,79 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "chrome/browser/ui/browser_navigator_browsertest.h"
|
| +
|
| #include "base/command_line.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/tab_contents/tab_contents.h"
|
| #include "chrome/browser/tab_contents/tab_contents_view.h"
|
| #include "chrome/browser/tabs/tab_strip_model.h"
|
| -#include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/browser/ui/browser_navigator.h"
|
| #include "chrome/browser/ui/browser_window.h"
|
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| #include "chrome/common/chrome_switches.h"
|
| -#include "chrome/test/in_process_browser_test.h"
|
| #include "chrome/test/ui_test_utils.h"
|
| #include "ipc/ipc_message.h"
|
|
|
| -namespace {
|
| +GURL BrowserNavigatorTest::GetGoogleURL() const {
|
| + return GURL("http://www.google.com/");
|
| +}
|
|
|
| -class BrowserNavigatorTest : public InProcessBrowserTest,
|
| - public NotificationObserver {
|
| - protected:
|
| - GURL GetGoogleURL() const {
|
| - return GURL("http://www.google.com/");
|
| - }
|
| +browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
|
| + return MakeNavigateParams(browser());
|
| +}
|
|
|
| - browser::NavigateParams MakeNavigateParams() const {
|
| - return MakeNavigateParams(browser());
|
| - }
|
| - browser::NavigateParams MakeNavigateParams(Browser* browser) const {
|
| - browser::NavigateParams params(browser, GetGoogleURL(),
|
| - PageTransition::LINK);
|
| - params.show_window = true;
|
| - return params;
|
| - }
|
| +browser::NavigateParams BrowserNavigatorTest::MakeNavigateParams(
|
| + Browser* browser) const {
|
| + browser::NavigateParams params(browser, GetGoogleURL(),
|
| + PageTransition::LINK);
|
| + params.show_window = true;
|
| + return params;
|
| +}
|
|
|
| - Browser* CreateEmptyBrowserForType(Browser::Type type, Profile* profile) {
|
| - Browser* browser = Browser::CreateForType(type, profile);
|
| - browser->AddBlankTab(true);
|
| - return browser;
|
| - }
|
| +Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
|
| + Profile* profile) {
|
| + Browser* browser = Browser::CreateForType(type, profile);
|
| + browser->AddBlankTab(true);
|
| + return browser;
|
| +}
|
|
|
| - TabContentsWrapper* CreateTabContents() {
|
| - return Browser::TabContentsFactory(
|
| - browser()->profile(),
|
| - NULL,
|
| - MSG_ROUTING_NONE,
|
| - browser()->GetSelectedTabContents(),
|
| - NULL);
|
| - }
|
| +TabContentsWrapper* BrowserNavigatorTest::CreateTabContents() {
|
| + return Browser::TabContentsFactory(
|
| + browser()->profile(),
|
| + NULL,
|
| + MSG_ROUTING_NONE,
|
| + browser()->GetSelectedTabContents(),
|
| + NULL);
|
| +}
|
|
|
| - void RunSuppressTest(WindowOpenDisposition disposition) {
|
| - GURL old_url = browser()->GetSelectedTabContents()->GetURL();
|
| - browser::NavigateParams p(MakeNavigateParams());
|
| - p.disposition = disposition;
|
| - browser::Navigate(&p);
|
| +void BrowserNavigatorTest::RunSuppressTest(WindowOpenDisposition disposition) {
|
| + GURL old_url = browser()->GetSelectedTabContents()->GetURL();
|
| + browser::NavigateParams p(MakeNavigateParams());
|
| + p.disposition = disposition;
|
| + browser::Navigate(&p);
|
|
|
| - // Nothing should have happened as a result of Navigate();
|
| - EXPECT_EQ(1, browser()->tab_count());
|
| - EXPECT_EQ(1u, BrowserList::size());
|
| - EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
|
| - }
|
| + // Nothing should have happened as a result of Navigate();
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + EXPECT_EQ(1u, BrowserList::size());
|
| + EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL());
|
| +}
|
|
|
| - void Observe(NotificationType type, const NotificationSource& source,
|
| - const NotificationDetails& details) {
|
| - switch (type.value) {
|
| - case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: {
|
| - ++this->created_tab_contents_count_;
|
| - break;
|
| - }
|
| - default:
|
| - break;
|
| +void BrowserNavigatorTest::Observe(NotificationType type,
|
| + const NotificationSource& source,
|
| + const NotificationDetails& details) {
|
| + switch (type.value) {
|
| + case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: {
|
| + ++this->created_tab_contents_count_;
|
| + break;
|
| }
|
| + default:
|
| + break;
|
| }
|
| +}
|
|
|
| - size_t created_tab_contents_count_;
|
| -};
|
| +namespace {
|
|
|
| // This test verifies that when a navigation occurs within a tab, the tab count
|
| // of the Browser remains the same and the current tab bears the loaded URL.
|
| @@ -90,14 +88,14 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
|
| EXPECT_EQ(1, browser()->tab_count());
|
| }
|
|
|
| -// This test verifies that a singleton tab is refocused if one is already open
|
| +// This test verifies that a singleton tab is refocused if one is already opened
|
| // in another or an existing window, or added if it is not.
|
| IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
|
| GURL url("http://www.google.com/");
|
| GURL singleton_url1("http://maps.google.com/");
|
|
|
| // Register for a notification if an additional tab_contents was instantiated.
|
| - // Opening a Singleton tab that is already open should not be opening a new
|
| + // Opening a Singleton tab that is already opened should not be opening a new
|
| // tab nor be creating a new TabContents object
|
| NotificationRegistrar registrar;
|
|
|
| @@ -135,7 +133,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
|
| GURL url("http://www.google.com/");
|
| GURL singleton_url1("http://maps.google.com/");
|
|
|
| - // We should have one browser with 3 tabs, the 3rd selected.
|
| + // We should have one browser with 1 tab.
|
| EXPECT_EQ(1u, BrowserList::size());
|
| EXPECT_EQ(0, browser()->selected_index());
|
|
|
| @@ -681,4 +679,56 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
|
| browser()->GetSelectedTabContents()->GetURL());
|
| }
|
|
|
| +// This test verifies that the settings page isn't opened in the incognito
|
| +// window.
|
| +IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
|
| + Disposition_Settings_UseNonIncognitoWindow) {
|
| + Browser* incognito_browser = CreateIncognitoBrowser();
|
| +
|
| + EXPECT_EQ(2u, BrowserList::size());
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + EXPECT_EQ(1, incognito_browser->tab_count());
|
| +
|
| + // Navigate to the settings page.
|
| + browser::NavigateParams p(MakeNavigateParams(incognito_browser));
|
| + p.disposition = SINGLETON_TAB;
|
| + p.url = GURL("chrome://settings");
|
| + p.show_window = true;
|
| + p.ignore_path = true;
|
| + browser::Navigate(&p);
|
| +
|
| + // The settings page should be opened in browser() window.
|
| + EXPECT_NE(incognito_browser, p.browser);
|
| + EXPECT_EQ(browser(), p.browser);
|
| + EXPECT_EQ(2, browser()->tab_count());
|
| + EXPECT_EQ(GURL("chrome://settings"),
|
| + browser()->GetSelectedTabContents()->GetURL());
|
| +}
|
| +
|
| +// This test verifies that the bookmarks page isn't opened in the incognito
|
| +// window.
|
| +IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
|
| + Disposition_Bookmarks_UseNonIncognitoWindow) {
|
| + Browser* incognito_browser = CreateIncognitoBrowser();
|
| +
|
| + EXPECT_EQ(2u, BrowserList::size());
|
| + EXPECT_EQ(1, browser()->tab_count());
|
| + EXPECT_EQ(1, incognito_browser->tab_count());
|
| +
|
| + // Navigate to the settings page.
|
| + browser::NavigateParams p(MakeNavigateParams(incognito_browser));
|
| + p.disposition = SINGLETON_TAB;
|
| + p.url = GURL("chrome://bookmarks");
|
| + p.show_window = true;
|
| + p.ignore_path = true;
|
| + browser::Navigate(&p);
|
| +
|
| + // The bookmarks page should be opened in browser() window.
|
| + EXPECT_NE(incognito_browser, p.browser);
|
| + EXPECT_EQ(browser(), p.browser);
|
| + EXPECT_EQ(2, browser()->tab_count());
|
| + EXPECT_EQ(GURL("chrome://bookmarks"),
|
| + browser()->GetSelectedTabContents()->GetURL());
|
| +}
|
| +
|
| } // namespace
|
|
|