Commit 025f7a53 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

tablet: Add screenshot related test suite.

Tablet mode has a performance feature which takes a screenshot to fully
occlude all windows while the top window is animating. This CL adds a
test suite to test the feature, including a regression test for a
recently found regression.

Test: added tests
Bug: 1002735
Change-Id: I712ecdb3778f720fa55b6cbcf34773caca0c1f94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815229Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698567}
parent ad602416
......@@ -7,7 +7,7 @@
#include "ash/display/window_tree_host_manager.h"
#include "ash/login_status.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/public/cpp/tablet_mode.h"
#include "ash/root_window_controller.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/session/session_controller_impl.h"
......@@ -71,23 +71,6 @@ void PerformDoubleTap() {
GetTray()->PerformAction(tap);
}
class TabletModeWaiter : public TabletModeObserver {
public:
TabletModeWaiter() {
Shell::Get()->tablet_mode_controller()->AddObserver(this);
loop_.Run();
}
~TabletModeWaiter() override {
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
}
void OnTabletModeStarted() override { loop_.QuitWhenIdle(); }
private:
base::RunLoop loop_;
DISALLOW_COPY_AND_ASSIGN(TabletModeWaiter);
};
} // namespace
class OverviewButtonTrayTest : public AshTestBase {
......@@ -142,16 +125,17 @@ TEST_F(OverviewButtonTrayTest, VisibilityTest) {
EXPECT_FALSE(Shell::Get()->tablet_mode_controller()->InTabletMode());
// When there is an window, it'll take an screenshot and
// switch becomes asynchronous
// switch becomes asynchronous.
std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
ASSERT_FALSE(GetTray()->GetVisible());
TabletMode::Waiter waiter(/*enable=*/true);
TabletModeControllerTestApi().EnterTabletMode();
EXPECT_TRUE(Shell::Get()->tablet_mode_controller()->InTabletMode());
EXPECT_FALSE(GetTray()->GetVisible());
TabletModeWaiter wait;
waiter.Wait();
EXPECT_TRUE(Shell::Get()->tablet_mode_controller()->InTabletMode());
EXPECT_TRUE(GetTray()->GetVisible());
......@@ -176,9 +160,9 @@ TEST_F(OverviewButtonTrayTest, PerformAction) {
EXPECT_FALSE(Shell::Get()->overview_controller()->InOverviewSession());
// Test in tablet mode.
TabletMode::Waiter waiter(/*enable=*/true);
TabletModeControllerTestApi().EnterTabletMode();
TabletModeWaiter wait;
waiter.Wait();
GetTray()->PerformAction(CreateTapEvent());
EXPECT_TRUE(Shell::Get()->overview_controller()->InOverviewSession());
......
......@@ -83,6 +83,10 @@ class TabletModeControllerTestApi {
return tablet_mode_controller_->AreInternalInputDeviceEventsBlocked();
}
bool IsScreenshotShown() const {
return !!tablet_mode_controller_->screenshot_layer_;
}
private:
TabletModeController* tablet_mode_controller_;
......
......@@ -164,6 +164,8 @@ class TabletModeControllerTest : public AshTestBase {
test_api_->SuspendDone(sleep_duration);
}
bool IsScreenshotShown() const { return test_api_->IsScreenshotShown(); }
// Creates a test window snapped on the left in desktop mode.
std::unique_ptr<aura::Window> CreateDesktopWindowSnappedLeft() {
std::unique_ptr<aura::Window> window = CreateTestWindow();
......@@ -1616,4 +1618,115 @@ TEST_F(TabletModeControllerTest, TabletModeTransitionHistogramsSnappedWindows) {
histogram_tester.ExpectTotalCount(kExitHistogram, 0);
}
class TabletModeControllerScreenshotTest : public TabletModeControllerTest {
public:
TabletModeControllerScreenshotTest() = default;
~TabletModeControllerScreenshotTest() override = default;
void SetUp() override {
TabletModeControllerTest::SetUp();
TabletModeController::SetUseScreenshotForTest(true);
// Remove TabletModeController as an observer of input device events to
// prevent interfering with the test.
ui::DeviceDataManager::GetInstance()->RemoveObserver(
tablet_mode_controller());
scoped_animation_duration_scale_mode_ =
std::make_unique<ui::ScopedAnimationDurationScaleMode>(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
// PowerManagerClient callback is a posted task.
base::RunLoop().RunUntilIdle();
}
void TearDown() override {
scoped_animation_duration_scale_mode_.reset();
ui::DeviceDataManager::GetInstance()->AddObserver(tablet_mode_controller());
TabletModeControllerTest::TearDown();
}
private:
std::unique_ptr<ui::ScopedAnimationDurationScaleMode>
scoped_animation_duration_scale_mode_;
DISALLOW_COPY_AND_ASSIGN(TabletModeControllerScreenshotTest);
};
// Tests that when there are no animations, no screenshot is taken.
TEST_F(TabletModeControllerScreenshotTest, NoAnimationNoScreenshot) {
// Tests that no windows means no screenshot.
SetTabletMode(true);
EXPECT_FALSE(IsScreenshotShown());
SetTabletMode(false);
// If the top window is already maximized, there is no animation, so no
// screenshot should be shown.
auto window = CreateTestWindow(gfx::Rect(200, 200));
WindowState::Get(window.get())->Maximize();
window->layer()->GetAnimator()->StopAnimating();
TabletMode::Waiter waiter(/*enable=*/true);
SetTabletMode(true);
EXPECT_FALSE(IsScreenshotShown());
waiter.Wait();
EXPECT_FALSE(IsScreenshotShown());
EXPECT_FALSE(window->layer()->GetAnimator()->is_animating());
}
// Regression test for screenshot staying visible when entering tablet mode when
// already in overview mode. See https://crbug.com/1002735.
TEST_F(TabletModeControllerScreenshotTest, FromOverviewNoScreenshot) {
// Create two maximized windows.
auto window = CreateTestWindow(gfx::Rect(200, 200));
auto window2 = CreateTestWindow(gfx::Rect(200, 200));
WindowState::Get(window.get())->Maximize();
WindowState::Get(window2.get())->Maximize();
window->layer()->GetAnimator()->StopAnimating();
window2->layer()->GetAnimator()->StopAnimating();
// Enter overview.
Shell::Get()->overview_controller()->StartOverview();
window->layer()->GetAnimator()->StopAnimating();
window2->layer()->GetAnimator()->StopAnimating();
// Enter tablet mode.
TabletMode::Waiter waiter(/*enable=*/true);
SetTabletMode(true);
EXPECT_FALSE(IsScreenshotShown());
waiter.Wait();
EXPECT_TRUE(IsScreenshotShown());
// Tests that after ending the overview animation, the screenshot is
// destroyed.
window->layer()->GetAnimator()->StopAnimating();
window2->layer()->GetAnimator()->StopAnimating();
EXPECT_FALSE(IsScreenshotShown());
}
// Tests that the screenshot is visible when a window animation happens when
// entering tablet mode.
TEST_F(TabletModeControllerScreenshotTest, ScreenshotVisibility) {
auto window = CreateTestWindow(gfx::Rect(200, 200));
auto window2 = CreateTestWindow(gfx::Rect(300, 200));
ui::Layer* layer = window2->layer();
ASSERT_FALSE(IsScreenshotShown());
TabletMode::Waiter waiter(/*enable=*/true);
SetTabletMode(true);
EXPECT_FALSE(IsScreenshotShown());
// Tests that after waiting for the async tablet mode entry, the screenshot is
// shown.
waiter.Wait();
EXPECT_TRUE(IsScreenshotShown());
EXPECT_TRUE(layer->GetAnimator()->is_animating());
// Tests that the screenshot is destroyed after the window is done animating.
layer->GetAnimator()->StopAnimating();
EXPECT_FALSE(IsScreenshotShown());
}
} // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment