Commit aa890843 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Commit Bot

Revert "overview: Introduce OnOverviewStartAnimationComplete observer."

This reverts commit 77cbc4f0.

Reason for revert:
Suspect compile failure on linux-chromeos-dbg.

Example:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/linux-chromeos-dbg/8511

Log:
FAILED: ash_unittests 
../../buildtools/third_party/libc++/trunk/include/memory:5091: error: undefined reference to 'ash::StartAnimationObserver::StartAnimationObserver()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Original change's description:
> overview: Introduce OnOverviewStartAnimationComplete observer.
> 
> Introdue a new overview observer which notifies observers when the start
> animation for overview is different.
> 
> Uses will be both in and out of overview - for example adding mask, shadow
> and animating tray, shelf.
> 
> Also modify CleanupObserverTest to use some new stuff.
> 
> Test: ash_unittests StartAnimationObserverTest.Basic
> Bug: 898222
> Change-Id: I86bdd253f0a4a4dd81ad6ba03780baf07923d256
> Reviewed-on: https://chromium-review.googlesource.com/c/1297405
> Commit-Queue: Sammie Quon <sammiequon@chromium.org>
> Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#602941}

TBR=oshima@chromium.org,sammiequon@chromium.org

Change-Id: I5038dbe64ae02fb0f71a7c4ffcc36bcfaaca13ca
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 898222
Reviewed-on: https://chromium-review.googlesource.com/c/1300815Reviewed-by: default avatarTakashi Sakamoto <tasak@google.com>
Commit-Queue: Takashi Sakamoto <tasak@google.com>
Cr-Commit-Position: refs/heads/master@{#602972}
parent bf48cde8
......@@ -1187,8 +1187,6 @@ component("ash") {
"wm/overview/scoped_overview_animation_settings.h",
"wm/overview/scoped_transform_overview_window.cc",
"wm/overview/scoped_transform_overview_window.h",
"wm/overview/start_animation_observer.cc",
"wm/overview/start_animation_observer.h",
"wm/overview/window_grid.cc",
"wm/overview/window_grid.h",
"wm/overview/window_selector.cc",
......@@ -1933,7 +1931,6 @@ test("ash_unittests") {
"wm/overlay_event_filter_unittest.cc",
"wm/overlay_layout_manager_unittest.cc",
"wm/overview/cleanup_animation_observer_unittest.cc",
"wm/overview/start_animation_observer_unittest.cc",
"wm/overview/window_selector_controller_unittest.cc",
"wm/overview/window_selector_unittest.cc",
"wm/pip/pip_positioner_unittest.cc",
......
......@@ -521,9 +521,8 @@ void AppListControllerImpl::OnOverviewModeEnding() {
WindowSelector::EnterExitOverviewType::kWindowsMinimized;
}
void AppListControllerImpl::OnOverviewModeEndingAnimationComplete(
bool canceled) {
if (!IsHomeLauncherEnabledInTabletMode() || canceled)
void AppListControllerImpl::OnOverviewModeEndingAnimationComplete() {
if (!IsHomeLauncherEnabledInTabletMode())
return;
presenter_.ScheduleOverviewModeAnimation(/*start=*/false,
......
......@@ -197,7 +197,7 @@ class ASH_EXPORT AppListControllerImpl
// ShellObserver:
void OnOverviewModeStarting() override;
void OnOverviewModeEnding() override;
void OnOverviewModeEndingAnimationComplete(bool canceled) override;
void OnOverviewModeEndingAnimationComplete() override;
// TabletModeObserver:
void OnTabletModeStarted() override;
......
......@@ -585,11 +585,6 @@ void Shell::NotifyOverviewModeStarting() {
observer.OnOverviewModeStarting();
}
void Shell::NotifyOverviewModeStartingAnimationComplete(bool canceled) {
for (auto& observer : shell_observers_)
observer.OnOverviewModeStartingAnimationComplete(canceled);
}
void Shell::NotifyOverviewModeEnding() {
for (auto& observer : shell_observers_)
observer.OnOverviewModeEnding();
......@@ -600,9 +595,9 @@ void Shell::NotifyOverviewModeEnded() {
observer.OnOverviewModeEnded();
}
void Shell::NotifyOverviewModeEndingAnimationComplete(bool canceled) {
void Shell::NotifyOverviewModeEndingAnimationComplete() {
for (auto& observer : shell_observers_)
observer.OnOverviewModeEndingAnimationComplete(canceled);
observer.OnOverviewModeEndingAnimationComplete();
}
void Shell::NotifySplitViewModeStarting() {
......
......@@ -602,18 +602,15 @@ class ASH_EXPORT Shell : public SessionObserver,
// windows get re-arranged).
void NotifyOverviewModeStarting();
// Notifies observers that the start overview mode animation has completed.
void NotifyOverviewModeStartingAnimationComplete(bool canceled);
// Notifies observers that overview mode is about to end (before the windows
// Notifies observers that overview mode is about to end (bofore the windows
// restore themselves).
void NotifyOverviewModeEnding();
// Notifies observers that overview mode has ended.
void NotifyOverviewModeEnded();
// Notifies observers that the end overview mode animation has completed.
void NotifyOverviewModeEndingAnimationComplete(bool canceled);
// Notifies observers that the end overivew mode animation has completed.
void NotifyOverviewModeEndingAnimationComplete();
// Notifies observers that split view mode is about to be started (before the
// window gets snapped and activated).
......
......@@ -45,11 +45,6 @@ class ASH_EXPORT ShellObserver {
// get re-arranged).
virtual void OnOverviewModeStarting() {}
// Called after the animations that happen when overview mode is started are
// complete. If |canceled| it means overview was quit before the start
// animations were finished.
virtual void OnOverviewModeStartingAnimationComplete(bool canceled) {}
// Called when the overview mode is about to end (bofore the windows restore
// themselves).
virtual void OnOverviewModeEnding() {}
......@@ -58,9 +53,8 @@ class ASH_EXPORT ShellObserver {
virtual void OnOverviewModeEnded() {}
// Called after the animations that happen when overview mode is ended are
// complete. If |canceled| it means overview was reentered before the exit
// animations were finished.
virtual void OnOverviewModeEndingAnimationComplete(bool canceled) {}
// complete.
virtual void OnOverviewModeEndingAnimationComplete() {}
// Called when the split view mode is about to be started before the window
// gets snapped and activated).
......
......@@ -37,8 +37,6 @@ class ASH_EXPORT CleanupAnimationObserver
void Shutdown() override;
private:
FRIEND_TEST_ALL_PREFIXES(WindowSelectorTest, OverviewExitAnimationObserver);
std::unique_ptr<views::Widget> widget_;
WindowSelectorDelegate* owner_;
......
......@@ -8,7 +8,6 @@
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/window_selector_delegate.h"
#include "base/containers/unique_ptr_adapters.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
......@@ -42,14 +41,22 @@ class TestWindowSelectorDelegate : public WindowSelectorDelegate {
void RemoveAndDestroyAnimationObserver(
DelayedAnimationObserver* animation_observer) override {
base::EraseIf(observers_, base::MatchesUniquePtr(animation_observer));
class IsEqual {
public:
explicit IsEqual(DelayedAnimationObserver* animation_observer)
: animation_observer_(animation_observer) {}
bool operator()(const std::unique_ptr<DelayedAnimationObserver>& other) {
return (other.get() == animation_observer_);
}
private:
const DelayedAnimationObserver* animation_observer_;
};
observers_.erase(std::remove_if(observers_.begin(), observers_.end(),
IsEqual(animation_observer)),
observers_.end());
}
void AddStartAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) override {}
void RemoveAndDestroyStartAnimationObserver(
DelayedAnimationObserver* animation_observer) override {}
private:
std::vector<std::unique_ptr<DelayedAnimationObserver>> observers_;
......@@ -71,7 +78,7 @@ class CleanupAnimationObserverTest : public AshTestBase,
// cause a window to be closed via
// views::Widget::GetWidgetForNativeView(window)->Close().
std::unique_ptr<views::Widget> CreateWindowWidget(const gfx::Rect& bounds) {
auto widget = std::make_unique<views::Widget>();
std::unique_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.bounds = bounds;
params.type = views::Widget::InitParams::TYPE_WINDOW;
......@@ -103,8 +110,10 @@ class CleanupAnimationObserverTest : public AshTestBase,
// Tests that basic create-destroy sequence does not crash.
TEST_F(CleanupAnimationObserverTest, CreateDestroy) {
TestWindowSelectorDelegate delegate;
std::unique_ptr<views::Widget> widget = CreateWindowWidget(gfx::Rect(40, 40));
auto observer = std::make_unique<CleanupAnimationObserver>(std::move(widget));
std::unique_ptr<views::Widget> widget(
CreateWindowWidget(gfx::Rect(0, 0, 40, 40)));
std::unique_ptr<CleanupAnimationObserver> observer(
new CleanupAnimationObserver(std::move(widget)));
delegate.AddDelayedAnimationObserver(std::move(observer));
}
......@@ -113,7 +122,8 @@ TEST_F(CleanupAnimationObserverTest, CreateDestroy) {
// owns the observer does not crash.
TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) {
TestWindowSelectorDelegate delegate;
std::unique_ptr<views::Widget> widget = CreateWindowWidget(gfx::Rect(40, 40));
std::unique_ptr<views::Widget> widget(
CreateWindowWidget(gfx::Rect(0, 0, 40, 40)));
aura::Window* widget_window = widget->GetNativeWindow();
{
ui::ScopedLayerAnimationSettings animation_settings(
......@@ -123,8 +133,8 @@ TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) {
animation_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
auto observer =
std::make_unique<CleanupAnimationObserver>(std::move(widget));
std::unique_ptr<CleanupAnimationObserver> observer(
new CleanupAnimationObserver(std::move(widget)));
animation_settings.AddObserver(observer.get());
delegate.AddDelayedAnimationObserver(std::move(observer));
......@@ -143,7 +153,8 @@ TEST_F(CleanupAnimationObserverTest, CreateAnimateComplete) {
// instance in destructor, this test would have crashed.
TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) {
TestWindowSelectorDelegate delegate;
std::unique_ptr<views::Widget> widget = CreateWindowWidget(gfx::Rect(40, 40));
std::unique_ptr<views::Widget> widget(
CreateWindowWidget(gfx::Rect(0, 0, 40, 40)));
aura::Window* widget_window = widget->GetNativeWindow();
{
// Normal animations for tests have ZERO_DURATION, make sure we are actually
......@@ -157,8 +168,8 @@ TEST_F(CleanupAnimationObserverTest, CreateAnimateShutdown) {
animation_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
auto observer =
std::make_unique<CleanupAnimationObserver>(std::move(widget));
std::unique_ptr<CleanupAnimationObserver> observer(
new CleanupAnimationObserver(std::move(widget)));
animation_settings.AddObserver(observer.get());
delegate.AddDelayedAnimationObserver(std::move(observer));
......
......@@ -13,10 +13,8 @@
#include "ash/wm/overview/drop_target_view.h"
#include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/scoped_overview_animation_settings.h"
#include "ash/wm/overview/start_animation_observer.h"
#include "ash/wm/overview/window_grid.h"
#include "ash/wm/overview/window_selector.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/window_mirror_view.h"
#include "ash/wm/window_state.h"
......@@ -271,16 +269,6 @@ void ScopedTransformOverviewWindow::BeginScopedAnimation(
auto settings = std::make_unique<ScopedOverviewAnimationSettings>(
animation_type, window);
settings->DeferPaint();
// Create a start animation observer if this is an enter overview layout
// animation.
if (animation_type == OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS_ON_ENTER) {
auto start_observer = std::make_unique<StartAnimationObserver>();
settings->AddObserver(start_observer.get());
Shell::Get()->window_selector_controller()->AddStartAnimationObserver(
std::move(start_observer));
}
animation_settings->push_back(std::move(settings));
}
......
// Copyright 2018 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/overview/start_animation_observer.h"
namespace ash {
StartAnimationObserver::StartAnimationObserver() = default;
StartAnimationObserver::~StartAnimationObserver() = default;
void StartAnimationObserver::OnImplicitAnimationsCompleted() {
if (owner_)
owner_->RemoveAndDestroyStartAnimationObserver(this);
}
void StartAnimationObserver::SetOwner(WindowSelectorDelegate* owner) {
DCHECK(!owner_);
owner_ = owner;
}
void StartAnimationObserver::Shutdown() {
owner_ = nullptr;
}
} // namespace ash
\ No newline at end of file
// Copyright 2018 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_OVERVIEW_START_ANIMATION_OBSERVER_H_
#define ASH_WM_OVERVIEW_START_ANIMATION_OBSERVER_H_
#include "ash/wm/overview/window_selector_delegate.h"
#include "base/macros.h"
#include "ui/compositor/layer_animation_observer.h"
namespace ash {
// An observer which watches a overview start animation and signals its owner
// when the animation it is watching finishes.
class StartAnimationObserver : public ui::ImplicitAnimationObserver,
public DelayedAnimationObserver {
public:
StartAnimationObserver();
~StartAnimationObserver() override;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override;
// DelayedAnimationObserver:
void SetOwner(WindowSelectorDelegate* owner) override;
void Shutdown() override;
private:
WindowSelectorDelegate* owner_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(StartAnimationObserver);
};
} // namespace ash
#endif // ASH_WM_OVERVIEW_START_ANIMATION_OBSERVER_H_
\ No newline at end of file
// Copyright 2018 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/overview/start_animation_observer.h"
#include <vector>
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/window_selector_delegate.h"
#include "base/containers/unique_ptr_adapters.h"
#include "ui/aura/window.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/transform.h"
namespace ash {
namespace {
class TestWindowSelectorDelegate : public WindowSelectorDelegate {
public:
TestWindowSelectorDelegate() = default;
~TestWindowSelectorDelegate() override = default;
// WindowSelectorDelegate:
void OnSelectionEnded() override {}
void AddDelayedAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) override {}
void RemoveAndDestroyAnimationObserver(
DelayedAnimationObserver* animation_observer) override {}
void AddStartAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) override {
animation_observer->SetOwner(this);
observers_.push_back(std::move(animation_observer));
}
void RemoveAndDestroyStartAnimationObserver(
DelayedAnimationObserver* animation_observer) override {
base::EraseIf(observers_, base::MatchesUniquePtr(animation_observer));
}
size_t NumObservers() const { return observers_.size(); }
private:
std::vector<std::unique_ptr<DelayedAnimationObserver>> observers_;
DISALLOW_COPY_AND_ASSIGN(TestWindowSelectorDelegate);
};
} // namespace
using StartAnimationObserverTest = AshTestBase;
// Tests that adding a StartAnimationObserver works as intended.
TEST_F(StartAnimationObserverTest, Basic) {
TestWindowSelectorDelegate delegate;
std::unique_ptr<aura::Window> window = CreateTestWindow();
{
ui::ScopedLayerAnimationSettings animation_settings(
window->layer()->GetAnimator());
animation_settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(1000));
animation_settings.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
auto observer = std::make_unique<StartAnimationObserver>();
animation_settings.AddObserver(observer.get());
delegate.AddStartAnimationObserver(std::move(observer));
window->SetTransform(gfx::Transform(1.f, 0.f, 0.f, 1.f, 100.f, 0.f));
EXPECT_EQ(1u, delegate.NumObservers());
}
// Tests that when done animating, the observer count is zero.
window->layer()->GetAnimator()->StopAnimating();
EXPECT_EQ(0u, delegate.NumObservers());
}
} // namespace ash
\ No newline at end of file
......@@ -325,10 +325,6 @@ bool WindowSelectorController::ToggleOverview(
// Clear any animations that may be running from last overview end.
for (const auto& animation : delayed_animations_)
animation->Shutdown();
if (!delayed_animations_.empty()) {
Shell::Get()->NotifyOverviewModeStartingAnimationComplete(
/*canceled=*/true);
}
delayed_animations_.clear();
window_selector_ = std::make_unique<WindowSelector>(this);
......@@ -479,12 +475,6 @@ WindowSelectorController::GetWindowsListInOverviewGridsForTesting() {
void WindowSelectorController::OnSelectionEnded() {
if (is_shutting_down_)
return;
if (!start_animations_.empty()) {
Shell::Get()->NotifyOverviewModeEndingAnimationComplete(
/*canceled=*/true);
}
start_animations_.clear();
is_shutting_down_ = true;
Shell::Get()->NotifyOverviewModeEnding();
auto* window_selector = window_selector_.release();
......@@ -518,24 +508,7 @@ void WindowSelectorController::RemoveAndDestroyAnimationObserver(
if (!window_selector_ && !previous_empty && delayed_animations_.empty()) {
if (IsBlurAllowed())
overview_blur_controller_->Unblur();
Shell::Get()->NotifyOverviewModeEndingAnimationComplete(/*canceled=*/false);
}
}
void WindowSelectorController::AddStartAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) {
animation_observer->SetOwner(this);
start_animations_.push_back(std::move(animation_observer));
}
void WindowSelectorController::RemoveAndDestroyStartAnimationObserver(
DelayedAnimationObserver* animation_observer) {
const bool previous_empty = start_animations_.empty();
base::EraseIf(start_animations_, base::MatchesUniquePtr(animation_observer));
if (!previous_empty && start_animations_.empty()) {
Shell::Get()->NotifyOverviewModeStartingAnimationComplete(
/*canceled=*/false);
Shell::Get()->NotifyOverviewModeEndingAnimationComplete();
}
}
......
......@@ -22,11 +22,6 @@ class WindowSelectorTest;
// allows selecting a window to activate it.
class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
public:
enum class AnimationCompleteReason {
kCompleted,
kCanceled,
};
WindowSelectorController();
~WindowSelectorController() override;
......@@ -77,10 +72,6 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
std::unique_ptr<DelayedAnimationObserver> animation) override;
void RemoveAndDestroyAnimationObserver(
DelayedAnimationObserver* animation) override;
void AddStartAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) override;
void RemoveAndDestroyStartAnimationObserver(
DelayedAnimationObserver* animation_observer) override;
WindowSelector* window_selector() { return window_selector_.get(); }
......@@ -89,7 +80,6 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
friend class WindowSelectorTest;
FRIEND_TEST_ALL_PREFIXES(TabletModeControllerTest,
DisplayDisconnectionDuringOverview);
FRIEND_TEST_ALL_PREFIXES(WindowSelectorTest, OverviewExitAnimationObserver);
// There is no need to blur or unblur the wallpaper for tests.
static void SetDoNotChangeWallpaperBlurForTests();
......@@ -102,10 +92,6 @@ class ASH_EXPORT WindowSelectorController : public WindowSelectorDelegate {
// those animations are in progress, the animations are shut down and the
// widgets destroyed.
std::vector<std::unique_ptr<DelayedAnimationObserver>> delayed_animations_;
// Collection of DelayedAnimationObserver objects. When this becomes empty,
// notify shell that the starting animations have been completed.
std::vector<std::unique_ptr<DelayedAnimationObserver>> start_animations_;
std::unique_ptr<WindowSelector> window_selector_;
base::Time last_selection_time_;
......
......@@ -5,8 +5,6 @@
#ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_DELEGATE_H_
#define ASH_WM_OVERVIEW_WINDOW_SELECTOR_DELEGATE_H_
#include <memory>
#include "ash/ash_export.h"
#include "base/compiler_specific.h"
......@@ -39,24 +37,14 @@ class ASH_EXPORT WindowSelectorDelegate {
std::unique_ptr<DelayedAnimationObserver> animation_observer) = 0;
// Finds and erases |animation_observer| from the list deleting the widget
// owned by the |animation_observer|. This method should be called when a
// scheduled animation completes. If the animation completion callback is a
// result of a window getting destroyed then the
// DelayedAnimationObserver::Shutdown() should be called first before
// destroying the window.
// owned by the |animation_observer|.
// This method should be called when a scheduled animation completes.
// If the animation completion callback is a result of a window getting
// destroyed then the DelayedAnimationObserver::Shutdown() should be called
// first before destroying the window.
virtual void RemoveAndDestroyAnimationObserver(
DelayedAnimationObserver* animation_observer) = 0;
// Passes ownership of |animation_observer| to |this| delegate.
virtual void AddStartAnimationObserver(
std::unique_ptr<DelayedAnimationObserver> animation_observer) = 0;
// Finds and erases |animation_observer| from the list which tracks the start
// animations. This method should be called when a scheduled start overview
// animation completes.
virtual void RemoveAndDestroyStartAnimationObserver(
DelayedAnimationObserver* animation_observer) = 0;
protected:
virtual ~WindowSelectorDelegate() {}
};
......
......@@ -18,7 +18,6 @@
#include "ash/wm/overview/rounded_rect_view.h"
#include "ash/wm/overview/scoped_overview_animation_settings.h"
#include "ash/wm/overview/scoped_transform_overview_window.h"
#include "ash/wm/overview/start_animation_observer.h"
#include "ash/wm/overview/window_grid.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/splitview/split_view_constants.h"
......@@ -1180,16 +1179,6 @@ void WindowSelectorItem::UpdateHeaderLayout(
mode == HeaderFadeInMode::kFirstUpdate ? OVERVIEW_ANIMATION_NONE
: animation_type,
widget_window);
// Create a start animation observer if this is an enter overview layout
// animation.
if (animation_type == OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS_ON_ENTER) {
auto start_observer = std::make_unique<StartAnimationObserver>();
animation_settings.AddObserver(start_observer.get());
Shell::Get()->window_selector_controller()->AddStartAnimationObserver(
std::move(start_observer));
}
// |widget_window| covers both the transformed window and the header
// as well as the gap between the windows to prevent events from reaching
// the window including its sizing borders.
......
......@@ -28,7 +28,6 @@
#include "ash/system/tray/system_tray.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/overview/cleanup_animation_observer.h"
#include "ash/wm/overview/overview_utils.h"
#include "ash/wm/overview/overview_window_drag_controller.h"
#include "ash/wm/overview/window_grid.h"
......@@ -3109,25 +3108,19 @@ namespace {
// Test class that allows us to check what whether the last overview enter or
// exit was using a slide animation. This is needed because the cached slide
// animation variable may be reset or the WindowSelector object may not be
// available after a toggle has completed. Also stores whether the animation
// complete observers fired because an animation completed or was canceled.
class TestOverviewObserver : public ShellObserver {
// available after a toggle has completed.
class TestOverviewAnimationTypeObserver : public ShellObserver {
public:
TestOverviewObserver() { Shell::Get()->AddShellObserver(this); }
~TestOverviewObserver() override { Shell::Get()->RemoveShellObserver(this); }
TestOverviewAnimationTypeObserver() { Shell::Get()->AddShellObserver(this); }
~TestOverviewAnimationTypeObserver() override {
Shell::Get()->RemoveShellObserver(this);
}
// ShellObserver:
void OnOverviewModeStarting() override { UpdateLastAnimationWasSlide(); }
void OnOverviewModeEnding() override { UpdateLastAnimationWasSlide(); }
void OnOverviewModeStartingAnimationComplete(bool canceled) override {
animation_canceled_ = canceled;
}
void OnOverviewModeEndingAnimationComplete(bool canceled) override {
animation_canceled_ = canceled;
}
bool last_animation_was_slide() const { return last_animation_was_slide_; }
bool animation_canceled() const { return animation_canceled_; }
private:
void UpdateLastAnimationWasSlide() {
......@@ -3140,19 +3133,18 @@ class TestOverviewObserver : public ShellObserver {
}
bool last_animation_was_slide_ = false;
bool animation_canceled_ = false;
DISALLOW_COPY_AND_ASSIGN(TestOverviewObserver);
DISALLOW_COPY_AND_ASSIGN(TestOverviewAnimationTypeObserver);
};
} // namespace
// Tests the slide animation for overview is never used in clamshell.
TEST_F(WindowSelectorTest, OverviewEnterExitAnimation) {
TestOverviewObserver observer;
TestOverviewAnimationTypeObserver observer;
const gfx::Rect bounds(200, 200);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
ToggleOverview();
EXPECT_FALSE(observer.last_animation_was_slide());
......@@ -3162,7 +3154,7 @@ TEST_F(WindowSelectorTest, OverviewEnterExitAnimation) {
// Even with all window minimized, there should not be a slide animation.
ASSERT_FALSE(IsSelecting());
wm::GetWindowState(window.get())->Minimize();
wm::GetWindowState(window1.get())->Minimize();
ToggleOverview();
EXPECT_FALSE(observer.last_animation_was_slide());
}
......@@ -3171,7 +3163,7 @@ TEST_F(WindowSelectorTest, OverviewEnterExitAnimation) {
// are minimized, and that if overview is exited from the home launcher all
// windows are minimized.
TEST_F(WindowSelectorTest, OverviewEnterExitAnimationTablet) {
TestOverviewObserver observer;
TestOverviewAnimationTypeObserver observer;
// Ensure calls to EnableTabletModeWindowManager complete.
base::RunLoop().RunUntilIdle();
......@@ -3179,7 +3171,7 @@ TEST_F(WindowSelectorTest, OverviewEnterExitAnimationTablet) {
base::RunLoop().RunUntilIdle();
const gfx::Rect bounds(200, 200);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
ToggleOverview();
EXPECT_FALSE(observer.last_animation_was_slide());
......@@ -3189,77 +3181,13 @@ TEST_F(WindowSelectorTest, OverviewEnterExitAnimationTablet) {
ToggleOverview(WindowSelector::EnterExitOverviewType::kWindowsMinimized);
EXPECT_TRUE(observer.last_animation_was_slide());
ASSERT_FALSE(IsSelecting());
EXPECT_TRUE(wm::GetWindowState(window.get())->IsMinimized());
EXPECT_TRUE(wm::GetWindowState(window1.get())->IsMinimized());
// All windows are minimized, so we should use the slide animation.
ToggleOverview();
EXPECT_TRUE(observer.last_animation_was_slide());
}
// Tests that the overview enter animation observer works as expected.
TEST_F(WindowSelectorTest, OverviewEnterAnimationObserver) {
TestOverviewObserver observer;
ui::ScopedAnimationDurationScaleMode animation_scale_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
const gfx::Rect bounds(200, 200);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
// Test that if the animations are allowed to run out on enter the observer
// will be notified of complete animations.
ToggleOverview();
WindowSelectorItem* item = GetWindowItemForWindow(0, window.get());
window->layer()->GetAnimator()->StopAnimating();
item_widget(item)->GetNativeWindow()->layer()->GetAnimator()->StopAnimating();
EXPECT_FALSE(observer.animation_canceled());
ToggleOverview();
// Test that if the animations are canceled after entering by exiting overview
// right away, the observer will be notified of incomplete animations.
ToggleOverview();
ToggleOverview();
EXPECT_TRUE(observer.animation_canceled());
}
// Tests that the overview exit animation observer works as expected.
TEST_F(WindowSelectorTest, OverviewExitAnimationObserver) {
TestOverviewObserver observer;
ui::ScopedAnimationDurationScaleMode animation_scale_mode(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
const gfx::Rect bounds(200, 200);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
ToggleOverview();
// Test that if the animations are allowed to run out on exit the observer
// will be notified of complete animations.
ToggleOverview();
window->layer()->GetAnimator()->StopAnimating();
std::vector<std::unique_ptr<DelayedAnimationObserver>>& delayed_animations =
window_selector_controller()->delayed_animations_;
// On animation complete |delayed_animations| will erase its own members, so
// use a while loop to avoid indexing errors.
ASSERT_FALSE(delayed_animations.empty());
while (!delayed_animations.empty()) {
views::Widget* item_widget =
static_cast<CleanupAnimationObserver*>(delayed_animations.back().get())
->widget_.get();
item_widget->GetNativeWindow()->layer()->GetAnimator()->StopAnimating();
}
EXPECT_FALSE(observer.animation_canceled());
// Test that if the animations are canceled after exiting by reentering
// overview right away, the observer will be notified of incomplete
// animations.
ToggleOverview();
ToggleOverview();
EXPECT_TRUE(observer.animation_canceled());
}
// Tests that overview mode is entered with kWindowDragged mode when an app is
// dragged from the top of the screen.
TEST_F(WindowSelectorTest, DraggingFromTopAnimation) {
......
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