1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/browser_navigator_browsertest.h"
6
7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/browser/chromeos/login/login_utils.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "content/browser/tab_contents/tab_contents.h"
14
15 namespace {
16
17 // Subclass that tests navigation while in the Guest session.
18 class BrowserGuestSessionNavigatorTest: public BrowserNavigatorTest {
19 protected:
SetUpCommandLine(CommandLine * command_line)20 virtual void SetUpCommandLine(CommandLine* command_line) {
21 CommandLine command_line_copy = *command_line;
22 command_line_copy.AppendSwitchASCII(switches::kLoginProfile, "user");
23 chromeos::LoginUtils::Get()->GetOffTheRecordCommandLine(GetGoogleURL(),
24 command_line_copy,
25 command_line);
26 }
27 };
28
29 // This test verifies that the settings page is opened in the incognito window
30 // in Guest Session (as well as all other windows in Guest session).
IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,Disposition_Settings_UseIncognitoWindow)31 IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
32 Disposition_Settings_UseIncognitoWindow) {
33 Browser* incognito_browser = CreateIncognitoBrowser();
34
35 EXPECT_EQ(2u, BrowserList::size());
36 EXPECT_EQ(1, browser()->tab_count());
37 EXPECT_EQ(1, incognito_browser->tab_count());
38
39 // Navigate to the settings page.
40 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
41 p.disposition = SINGLETON_TAB;
42 p.url = GURL("chrome://settings");
43 p.window_action = browser::NavigateParams::SHOW_WINDOW;
44 p.path_behavior = browser::NavigateParams::IGNORE_AND_NAVIGATE;
45 browser::Navigate(&p);
46
47 // Settings page should be opened in incognito window.
48 EXPECT_NE(browser(), p.browser);
49 EXPECT_EQ(incognito_browser, p.browser);
50 EXPECT_EQ(2, incognito_browser->tab_count());
51 EXPECT_EQ(GURL("chrome://settings"),
52 incognito_browser->GetSelectedTabContents()->GetURL());
53 }
54
55 } // namespace
56