Commit 341bf50b authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

Reland "desks: Add tests for RootWindowDeskSwitchAnimator."

This is a reland of 4c93f79b. The
original change patch is in ps1.

The reason for the revert was an error was something with managing
GPU textures (mailbox name not found). Tried copying some GPU test
code [1] but still got the same error and was building up a lot of
GPU dependencies.

Instead of creating fake output, this cl wraps the existing
TakeScreenshot calls and puts a waiter in.

[1] https://source.chromium.org/chromium/chromium/src/+/master:components/viz/test/fake_skia_output_surface.cc;drc=361ef8a161b516ba106966bb0740314c41dc2678;l=272

Original change's description:
> desks: Add tests for RootWindowDeskSwitchAnimator.
>
> Test: added
> Bug: 1111445
> Change-Id: I0f79be1c09d4ef0eeff276e3c50f491efbe56244
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380517
> Reviewed-by: Khushal <khushalsagar@chromium.org>
> Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
> Commit-Queue: Sammie Quon <sammiequon@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#809854}

Bug: 1111445
Change-Id: Ib4e50c22fb063b82f50c3f4f79bb026e648a6157
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429363
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810754}
parent 7a32afe1
...@@ -2174,6 +2174,7 @@ test("ash_unittests") { ...@@ -2174,6 +2174,7 @@ test("ash_unittests") {
"wm/default_window_resizer_unittest.cc", "wm/default_window_resizer_unittest.cc",
"wm/desks/autotest_desks_api_unittests.cc", "wm/desks/autotest_desks_api_unittests.cc",
"wm/desks/desks_unittests.cc", "wm/desks/desks_unittests.cc",
"wm/desks/root_window_desk_switch_animator_unittest.cc",
"wm/drag_window_resizer_unittest.cc", "wm/drag_window_resizer_unittest.cc",
"wm/fullscreen_window_finder_unittest.cc", "wm/fullscreen_window_finder_unittest.cc",
"wm/gestures/back_gesture/back_gesture_affordance_unittest.cc", "wm/gestures/back_gesture/back_gesture_affordance_unittest.cc",
...@@ -2543,6 +2544,8 @@ static_library("test_support") { ...@@ -2543,6 +2544,8 @@ static_library("test_support") {
"wm/cursor_manager_test_api.h", "wm/cursor_manager_test_api.h",
"wm/desks/desks_test_util.cc", "wm/desks/desks_test_util.cc",
"wm/desks/desks_test_util.h", "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.cc",
"wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h", "wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h",
"wm/lock_state_controller_test_api.cc", "wm/lock_state_controller_test_api.cc",
......
...@@ -29,9 +29,6 @@ namespace ash { ...@@ -29,9 +29,6 @@ namespace ash {
namespace { 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 // 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 // starting or the ending desks. After this maximum number is reached, we ignore
// a failed screenshot request and proceed with next phases. // a failed screenshot request and proceed with next phases.
...@@ -50,12 +47,6 @@ constexpr base::TimeDelta kAnimationDuration = ...@@ -50,12 +47,6 @@ constexpr base::TimeDelta kAnimationDuration =
// desk change. // desk change.
constexpr int kTouchpadSwipeLengthForDeskChange = 100; 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, // The amount, by which the detached old layers of the removed desk's windows,
// is translated vertically during the for-remove desk switch animation. // is translated vertically during the for-remove desk switch animation.
constexpr int kRemovedDeskWindowYTranslation = 20; constexpr int kRemovedDeskWindowYTranslation = 20;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "ash/ash_export.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
...@@ -157,7 +158,8 @@ namespace ash { ...@@ -157,7 +158,8 @@ namespace ash {
// slightly more to accommodate the continuous desk animations feature. The base // slightly more to accommodate the continuous desk animations feature. The base
// algorithm is still valid, but once the features are near completion these // algorithm is still valid, but once the features are near completion these
// need to be updated. // need to be updated.
class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { class ASH_EXPORT RootWindowDeskSwitchAnimator
: public ui::ImplicitAnimationObserver {
public: public:
class Delegate { class Delegate {
public: public:
...@@ -179,6 +181,15 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -179,6 +181,15 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
virtual ~Delegate() = default; 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, RootWindowDeskSwitchAnimator(aura::Window* root,
int starting_desk_index, int starting_desk_index,
int ending_desk_index, int ending_desk_index,
...@@ -235,6 +246,8 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver { ...@@ -235,6 +246,8 @@ class RootWindowDeskSwitchAnimator : public ui::ImplicitAnimationObserver {
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
private: private:
friend class RootWindowDeskSwitchAnimatorTestApi;
// Completes the first phase of the animation using the given |layer| as the // 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 // screenshot layer of the starting desk. This layer will be parented to the
// animation layer, which will be setup with its initial transform according // 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 "ash/wm/desks/root_window_desk_switch_animator.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_tree_owner.h"
namespace ash {
RootWindowDeskSwitchAnimatorTestApi::RootWindowDeskSwitchAnimatorTestApi(
RootWindowDeskSwitchAnimator* animator)
: animator_(animator) {
DCHECK(animator_);
}
RootWindowDeskSwitchAnimatorTestApi::~RootWindowDeskSwitchAnimatorTestApi() =
default;
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();
// 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