Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / browser_navigator_browsertest_chromeos.cc
blobde7baecf63e259b7d6e5444f5a2a20c11075e793
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"
19 namespace {
21 GURL GetGoogleURL() {
22 return GURL("http://www.google.com/");
25 // Subclass that tests navigation while in the Guest session.
26 class BrowserGuestSessionNavigatorTest: public BrowserNavigatorTest {
27 protected:
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(),
34 true,
35 command_line_copy,
36 command_line);
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(&params);
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()->
64 GetURL());
67 // Test that in multi user environments a newly created browser gets created
68 // on the same desktop as the browser is shown on.
70 // Flakily hits assert: http://crbug.com/469717
71 IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
72 DISABLED_Browser_Gets_Created_On_Visiting_Desktop) {
73 // Test 1: Test that a browser created from a visiting browser will be on the
74 // same visiting desktop.
76 const std::string desktop_user_id = "desktop_user_id@fake.com";
77 TestMultiUserWindowManager* manager =
78 new TestMultiUserWindowManager(browser(), desktop_user_id);
80 EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
82 // Navigate to the settings page.
83 chrome::NavigateParams params(MakeNavigateParams(browser()));
84 params.disposition = NEW_POPUP;
85 params.url = GURL("chrome://chrome/settings");
86 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
87 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
88 params.browser = browser();
89 chrome::Navigate(&params);
91 EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
93 aura::Window* created_window = manager->created_window();
94 ASSERT_TRUE(created_window);
95 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(created_window,
96 desktop_user_id));
98 // Test 2: Test that a window which is not visiting does not cause an owner
99 // assignment of a newly created browser.
101 std::string browser_owner =
102 multi_user_util::GetUserIDFromProfile(browser()->profile());
103 TestMultiUserWindowManager* manager =
104 new TestMultiUserWindowManager(browser(), browser_owner);
106 // Navigate to the settings page.
107 chrome::NavigateParams params(MakeNavigateParams(browser()));
108 params.disposition = NEW_POPUP;
109 params.url = GURL("chrome://chrome/settings");
110 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
111 params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
112 params.browser = browser();
113 chrome::Navigate(&params);
115 EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
117 // The ShowWindowForUser should not have been called since the window is
118 // already on the correct desktop.
119 ASSERT_FALSE(manager->created_window());
123 } // namespace