1 // Copyright 2012 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.
5 #include "chrome/browser/ui/browser_navigator_browsertest.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/chrome_restart_request.h"
9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chromeos/chromeos_switches.h"
17 #include "content/public/browser/web_contents.h"
22 return GURL("http://www.google.com/");
25 // Subclass that tests navigation while in the Guest session.
26 class BrowserGuestSessionNavigatorTest
: public BrowserNavigatorTest
{
28 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
29 base::CommandLine command_line_copy
= *command_line
;
30 command_line_copy
.AppendSwitchASCII(
31 chromeos::switches::kLoginProfile
, "user");
32 command_line_copy
.AppendSwitch(chromeos::switches::kGuestSession
);
33 chromeos::GetOffTheRecordCommandLine(GetGoogleURL(),
40 // This test verifies that the settings page is opened in the incognito window
41 // in Guest Session (as well as all other windows in Guest session).
42 IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest
,
43 Disposition_Settings_UseIncognitoWindow
) {
44 Browser
* incognito_browser
= CreateIncognitoBrowser();
46 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
47 EXPECT_EQ(1, browser()->tab_strip_model()->count());
48 EXPECT_EQ(1, incognito_browser
->tab_strip_model()->count());
50 // Navigate to the settings page.
51 chrome::NavigateParams
params(MakeNavigateParams(incognito_browser
));
52 params
.disposition
= SINGLETON_TAB
;
53 params
.url
= GURL("chrome://chrome/settings");
54 params
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
55 params
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
56 chrome::Navigate(¶ms
);
58 // Settings page should be opened in incognito window.
59 EXPECT_NE(browser(), params
.browser
);
60 EXPECT_EQ(incognito_browser
, params
.browser
);
61 EXPECT_EQ(2, incognito_browser
->tab_strip_model()->count());
62 EXPECT_EQ(GURL("chrome://chrome/settings"),
63 incognito_browser
->tab_strip_model()->GetActiveWebContents()->
67 // Test that in multi user environments a newly created browser gets created
68 // on the same desktop as the browser is shown on.
69 IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest
,
70 Browser_Gets_Created_On_Visiting_Desktop
) {
71 // Test 1: Test that a browser created from a visiting browser will be on the
72 // same visiting desktop.
74 const std::string desktop_user_id
= "desktop_user_id@fake.com";
75 TestMultiUserWindowManager
* manager
=
76 new TestMultiUserWindowManager(browser(), desktop_user_id
);
78 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
80 // Navigate to the settings page.
81 chrome::NavigateParams
params(MakeNavigateParams(browser()));
82 params
.disposition
= NEW_POPUP
;
83 params
.url
= GURL("chrome://chrome/settings");
84 params
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
85 params
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
86 params
.browser
= browser();
87 chrome::Navigate(¶ms
);
89 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
91 aura::Window
* created_window
= manager
->created_window();
92 ASSERT_TRUE(created_window
);
93 EXPECT_TRUE(manager
->IsWindowOnDesktopOfUser(created_window
,
96 // Test 2: Test that a window which is not visiting does not cause an owner
97 // assignment of a newly created browser.
99 std::string browser_owner
=
100 multi_user_util::GetUserIDFromProfile(browser()->profile());
101 TestMultiUserWindowManager
* manager
=
102 new TestMultiUserWindowManager(browser(), browser_owner
);
104 // Navigate to the settings page.
105 chrome::NavigateParams
params(MakeNavigateParams(browser()));
106 params
.disposition
= NEW_POPUP
;
107 params
.url
= GURL("chrome://chrome/settings");
108 params
.window_action
= chrome::NavigateParams::SHOW_WINDOW
;
109 params
.path_behavior
= chrome::NavigateParams::IGNORE_AND_NAVIGATE
;
110 params
.browser
= browser();
111 chrome::Navigate(¶ms
);
113 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
115 // The ShowWindowForUser should not have been called since the window is
116 // already on the correct desktop.
117 ASSERT_FALSE(manager
->created_window());