This source file includes following definitions.
- GetZPosition
- GetWindowZPosition
- GetLayerZPosition
- TearDown
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- OnWindowHidingAnimationCompleted
- SetHostTransitionOffsets
- hide_completed
- TEST_F
#include "ui/wm/core/window_animations.h"
#include "base/time/time.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/animation/animation_container_element.h"
#include "ui/gfx/vector2d.h"
#include "ui/wm/core/transient_window_manager.h"
#include "ui/wm/core/transient_window_stacking_client.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/animation_host.h"
using aura::Window;
using ui::Layer;
namespace wm {
namespace {
template<typename T>int GetZPosition(const T* child) {
const T* parent = child->parent();
const std::vector<T*> children = parent->children();
typename std::vector<T*>::const_iterator iter =
std::find(children.begin(), children.end(), child);
DCHECK(iter != children.end());
return iter - children.begin();
}
int GetWindowZPosition(const aura::Window* child) {
return GetZPosition<aura::Window>(child);
}
int GetLayerZPosition(const ui::Layer* child) {
return GetZPosition<ui::Layer>(child);
}
}
class WindowAnimationsTest : public aura::test::AuraTestBase {
public:
WindowAnimationsTest() {}
virtual void TearDown() OVERRIDE {
AuraTestBase::TearDown();
}
private:
DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest);
};
TEST_F(WindowAnimationsTest, LayerTargetVisibility) {
scoped_ptr<aura::Window> window(
aura::test::CreateTestWindowWithId(0, NULL));
window->Show();
EXPECT_TRUE(window->layer()->GetTargetVisibility());
window->Hide();
EXPECT_FALSE(window->layer()->GetTargetVisibility());
window->Show();
EXPECT_TRUE(window->layer()->GetTargetVisibility());
}
TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateShow) {
scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL));
SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_SHOW);
window->Show();
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_TRUE(window->layer()->GetTargetVisibility());
EXPECT_EQ(1, window->layer()->opacity());
window->Hide();
AnimateOnChildWindowVisibilityChanged(window.get(), false);
EXPECT_FALSE(window->layer()->GetTargetVisibility());
EXPECT_EQ(0, window->layer()->opacity());
EXPECT_EQ(gfx::Transform(), window->layer()->transform());
window->Show();
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_TRUE(window->layer()->GetTargetVisibility());
EXPECT_EQ(1, window->layer()->opacity());
}
TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateHide) {
scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL));
SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_HIDE);
window->Show();
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_TRUE(window->layer()->GetTargetVisibility());
EXPECT_EQ(1, window->layer()->opacity());
EXPECT_EQ(gfx::Transform(), window->layer()->transform());
window->Hide();
AnimateOnChildWindowVisibilityChanged(window.get(), false);
EXPECT_FALSE(window->layer()->GetTargetVisibility());
EXPECT_EQ(0, window->layer()->opacity());
window->Show();
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_TRUE(window->layer()->GetTargetVisibility());
EXPECT_EQ(1, window->layer()->opacity());
EXPECT_EQ(gfx::Transform(), window->layer()->transform());
}
TEST_F(WindowAnimationsTest, HideAnimationDetachLayers) {
scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL));
scoped_ptr<aura::Window> other(
aura::test::CreateTestWindowWithId(1, parent.get()));
scoped_ptr<aura::Window> animating_window(
aura::test::CreateTestWindowWithId(2, parent.get()));
SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE);
EXPECT_EQ(0, GetWindowZPosition(other.get()));
EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(0, GetLayerZPosition(other->layer()));
EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
{
ui::ScopedAnimationDurationScaleMode scale_mode(
ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
ui::Layer* animating_layer = animating_window->layer();
animating_window->Hide();
EXPECT_TRUE(AnimateOnChildWindowVisibilityChanged(
animating_window.get(), false));
EXPECT_TRUE(animating_layer->GetAnimator()->is_animating());
EXPECT_FALSE(animating_layer->delegate());
EXPECT_NE(animating_window->layer(), animating_layer);
EXPECT_TRUE(
std::find(parent->layer()->children().begin(),
parent->layer()->children().end(),
animating_layer) !=
parent->layer()->children().end());
EXPECT_TRUE(
std::find(parent->layer()->children().begin(),
parent->layer()->children().end(),
animating_window->layer()) !=
parent->layer()->children().end());
EXPECT_FALSE(animating_window->layer()->visible());
EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
EXPECT_EQ(2, GetLayerZPosition(animating_layer));
parent->StackChildAtTop(other.get());
EXPECT_EQ(0, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(1, GetWindowZPosition(other.get()));
EXPECT_EQ(0, GetLayerZPosition(animating_window->layer()));
EXPECT_EQ(1, GetLayerZPosition(other->layer()));
EXPECT_EQ(2, GetLayerZPosition(animating_layer));
animating_layer->GetAnimator()->StopAnimating();
EXPECT_TRUE(
std::find(parent->layer()->children().begin(),
parent->layer()->children().end(),
animating_layer) ==
parent->layer()->children().end());
}
}
TEST_F(WindowAnimationsTest, HideAnimationDetachLayersWithTransientChildren) {
TransientWindowStackingClient transient_stacking_client;
scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL));
scoped_ptr<aura::Window> other(
aura::test::CreateTestWindowWithId(1, parent.get()));
scoped_ptr<aura::Window> animating_window(
aura::test::CreateTestWindowWithId(2, parent.get()));
SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE);
scoped_ptr<aura::Window> transient1(
aura::test::CreateTestWindowWithId(3, parent.get()));
scoped_ptr<aura::Window> transient2(
aura::test::CreateTestWindowWithId(4, parent.get()));
TransientWindowManager::Get(animating_window.get());
AddTransientChild(animating_window.get(), transient1.get());
AddTransientChild(animating_window.get(), transient2.get());
EXPECT_EQ(0, GetWindowZPosition(other.get()));
EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(2, GetWindowZPosition(transient1.get()));
EXPECT_EQ(3, GetWindowZPosition(transient2.get()));
{
ui::ScopedAnimationDurationScaleMode scale_mode(
ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
ui::Layer* animating_layer = animating_window->layer();
animating_window->Hide();
EXPECT_TRUE(AnimateOnChildWindowVisibilityChanged(
animating_window.get(), false));
EXPECT_TRUE(animating_layer->GetAnimator()->is_animating());
EXPECT_FALSE(animating_layer->delegate());
EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(2, GetWindowZPosition(transient1.get()));
EXPECT_EQ(3, GetWindowZPosition(transient2.get()));
EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
EXPECT_EQ(2, GetLayerZPosition(transient1->layer()));
EXPECT_EQ(3, GetLayerZPosition(transient2->layer()));
EXPECT_EQ(4, GetLayerZPosition(animating_layer));
parent->StackChildAtTop(other.get());
EXPECT_EQ(0, GetWindowZPosition(animating_window.get()));
EXPECT_EQ(1, GetWindowZPosition(transient1.get()));
EXPECT_EQ(2, GetWindowZPosition(transient2.get()));
EXPECT_EQ(3, GetWindowZPosition(other.get()));
EXPECT_EQ(0, GetLayerZPosition(animating_window->layer()));
EXPECT_EQ(1, GetLayerZPosition(transient1->layer()));
EXPECT_EQ(2, GetLayerZPosition(transient2->layer()));
EXPECT_EQ(3, GetLayerZPosition(other->layer()));
EXPECT_EQ(4, GetLayerZPosition(animating_layer));
}
}
class NotifyHideCompletedAnimationHost : public aura::client::AnimationHost {
public:
NotifyHideCompletedAnimationHost() : hide_completed_(false) {}
virtual ~NotifyHideCompletedAnimationHost() {}
virtual void OnWindowHidingAnimationCompleted() OVERRIDE {
hide_completed_ = true;
}
virtual void SetHostTransitionOffsets(
const gfx::Vector2d& top_left,
const gfx::Vector2d& bottom_right) OVERRIDE {}
bool hide_completed() const { return hide_completed_; }
private:
bool hide_completed_;
DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedAnimationHost);
};
TEST_F(WindowAnimationsTest, NotifyHideCompleted) {
NotifyHideCompletedAnimationHost animation_host;
scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL));
aura::client::SetAnimationHost(window.get(), &animation_host);
wm::SetWindowVisibilityAnimationType(
window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
AnimateOnChildWindowVisibilityChanged(window.get(), true);
EXPECT_TRUE(window->layer()->visible());
EXPECT_FALSE(animation_host.hide_completed());
AnimateOnChildWindowVisibilityChanged(window.get(), false);
EXPECT_TRUE(animation_host.hide_completed());
}
}