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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/ash/test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/frame/browser_non_client_frame_view_chromeos.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller_chromeos.h"
#include "chrome/browser/ui/views/frame/immersive_mode_tester.h"
#include "chrome/browser/ui/views/frame/tab_strip_region_view.h"
#include "chrome/browser/ui/views/fullscreen_control/fullscreen_control_host.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/ui/frame/caption_buttons/frame_caption_button_container_view.h"
#include "chromeos/ui/frame/immersive/immersive_fullscreen_controller_test_api.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "ui/aura/window.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/ui_base_types.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/caption_button_layout_constants.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace {
class ImmersiveModeBrowserViewTest
: public TopChromeMdParamTest<ChromeOSBrowserUITest> {
public:
ImmersiveModeBrowserViewTest() = default;
ImmersiveModeBrowserViewTest(const ImmersiveModeBrowserViewTest&) = delete;
ImmersiveModeBrowserViewTest& operator=(const ImmersiveModeBrowserViewTest&) =
delete;
~ImmersiveModeBrowserViewTest() override = default;
// TopChromeMdParamTest<ChromeOSBrowserUITest>:
void PreRunTestOnMainThread() override {
InProcessBrowserTest::PreRunTestOnMainThread();
BrowserView::SetDisableRevealerDelayForTesting(true);
chromeos::ImmersiveFullscreenControllerTestApi(
static_cast<ImmersiveModeControllerChromeos*>(
BrowserView::GetBrowserViewForBrowser(browser())
->immersive_mode_controller())
->controller())
.SetupForTest();
}
};
} // namespace
using ImmersiveModeBrowserViewTestNoWebUiTabStrip =
WebUiTabStripOverrideTest<false, ImmersiveModeBrowserViewTest>;
// This test does not make sense for the webUI tabstrip, since the frame is not
// painted in that case.
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTestNoWebUiTabStrip,
ImmersiveFullscreen) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
content::WebContents* web_contents = browser_view->GetActiveWebContents();
BrowserNonClientFrameViewChromeOS* frame_view =
GetFrameViewChromeOS(browser_view);
ImmersiveModeController* immersive_mode_controller =
browser_view->immersive_mode_controller();
// Immersive fullscreen starts disabled.
ASSERT_FALSE(browser_view->GetWidget()->IsFullscreen());
EXPECT_FALSE(immersive_mode_controller->IsEnabled());
// Frame paints by default.
EXPECT_TRUE(frame_view->GetShouldPaint());
EXPECT_LT(0, frame_view
->GetBoundsForTabStripRegion(
browser_view->tab_strip_region_view()->GetMinimumSize())
.bottom());
// Enter both browser fullscreen and tab fullscreen. Entering browser
// fullscreen should enable immersive fullscreen.
ui_test_utils::ToggleFullscreenModeAndWait(browser());
EnterTabFullscreenMode(browser(), web_contents);
EXPECT_TRUE(immersive_mode_controller->IsEnabled());
// Caption button container is hidden.
EXPECT_FALSE(frame_view->caption_button_container_->GetVisible());
// An immersive reveal shows the buttons and the top of the frame.
std::unique_ptr<ImmersiveRevealedLock> revealed_lock =
immersive_mode_controller->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO);
EXPECT_TRUE(immersive_mode_controller->IsRevealed());
EXPECT_TRUE(frame_view->GetShouldPaint());
// Caption button container is visible again.
EXPECT_TRUE(frame_view->caption_button_container_->GetVisible());
// End the reveal. When in both immersive browser fullscreen and tab
// fullscreen.
revealed_lock.reset();
EXPECT_FALSE(immersive_mode_controller->IsRevealed());
EXPECT_FALSE(frame_view->GetShouldPaint());
EXPECT_EQ(0, frame_view
->GetBoundsForTabStripRegion(
browser_view->tab_strip_region_view()->GetMinimumSize())
.bottom());
EXPECT_FALSE(frame_view->caption_button_container()->GetVisible());
// Repeat test but without tab fullscreen.
EnterTabFullscreenMode(browser(), web_contents);
// Immersive reveal should have same behavior as before.
revealed_lock = immersive_mode_controller->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO);
EXPECT_TRUE(immersive_mode_controller->IsRevealed());
EXPECT_TRUE(frame_view->GetShouldPaint());
EXPECT_LT(0, frame_view
->GetBoundsForTabStripRegion(
browser_view->tab_strip_region_view()->GetMinimumSize())
.bottom());
EXPECT_TRUE(frame_view->caption_button_container()->GetVisible());
// Ending the reveal. Immersive browser should have the same behavior as full
// screen, i.e., having an origin of (0,0).
revealed_lock.reset();
EXPECT_FALSE(frame_view->GetShouldPaint());
EXPECT_EQ(0, frame_view
->GetBoundsForTabStripRegion(
browser_view->tab_strip_region_view()->GetMinimumSize())
.bottom());
EXPECT_FALSE(frame_view->caption_button_container()->GetVisible());
// Exiting immersive fullscreen should make the caption buttons and the frame
// visible again.
{
ui_test_utils::FullscreenWaiter waiter(
browser(), ui_test_utils::FullscreenWaiter::kNoFullscreen);
browser_view->ExitFullscreen();
waiter.Wait();
}
EXPECT_FALSE(immersive_mode_controller->IsEnabled());
EXPECT_TRUE(frame_view->GetShouldPaint());
EXPECT_LT(0, frame_view
->GetBoundsForTabStripRegion(
browser_view->tab_strip_region_view()->GetMinimumSize())
.bottom());
EXPECT_TRUE(frame_view->caption_button_container()->GetVisible());
}
// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
// IDC_SELECT_LAST_TAB when the browser is in immersive fullscreen mode.
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTest,
TabNavigationAcceleratorsFullscreenBrowser) {
ImmersiveModeTester tester(browser());
// Make sure that the focus is on the webcontents rather than on the omnibox,
// because if the focus is on the omnibox, the tab strip will remain revealed
// in the immersive fullscreen mode and will interfere with this test waiting
// for the revealer to be dismissed.
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
// Create three more tabs plus the existing one that browser tests start with.
const GURL about_blank(url::kAboutBlankURL);
ASSERT_TRUE(AddTabAtIndex(0, about_blank, ui::PAGE_TRANSITION_TYPED));
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
ASSERT_TRUE(AddTabAtIndex(0, about_blank, ui::PAGE_TRANSITION_TYPED));
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
ASSERT_TRUE(AddTabAtIndex(0, about_blank, ui::PAGE_TRANSITION_TYPED));
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
EnterImmersiveFullscreenMode(browser());
// Wait for the end of the initial reveal which results from adding the new
// tabs and changing the focused tab.
tester.VerifyTabIndexAfterReveal(0);
// Groups the browser command ID and its corresponding active tab index that
// will result when the command is executed in this test.
struct TestData {
int command;
int expected_index;
};
constexpr TestData test_data[] = {{IDC_SELECT_LAST_TAB, 3},
{IDC_SELECT_TAB_0, 0},
{IDC_SELECT_NEXT_TAB, 1},
{IDC_SELECT_PREVIOUS_TAB, 0}};
for (const auto& datum : test_data) {
tester.RunCommand(datum.command, datum.expected_index);
}
}
// This test does not make sense for the webUI tabstrip, since the window layout
// is different in that case.
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTestNoWebUiTabStrip,
TestCaptionButtonsReceiveEventsInBrowserImmersiveMode) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
// Make sure that the focus is on the webcontents rather than on the omnibox,
// because if the focus is on the omnibox, the tab strip will remain revealed
// in the immersive fullscreen mode and will interfere with this test waiting
// for the revealer to be dismissed.
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
EnterImmersiveFullscreenMode(browser());
EXPECT_FALSE(browser()->window()->IsMaximized());
EXPECT_FALSE(browser_view->immersive_mode_controller()->IsRevealed());
std::unique_ptr<ImmersiveRevealedLock> revealed_lock =
browser_view->immersive_mode_controller()->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO);
EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed());
// Clicking the "restore" caption button should exit the immersive mode.
aura::Window* window = browser()->window()->GetNativeWindow();
ui::test::EventGenerator event_generator(window->GetRootWindow());
gfx::Size button_size = views::GetCaptionButtonLayoutSize(
views::CaptionButtonLayoutSize::kBrowserCaptionMaximized);
gfx::Point point_in_restore_button(window->GetBoundsInScreen().top_right());
point_in_restore_button.Offset(-button_size.width() * 3 / 2,
button_size.height() / 2);
event_generator.MoveMouseTo(point_in_restore_button);
EXPECT_TRUE(browser_view->immersive_mode_controller()->IsRevealed());
event_generator.ClickLeftButton();
ImmersiveModeTester(browser()).WaitForFullscreenToExit();
EXPECT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(browser()->window()->IsFullscreen());
}
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTest,
TestCaptionButtonsReceiveEventsInAppImmersiveMode) {
// Open a new app window.
Browser* app_browser =
CreateBrowserForApp("test_browser_app", browser()->profile());
BrowserView* app_view = BrowserView::GetBrowserViewForBrowser(app_browser);
chromeos::ImmersiveFullscreenControllerTestApi(
static_cast<ImmersiveModeControllerChromeos*>(
app_view->immersive_mode_controller())
->controller())
.SetupForTest();
EnterImmersiveFullscreenMode(app_browser);
EXPECT_TRUE(app_browser->window()->IsFullscreen());
EXPECT_FALSE(app_browser->window()->IsMaximized());
EXPECT_FALSE(app_view->GetTabStripVisible());
EXPECT_FALSE(app_view->immersive_mode_controller()->IsRevealed());
std::unique_ptr<ImmersiveRevealedLock> revealed_lock =
app_view->immersive_mode_controller()->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO);
EXPECT_TRUE(app_view->immersive_mode_controller()->IsRevealed());
AddBlankTabAndShow(app_browser);
// Clicking the "restore" caption button should exit the immersive mode.
aura::Window* app_window = app_browser->window()->GetNativeWindow();
ui::test::EventGenerator event_generator(app_window->GetRootWindow(),
app_window);
gfx::Size button_size = views::GetCaptionButtonLayoutSize(
views::CaptionButtonLayoutSize::kBrowserCaptionMaximized);
gfx::Point point_in_restore_button(
app_window->GetBoundsInRootWindow().top_right());
point_in_restore_button.Offset(-2 * button_size.width(),
button_size.height() / 2);
event_generator.MoveMouseTo(point_in_restore_button);
EXPECT_TRUE(app_view->immersive_mode_controller()->IsRevealed());
event_generator.ClickLeftButton();
ImmersiveModeTester(app_browser).WaitForFullscreenToExit();
EXPECT_FALSE(app_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(app_browser->window()->IsFullscreen());
}
// Regression test for crbug.com/796171. Make sure that going from regular
// fullscreen to locked fullscreen does not cause a crash.
// Also test that the immersive mode is disabled afterwards (and the shelf is
// hidden, and the fullscreen control popup doesn't show up).
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTest,
RegularToLockedFullscreenDisablesImmersive) {
if (!IsIsShelfVisibleSupported()) {
GTEST_SKIP() << "Ash is too old.";
}
EnterImmersiveFullscreenMode(browser());
// Set locked fullscreen state.
PinWindow(browser()->window()->GetNativeWindow(), /*trusted=*/true);
// We're fullscreen, immersive is disabled in locked fullscreen, and while
// we're at it, also make sure that the shelf is hidden.
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
EXPECT_TRUE(browser_view->GetWidget()->IsFullscreen());
EXPECT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(IsShelfVisible());
// Make sure the fullscreen control popup doesn't show up.
ui::MouseEvent mouse_move(ui::EventType::kMouseMoved, gfx::Point(1, 1),
gfx::Point(), base::TimeTicks(), 0, 0);
ASSERT_TRUE(browser_view->fullscreen_control_host_for_test());
browser_view->fullscreen_control_host_for_test()->OnMouseEvent(mouse_move);
EXPECT_FALSE(browser_view->fullscreen_control_host_for_test()->IsVisible());
}
// Regression test for crbug.com/883104. Make sure that immersive fullscreen is
// disabled in locked fullscreen mode (also the shelf is hidden, and the
// fullscreen control popup doesn't show up).
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTest,
LockedFullscreenDisablesImmersive) {
if (!IsIsShelfVisibleSupported()) {
GTEST_SKIP() << "Ash is too old.";
}
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
EXPECT_FALSE(browser_view->GetWidget()->IsFullscreen());
// Set locked fullscreen state.
PinWindow(browser()->window()->GetNativeWindow(), /*trusted=*/true);
// We're fullscreen, immersive is disabled in locked fullscreen, and while
// we're at it, also make sure that the shelf is hidden.
EXPECT_TRUE(browser_view->GetWidget()->IsFullscreen());
EXPECT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(IsShelfVisible());
// Make sure the fullscreen control popup doesn't show up.
ui::MouseEvent mouse_move(ui::EventType::kMouseMoved, gfx::Point(1, 1),
gfx::Point(), base::TimeTicks(), 0, 0);
ASSERT_TRUE(browser_view->fullscreen_control_host_for_test());
browser_view->fullscreen_control_host_for_test()->OnMouseEvent(mouse_move);
EXPECT_FALSE(browser_view->fullscreen_control_host_for_test()->IsVisible());
}
// Test the shelf visibility affected by entering and exiting tab fullscreen and
// immersive fullscreen.
IN_PROC_BROWSER_TEST_P(ImmersiveModeBrowserViewTest, TabAndBrowserFullscreen) {
if (!IsIsShelfVisibleSupported()) {
GTEST_SKIP() << "Ash is too old.";
}
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
ASSERT_TRUE(
AddTabAtIndex(0, GURL(url::kAboutBlankURL), ui::PAGE_TRANSITION_TYPED));
// The shelf should start out as visible.
EXPECT_TRUE(IsShelfVisible());
// 1) Test that entering tab fullscreen from immersive fullscreen hides the
// shelf.
EnterImmersiveFullscreenMode(browser());
EXPECT_FALSE(IsShelfVisible());
content::WebContents* web_contents = browser_view->GetActiveWebContents();
EnterTabFullscreenMode(browser(), web_contents);
ASSERT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(IsShelfVisible());
// 2) Test that exiting tab fullscreen autohides the shelf.
ExitTabFullscreenMode(browser(), web_contents);
ASSERT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_FALSE(IsShelfVisible());
// 3) Test that exiting tab fullscreen and immersive fullscreen correctly
// updates the shelf visibility.
EnterTabFullscreenMode(browser(), web_contents);
ASSERT_TRUE(browser_view->immersive_mode_controller()->IsEnabled());
ui_test_utils::ToggleFullscreenModeAndWait(browser());
ASSERT_FALSE(browser_view->immersive_mode_controller()->IsEnabled());
EXPECT_TRUE(IsShelfVisible());
}
#define INSTANTIATE_TEST_SUITE(name) \
INSTANTIATE_TEST_SUITE_P(All, name, ::testing::Values(false, true))
INSTANTIATE_TEST_SUITE(ImmersiveModeBrowserViewTest);
INSTANTIATE_TEST_SUITE(ImmersiveModeBrowserViewTestNoWebUiTabStrip);
|