Commit 6bff67f4 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

[CrOS Perf Test] Rotatoin Animation Test

This runs the rotation ainmation with following conditions:
with 2 or 8 windows,
with NTP or blank page
in overview mode or normal

Bug: 952885, 919707

Change-Id: I50f0a44a3c2a3f79d9ffd0d818f59d2e660784dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594043Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657321}
parent dfae77a3
......@@ -660,19 +660,23 @@ void AccelerometerReader::Initialize(
}
void AccelerometerReader::AddObserver(Observer* observer) {
accelerometer_file_reader_->AddObserver(observer);
if (accelerometer_file_reader_)
accelerometer_file_reader_->AddObserver(observer);
}
void AccelerometerReader::RemoveObserver(Observer* observer) {
accelerometer_file_reader_->RemoveObserver(observer);
if (accelerometer_file_reader_)
accelerometer_file_reader_->RemoveObserver(observer);
}
void AccelerometerReader::StartListenToTabletModeController() {
accelerometer_file_reader_->StartListenToTabletModeController();
if (accelerometer_file_reader_)
accelerometer_file_reader_->StartListenToTabletModeController();
}
void AccelerometerReader::StopListenToTabletModeController() {
accelerometer_file_reader_->StopListenToTabletModeController();
if (accelerometer_file_reader_)
accelerometer_file_reader_->StopListenToTabletModeController();
}
AccelerometerReader::AccelerometerReader()
......@@ -680,4 +684,11 @@ AccelerometerReader::AccelerometerReader()
AccelerometerReader::~AccelerometerReader() = default;
void AccelerometerReader::DisableForTest() {
if (accelerometer_file_reader_) {
accelerometer_file_reader_->StopListenToTabletModeController();
accelerometer_file_reader_.reset();
}
}
} // namespace ash
......@@ -54,6 +54,10 @@ class ASH_EXPORT AccelerometerReader {
void StartListenToTabletModeController();
void StopListenToTabletModeController();
void DisableForTest();
bool is_disabled() const { return !accelerometer_file_reader_; }
protected:
AccelerometerReader();
virtual ~AccelerometerReader();
......
......@@ -8,6 +8,7 @@
#include <utility>
#include "ash/accelerators/accelerator_commands.h"
#include "ash/accelerometer/accelerometer_reader.h"
#include "ash/app_list/app_list_controller_impl.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/keyboard/ash_keyboard_controller.h"
......@@ -196,6 +197,7 @@ void ShellTestApi::IsSystemModalWindowOpen(IsSystemModalWindowOpenCallback cb) {
}
void ShellTestApi::EnableTabletModeWindowManager(bool enable) {
AccelerometerReader::GetInstance()->DisableForTest();
shell_->tablet_mode_controller()->EnableTabletModeWindowManager(enable);
}
......
......@@ -670,6 +670,10 @@ void TabletModeController::OnGetSwitchStates(
base::Optional<chromeos::PowerManagerClient::SwitchStates> result) {
if (!result.has_value())
return;
if (AccelerometerReader::GetInstance()->is_disabled())
return;
LidEventReceived(result->lid_state, base::TimeTicks::Now());
TabletModeEventReceived(result->tablet_mode, base::TimeTicks::Now());
}
......
......@@ -59,4 +59,8 @@ specific_include_rules = {
"tab_scrubber\.cc": [
"+ash/shell.h",
],
"screen_rotation_interactive_uitest\.cc": [
"+ash/rotator/screen_rotation_animator.h",
"+ash/rotator/screen_rotation_animator_observer.h",
],
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/rotator/screen_rotation_animator_observer.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/task/post_task.h"
#include "chrome/browser/ui/ash/ash_test_util.h"
#include "chrome/browser/ui/ash/tablet_mode_client_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/perf/performance_test.h"
#include "ui/aura/window.h"
#include "ui/base/test/ui_controls.h"
// Test overview enter/exit animations with following conditions
// int: number of windows : 2, 8
// bool: the tab content (chrome://blank, chrome://newtab)
// bool: overview mode
class ScreenRotationTest
: public UIPerformanceTest,
public testing::WithParamInterface<::testing::tuple<int, bool, bool>> {
public:
ScreenRotationTest() = default;
~ScreenRotationTest() override = default;
// UIPerformanceTest:
void SetUpOnMainThread() override {
UIPerformanceTest::SetUpOnMainThread();
test::SetAndWaitForTabletMode(true);
auto* pref = browser()->profile()->GetPrefs();
pref->SetBoolean(
ash::prefs::kDisplayRotationAcceleratorDialogHasBeenAccepted, true);
int additional_browsers = std::get<0>(GetParam()) - 1;
ntp_page_ = std::get<1>(GetParam());
overview_mode_ = std::get<2>(GetParam());
GURL ntp_url("chrome://newtab");
// The default is blank page.
if (ntp_page_)
ui_test_utils::NavigateToURL(browser(), ntp_url);
for (int i = additional_browsers; i > 0; i--) {
Browser* new_browser = CreateBrowser(browser()->profile());
if (ntp_page_)
ui_test_utils::NavigateToURL(new_browser, ntp_url);
}
float cost_per_browser = ntp_page_ ? 0.5 : 0.1;
int wait_seconds = (base::SysInfo::IsRunningOnChromeOS() ? 5 : 0) +
additional_browsers * cost_per_browser;
base::RunLoop run_loop;
base::PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(wait_seconds));
run_loop.Run();
}
// UIPerformanceTest:
std::vector<std::string> GetUMAHistogramNames() const override {
return {"Ash.Rotation.AnimationSmoothness"};
}
bool overview_mode() const { return overview_mode_; }
bool ntp_page() const { return ntp_page_; }
private:
bool overview_mode_ = false;
bool ntp_page_ = false;
DISALLOW_COPY_AND_ASSIGN(ScreenRotationTest);
};
class ScreenRotationWaiter : public ash::ScreenRotationAnimatorObserver {
public:
explicit ScreenRotationWaiter(aura::Window* root_window)
: animator_(ash::ScreenRotationAnimator::GetForRootWindow(root_window)) {
animator_->AddObserver(this);
}
~ScreenRotationWaiter() override { animator_->RemoveObserver(this); }
// ash::ScreenRotationAnimationObserver:
void OnScreenCopiedBeforeRotation() override {}
void OnScreenRotationAnimationFinished(ash::ScreenRotationAnimator* animator,
bool canceled) override {
run_loop_.Quit();
}
void Wait() { run_loop_.Run(); }
private:
base::RunLoop run_loop_;
ash::ScreenRotationAnimator* animator_;
DISALLOW_COPY_AND_ASSIGN(ScreenRotationWaiter);
};
IN_PROC_BROWSER_TEST_P(ScreenRotationTest, RotateInTable) {
// Browser window is used just to identify display.
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
gfx::NativeWindow browser_window =
browser_view->GetWidget()->GetNativeWindow();
if (overview_mode()) {
ui_controls::SendKeyPress(browser_window, ui::VKEY_MEDIA_LAUNCH_APP1,
/*control=*/false,
/*shift=*/false,
/*alt=*/false,
/*command=*/false);
test::WaitForOverviewAnimationState(
ash::mojom::OverviewAnimationState::kEnterAnimationComplete);
// If we don't wait, it may skip animation (that is, it shift directly to
// the target state) on debug build.
// TODO(oshima): Consider disabling native perf test on debug build.
if (ntp_page()) {
base::RunLoop run_loop;
base::PostDelayedTask(FROM_HERE, run_loop.QuitClosure(),
base::TimeDelta::FromSeconds(1));
run_loop.Run();
}
}
ScreenRotationWaiter waiter(browser_window->GetRootWindow());
ui_controls::SendKeyPress(browser_window, ui::VKEY_BROWSER_REFRESH,
/*control=*/true,
/*shift=*/true,
/*alt=*/false,
/*command=*/false);
waiter.Wait();
}
// TODO(oshma): Support split screen in tablet mode
INSTANTIATE_TEST_SUITE_P(,
ScreenRotationTest,
::testing::Combine(::testing::Values(2, 8),
/*blank=*/testing::Bool(),
/*tablet=*/testing::Bool()));
......@@ -5286,6 +5286,7 @@ if (!is_android) {
"../browser/ui/ash/launcher_drag_interactive_uitest.cc",
"../browser/ui/ash/overview_animations_interactive_uitest.cc",
"../browser/ui/ash/overview_window_drag_interactive_uitest.cc",
"../browser/ui/ash/screen_rotation_interactive_uitest.cc",
"../browser/ui/ash/split_view_interactive_uitest.cc",
"base/perf/drag_event_generator.cc",
"base/perf/drag_event_generator.h",
......
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