Commit 4c93f79b authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

desks: Add tests for RootWindowDeskSwitchAnimator.

Test: added
Bug: 1111445
Change-Id: I0f79be1c09d4ef0eeff276e3c50f491efbe56244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380517Reviewed-by: default avatarKhushal <khushalsagar@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809854}
parent 08252de5
......@@ -2171,6 +2171,7 @@ test("ash_unittests") {
"wm/default_window_resizer_unittest.cc",
"wm/desks/autotest_desks_api_unittests.cc",
"wm/desks/desks_unittests.cc",
"wm/desks/root_window_desk_switch_animator_unittest.cc",
"wm/drag_window_resizer_unittest.cc",
"wm/fullscreen_window_finder_unittest.cc",
"wm/gestures/back_gesture/back_gesture_affordance_unittest.cc",
......@@ -2540,6 +2541,8 @@ static_library("test_support") {
"wm/cursor_manager_test_api.h",
"wm/desks/desks_test_util.cc",
"wm/desks/desks_test_util.h",
"wm/desks/root_window_desk_switch_animator_test_api.cc",
"wm/desks/root_window_desk_switch_animator_test_api.h",
"wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.cc",
"wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h",
"wm/lock_state_controller_test_api.cc",
......
specific_include_rules = {
"root_window_desk_switch_animator_test_api.cc": [
# These tests create a fake viz::CopyOutputTextureResult to avoid the async
# way of waiting for a layer output request. So this needs to explicity
# depend on gpu/command_buffer/common.
"+gpu/command_buffer/common",
],
}
......@@ -29,9 +29,6 @@ namespace ash {
namespace {
// The space between the starting and ending desks screenshots in dips.
constexpr int kDesksSpacing = 50;
// The maximum number of times to retry taking a screenshot for either the
// starting or the ending desks. After this maximum number is reached, we ignore
// a failed screenshot request and proceed with next phases.
......@@ -50,12 +47,6 @@ constexpr base::TimeDelta kAnimationDuration =
// desk change.
constexpr int kTouchpadSwipeLengthForDeskChange = 100;
// The animation layer has extra padding at its two edges. The width in dips is
// a ratio of the root window width. This padding is to notify users there are
// no more desks on that side by showing a black region as we swipe
// continuously.
constexpr float kEdgePaddingRatio = 0.15f;
// The amount, by which the detached old layers of the removed desk's windows,
// is translated vertically during the for-remove desk switch animation.
constexpr int kRemovedDeskWindowYTranslation = 20;
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h"
#include "ui/compositor/layer_animation_observer.h"
......@@ -157,7 +158,8 @@ namespace ash {
// slightly more to accommodate the continuous desk animations feature. The base
// algorithm is still valid, but once the features are near completion these
// need to be updated.
class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
class ASH_EXPORT RootWindowDeskSwitchAnimator
: public ui::ImplicitAnimationObserver {
public:
class Delegate {
public:
......@@ -179,6 +181,15 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
virtual ~Delegate() = default;
};
// The space between the starting and ending desks screenshots in dips.
static constexpr int kDesksSpacing = 50;
// The animation layer has extra padding at its two edges. The width in dips
// is a ratio of the root window width. This padding is to notify users there
// are no more desks on that side by showing a black region as we swipe
// continuously.
static constexpr float kEdgePaddingRatio = 0.15f;
RootWindowDeskSwitchAnimator(aura::Window* root,
int starting_desk_index,
int ending_desk_index,
......@@ -235,6 +246,8 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
void OnImplicitAnimationsCompleted() override;
private:
friend class RootWindowDeskSwitchAnimatorTestApi;
// Completes the first phase of the animation using the given |layer| as the
// screenshot layer of the starting desk. This layer will be parented to the
// animation layer, which will be setup with its initial transform according
......
// Copyright 2020 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/wm/desks/root_window_desk_switch_animator_test_api.h"
#include <memory>
#include "ash/wm/desks/root_window_desk_switch_animator.h"
#include "base/strings/string_number_conversions.h"
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
#include "ui/gfx/color_space.h"
namespace ash {
namespace {
int g_mailbox_id = 0;
// Creates a blank copy output result the size of |root_window|.
std::unique_ptr<viz::CopyOutputResult> CreateCopyOutputResult(
aura::Window* root_window) {
std::string mailbox_name =
"mailboxname" + base::NumberToString(g_mailbox_id++);
gpu::Mailbox mailbox;
mailbox.SetName(reinterpret_cast<const int8_t*>(mailbox_name.c_str()));
std::unique_ptr<viz::CopyOutputResult> copy_result =
std::make_unique<viz::CopyOutputTextureResult>(
root_window->bounds(), mailbox, gpu::SyncToken(),
gfx::ColorSpace::CreateSRGB(),
viz::SingleReleaseCallback::Create(base::DoNothing()));
DCHECK(!copy_result->IsEmpty());
return copy_result;
}
} // namespace
RootWindowDeskSwitchAnimatorTestApi::RootWindowDeskSwitchAnimatorTestApi(
RootWindowDeskSwitchAnimator* animator)
: animator_(animator) {
DCHECK(animator_);
}
RootWindowDeskSwitchAnimatorTestApi::~RootWindowDeskSwitchAnimatorTestApi() =
default;
void RootWindowDeskSwitchAnimatorTestApi::OnStartingDeskScreenshotTaken() {
animator_->OnStartingDeskScreenshotTaken(
CreateCopyOutputResult(animator_->root_window_));
}
void RootWindowDeskSwitchAnimatorTestApi::OnEndingDeskScreenshotTaken() {
animator_->OnEndingDeskScreenshotTaken(
CreateCopyOutputResult(animator_->root_window_));
}
ui::Layer* RootWindowDeskSwitchAnimatorTestApi::GetAnimationLayer() {
return animator_->animation_layer_owner_->root();
}
ui::Layer*
RootWindowDeskSwitchAnimatorTestApi::GetScreenshotLayerOfDeskWithIndex(
int desk_index) {
auto screenshot_layers = animator_->screenshot_layers_;
DCHECK_GE(desk_index, 0);
DCHECK_LT(desk_index, int{screenshot_layers.size()});
ui::Layer* layer = screenshot_layers[desk_index];
DCHECK(layer);
return layer;
}
int RootWindowDeskSwitchAnimatorTestApi::GetEndingDeskIndex() const {
return animator_->ending_desk_index_;
}
} // namespace ash
// Copyright 2020 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.
#ifndef ASH_WM_DESKS_ROOT_WINDOW_DESK_SWITCH_ANIMATOR_TEST_API_H_
#define ASH_WM_DESKS_ROOT_WINDOW_DESK_SWITCH_ANIMATOR_TEST_API_H_
namespace ui {
class Layer;
}
namespace ash {
class RootWindowDeskSwitchAnimator;
// Use the api in this class to test the internals of
// RootWindowDeskSwitchAnimator.
class RootWindowDeskSwitchAnimatorTestApi {
public:
explicit RootWindowDeskSwitchAnimatorTestApi(
RootWindowDeskSwitchAnimator* animator);
RootWindowDeskSwitchAnimatorTestApi(
const RootWindowDeskSwitchAnimatorTestApi&) = delete;
RootWindowDeskSwitchAnimatorTestApi& operator=(
const RootWindowDeskSwitchAnimatorTestApi&) = delete;
~RootWindowDeskSwitchAnimatorTestApi();
// Triggers the path taken when a screenshot is taken. Uses a blank
// viz::CopyOutputResult and is synchronous.
void OnStartingDeskScreenshotTaken();
void OnEndingDeskScreenshotTaken();
// Getters for the layers associated with the animation.
ui::Layer* GetAnimationLayer();
ui::Layer* GetScreenshotLayerOfDeskWithIndex(int desk_index);
int GetEndingDeskIndex() const;
private:
RootWindowDeskSwitchAnimator* const animator_;
};
} // namespace ash
#endif // ASH_WM_DESKS_ROOT_WINDOW_DESK_SWITCH_ANIMATOR_TEST_API_H_
This diff is collapsed.
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