Commit fc462640 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

setTabletModeEnabled test API to force into the specified mode

This changes the behavior of autotestPrivate.setTabletModeEnabled;
it will ensure entering into the specified mode, and will not
end and will not be affected by peripherals.

As is described in the bug, it is crucial to ensure into a certain
mode for conducting an integration test or a performance test, but
sometimes the test scenarios or existence of peripherals can affect
the intermediate states, which may cause failures when combined
with multiple tests. This CL simplifies this situation by adding
a new method to ash::TabletMode.

Note that we can't change the behavior of existing SetEnabledForTest,
because it is widely used by unittests and browsertests.

Bug: 1040292
Test: tast run ui.ScreenRotationPerf ui.WindowResizePerf on scarlet
Change-Id: I343e2b86c145bae789629df1baaf503fa2dfdef5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016193Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735676}
parent 15c951cb
...@@ -43,6 +43,15 @@ class ASH_PUBLIC_EXPORT TabletMode { ...@@ -43,6 +43,15 @@ class ASH_PUBLIC_EXPORT TabletMode {
// Returns true if the system is in tablet mode. // Returns true if the system is in tablet mode.
virtual bool InTabletMode() const = 0; virtual bool InTabletMode() const = 0;
// Force the tablet mode state for integration tests. The meaning of |enabled|
// are as follows:
// true: UI in the tablet mode
// false: UI in the clamshell mode
// nullopt: reset the forcing, UI in the default behavior (i.e. checking the
// physical state).
virtual void ForceUiTabletModeState(base::Optional<bool> enabled) = 0;
// Enable/disable the tablet mode. Used only by test cases.
virtual void SetEnabledForTest(bool enabled) = 0; virtual void SetEnabledForTest(bool enabled) = 0;
protected: protected:
......
...@@ -436,6 +436,25 @@ bool TabletModeController::InTabletMode() const { ...@@ -436,6 +436,25 @@ bool TabletModeController::InTabletMode() const {
return state_ == State::kInTabletMode || state_ == State::kEnteringTabletMode; return state_ == State::kInTabletMode || state_ == State::kEnteringTabletMode;
} }
void TabletModeController::ForceUiTabletModeState(
base::Optional<bool> enabled) {
if (!enabled.has_value()) {
tablet_mode_behavior_ = kDefault;
forced_ui_mode_ = UiMode::kNone;
if (!SetIsInTabletPhysicalState(CalculateIsInTabletPhysicalState()))
UpdateUiTabletState();
return;
}
if (*enabled) {
tablet_mode_behavior_ = kLockInTabletMode;
forced_ui_mode_ = UiMode::kTabletMode;
} else {
tablet_mode_behavior_ = kLockInClamshellMode;
forced_ui_mode_ = UiMode::kClamshell;
}
UpdateUiTabletState();
}
void TabletModeController::SetEnabledForTest(bool enabled) { void TabletModeController::SetEnabledForTest(bool enabled) {
tablet_mode_behavior_ = enabled ? kOnForTest : kDefault; tablet_mode_behavior_ = enabled ? kOnForTest : kDefault;
...@@ -1111,9 +1130,9 @@ bool TabletModeController::ShouldUiBeInTabletMode() const { ...@@ -1111,9 +1130,9 @@ bool TabletModeController::ShouldUiBeInTabletMode() const {
return is_in_tablet_physical_state_; return is_in_tablet_physical_state_;
} }
void TabletModeController::SetIsInTabletPhysicalState(bool new_state) { bool TabletModeController::SetIsInTabletPhysicalState(bool new_state) {
if (new_state == is_in_tablet_physical_state_) if (new_state == is_in_tablet_physical_state_)
return; return false;
is_in_tablet_physical_state_ = new_state; is_in_tablet_physical_state_ = new_state;
...@@ -1123,9 +1142,10 @@ void TabletModeController::SetIsInTabletPhysicalState(bool new_state) { ...@@ -1123,9 +1142,10 @@ void TabletModeController::SetIsInTabletPhysicalState(bool new_state) {
// InputDeviceBlocker must always be updated, but don't update it here if the // InputDeviceBlocker must always be updated, but don't update it here if the
// UI state has changed because it's already done. // UI state has changed because it's already done.
if (UpdateUiTabletState()) if (UpdateUiTabletState())
return; return true;
UpdateInternalInputDevicesEventBlocker(); UpdateInternalInputDevicesEventBlocker();
return true;
} }
bool TabletModeController::UpdateUiTabletState() { bool TabletModeController::UpdateUiTabletState() {
......
...@@ -123,6 +123,7 @@ class ASH_EXPORT TabletModeController ...@@ -123,6 +123,7 @@ class ASH_EXPORT TabletModeController
// about to be initialized. When it is about to be shutdown, we are considered // about to be initialized. When it is about to be shutdown, we are considered
// out of tablet mode. // out of tablet mode.
bool InTabletMode() const override; bool InTabletMode() const override;
void ForceUiTabletModeState(base::Optional<bool> enabled) override;
void SetEnabledForTest(bool enabled) override; void SetEnabledForTest(bool enabled) override;
// ShellObserver: // ShellObserver:
...@@ -297,8 +298,9 @@ class ASH_EXPORT TabletModeController ...@@ -297,8 +298,9 @@ class ASH_EXPORT TabletModeController
bool ShouldUiBeInTabletMode() const; bool ShouldUiBeInTabletMode() const;
// Sets |is_in_tablet_physical_state_| to |new_state| and potentially updating // Sets |is_in_tablet_physical_state_| to |new_state| and potentially updating
// the UI tablet mode state if needed. // the UI tablet mode state if needed. Returns true if the
void SetIsInTabletPhysicalState(bool new_state); // |is_in_tablet_physical_state_| has been changed.
bool SetIsInTabletPhysicalState(bool new_state);
// Updates the UI by either entering or exiting UI tablet mode if necessary // Updates the UI by either entering or exiting UI tablet mode if necessary
// based on the current state. Returns true if there's a change in the UI // based on the current state. Returns true if there's a change in the UI
......
...@@ -58,6 +58,8 @@ class FakeTabletMode : public ash::TabletMode { ...@@ -58,6 +58,8 @@ class FakeTabletMode : public ash::TabletMode {
bool InTabletMode() const override { return in_tablet_mode; } bool InTabletMode() const override { return in_tablet_mode; }
void ForceUiTabletModeState(base::Optional<bool> enabled) override {}
void SetEnabledForTest(bool enabled) override { void SetEnabledForTest(bool enabled) override {
bool changed = (in_tablet_mode != enabled); bool changed = (in_tablet_mode != enabled);
in_tablet_mode = enabled; in_tablet_mode = enabled;
......
...@@ -2628,7 +2628,7 @@ AutotestPrivateSetTabletModeEnabledFunction::Run() { ...@@ -2628,7 +2628,7 @@ AutotestPrivateSetTabletModeEnabledFunction::Run() {
api::autotest_private::SetTabletModeEnabled::Params::Create(*args_)); api::autotest_private::SetTabletModeEnabled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params); EXTENSION_FUNCTION_VALIDATE(params);
ash::TabletMode::Waiter waiter(params->enabled); ash::TabletMode::Waiter waiter(params->enabled);
ash::TabletMode::Get()->SetEnabledForTest(params->enabled); ash::TabletMode::Get()->ForceUiTabletModeState(params->enabled);
waiter.Wait(); waiter.Wait();
return RespondNow(OneArgument( return RespondNow(OneArgument(
std::make_unique<base::Value>(ash::TabletMode::Get()->InTabletMode()))); std::make_unique<base::Value>(ash::TabletMode::Get()->InTabletMode())));
......
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