1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/constants/ash_switches.h"
#include "base/command_line.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/ash/login/chrome_restart_request.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_helper.h"
#include "chrome/browser/ui/ash/multi_user/test_multi_user_window_manager.h"
#include "chrome/browser/ui/ash/window_pin_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_browsertest.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/account_id/account_id.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "ui/aura/window.h"
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "base/test/run_until.h"
#include "base/test/test_future.h"
#include "chromeos/crosapi/mojom/crosapi.mojom.h"
#include "chromeos/crosapi/mojom/test_controller.mojom.h"
#include "chromeos/lacros/lacros_test_helper.h"
#include "chromeos/startup/browser_init_params.h"
#endif
namespace {
using BrowserNavigatorTestChromeOS = BrowserNavigatorTest;
#if BUILDFLAG(IS_CHROMEOS_ASH)
GURL GetGoogleURL() {
return GURL("http://www.google.com/");
}
// Verifies that new browser is not opened for Signin profile.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTestChromeOS, RestrictSigninProfile) {
EXPECT_EQ(chrome::GetTotalBrowserCount(), 1u);
EXPECT_EQ(Browser::CreationStatus::kErrorProfileUnsuitable,
Browser::GetCreationStatusForProfile(
ash::ProfileHelper::GetSigninProfile()));
}
// Verify that page navigation is blocked in locked fullscreen mode.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTestChromeOS,
NavigationBlockedInLockedFullscreen) {
// Set locked fullscreen state.
aura::Window* window = browser()->window()->GetNativeWindow();
PinWindow(window, /*trusted=*/true);
// Navigate to a page.
auto url = GURL(chrome::kChromeUIVersionURL);
NavigateParams params(MakeNavigateParams(browser()));
params.disposition = WindowOpenDisposition::NEW_WINDOW;
params.url = url;
params.window_action = NavigateParams::SHOW_WINDOW;
Navigate(¶ms);
// The page should not be opened, and the browser should still sit at the
// default about:blank page.
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(GURL(url::kAboutBlankURL),
browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
// As a sanity check unset the locked fullscreen state and make sure that the
// navigation happens (the following EXPECTs fail if the next line isn't
// executed).
UnpinWindow(window);
Navigate(¶ms);
// The original browser should still be at the same page, but the newly
// opened browser should sit on the chrome:version page.
EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(GURL(url::kAboutBlankURL),
browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
EXPECT_EQ(1, params.browser->tab_strip_model()->count());
EXPECT_EQ(
GURL(chrome::kChromeUIVersionURL),
params.browser->tab_strip_model()->GetActiveWebContents()->GetURL());
}
// Subclass that tests navigation while in the Guest session.
class BrowserGuestSessionNavigatorTest : public BrowserNavigatorTest {
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
base::CommandLine command_line_copy = *command_line;
command_line_copy.AppendSwitchASCII(ash::switches::kLoginProfile, "user");
command_line_copy.AppendSwitch(ash::switches::kGuestSession);
ash::GetOffTheRecordCommandLine(GetGoogleURL(), command_line_copy,
command_line);
}
};
// This test verifies that the settings page is opened in the incognito window
// in Guest Session (as well as all other windows in Guest session).
IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
Disposition_Settings_UseIncognitoWindow) {
Browser* incognito_browser = CreateIncognitoBrowser();
EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
// Navigate to the settings page.
NavigateParams params(MakeNavigateParams(incognito_browser));
params.disposition = WindowOpenDisposition::SINGLETON_TAB;
params.url = GURL("chrome://settings");
params.window_action = NavigateParams::SHOW_WINDOW;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
Navigate(¶ms);
// Settings page should be opened in incognito window.
EXPECT_NE(browser(), params.browser);
EXPECT_EQ(incognito_browser, params.browser);
EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
EXPECT_EQ(
GURL("chrome://settings"),
incognito_browser->tab_strip_model()->GetActiveWebContents()->GetURL());
}
// Test that in multi user environments a newly created browser gets created
// on the same desktop as the browser is shown on.
IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
Browser_Gets_Created_On_Visiting_Desktop) {
// Test 1: Test that a browser created from a visiting browser will be on the
// same visiting desktop.
{
const AccountId desktop_account_id(
AccountId::FromUserEmail("desktop_user_id@fake.com"));
TestMultiUserWindowManager* window_manager =
TestMultiUserWindowManager::Create(browser(), desktop_account_id);
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
// Navigate to the settings page.
NavigateParams params(MakeNavigateParams(browser()));
params.disposition = WindowOpenDisposition::NEW_POPUP;
params.url = GURL("chrome://settings");
params.window_action = NavigateParams::SHOW_WINDOW;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
params.browser = browser();
Navigate(¶ms);
EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
aura::Window* created_window = window_manager->created_window();
ASSERT_TRUE(created_window);
EXPECT_TRUE(
MultiUserWindowManagerHelper::GetInstance()->IsWindowOnDesktopOfUser(
created_window, desktop_account_id));
}
// Test 2: Test that a window which is not visiting does not cause an owner
// assignment of a newly created browser.
{
const AccountId browser_owner =
multi_user_util::GetAccountIdFromProfile(browser()->profile());
TestMultiUserWindowManager* window_manager =
TestMultiUserWindowManager::Create(browser(), browser_owner);
// Navigate to the settings page.
NavigateParams params(MakeNavigateParams(browser()));
params.disposition = WindowOpenDisposition::NEW_POPUP;
params.url = GURL("chrome://settings");
params.window_action = NavigateParams::SHOW_WINDOW;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
params.browser = browser();
Navigate(¶ms);
EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
// The ShowWindowForUser should not have been called since the window is
// already on the correct desktop.
ASSERT_FALSE(window_manager->created_window());
}
}
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if BUILDFLAG(IS_CHROMEOS_LACROS)
// Verifies that the navigation is trying to open the os:// scheme page in
// Ash, will fail and then open it as chrome:// in Lacros to show a 404 error.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTestChromeOS, OsSchemeRedirectFail) {
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
// Navigate to an unknown page with an os:// scheme.
NavigateParams params(MakeNavigateParams(browser()));
params.disposition = WindowOpenDisposition::SINGLETON_TAB;
params.url = GURL("os://foobar");
params.window_action = NavigateParams::SHOW_WINDOW;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
Navigate(¶ms);
// A new blocked page should be shown in the browser.
EXPECT_EQ(browser(), params.browser);
EXPECT_EQ(2, browser()->tab_strip_model()->count());
EXPECT_EQ(GURL(content::kBlockedURL),
browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
}
// Verifies that the navigation of an os:// scheme page is opening an app on
// the ash side and does not produce a navigation on the Lacros side.
IN_PROC_BROWSER_TEST_F(BrowserNavigatorTestChromeOS, OsSchemeRedirectSucceed) {
if (chromeos::LacrosService::Get()
->GetInterfaceVersion<crosapi::mojom::TestController>() <
static_cast<int>(crosapi::mojom::TestController::MethodMinVersions::
kGetOpenAshBrowserWindowsMinVersion)) {
LOG(WARNING) << "Unsupported ash version.";
return;
}
auto& test_controller = chromeos::LacrosService::Get()
->GetRemote<crosapi::mojom::TestController>();
// Ash shouldn't have a browser window open by now.
base::test::TestFuture<uint32_t> window_count_future;
test_controller->GetOpenAshBrowserWindows(window_count_future.GetCallback());
EXPECT_EQ(0u, window_count_future.Take());
// First we make sure that the GURL we are interested in is in our allow list.
auto init_params = crosapi::mojom::BrowserInitParams::New();
init_params->accepted_internal_ash_urls =
std::vector<GURL>{GURL(chrome::kChromeUIFlagsURL)};
chromeos::BrowserInitParams::SetInitParamsForTests(std::move(init_params));
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
GURL url_before_navigation =
browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
// Navigate to a known Ash page.
NavigateParams params(MakeNavigateParams(browser()));
params.disposition = WindowOpenDisposition::SINGLETON_TAB;
params.url = GURL(chrome::kOsUIFlagsURL);
params.window_action = NavigateParams::SHOW_WINDOW;
params.path_behavior = NavigateParams::IGNORE_AND_NAVIGATE;
params.transition = ui::PageTransitionFromInt(
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
Navigate(¶ms);
// No change should have happened on the Lacros side.
EXPECT_EQ(browser(), params.browser);
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(url_before_navigation,
browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
// Clean up the window we have created.
// Wait until we have the app running.
ASSERT_TRUE(base::test::RunUntil([&] {
test_controller->GetOpenAshBrowserWindows(
window_count_future.GetCallback());
return window_count_future.Take() > 0;
}));
// Close it.
base::test::TestFuture<bool> success_future;
test_controller->CloseAllBrowserWindows(success_future.GetCallback());
EXPECT_TRUE(success_future.Get());
// Wait until all are gone.
ASSERT_TRUE(base::test::RunUntil([&] {
test_controller->GetOpenAshBrowserWindows(
window_count_future.GetCallback());
return window_count_future.Take() == 0;
}));
}
#endif
} // namespace
|