#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/aura_test_utils.h"
-#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/test/window_test_api.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/test_layers.h"
#include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_configuration.h"
#include "ui/events/keycodes/keyboard_codes.h"
+#include "ui/events/test/event_generator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h"
}
// Test Window::ConvertPointToWindow() with transform to root_window.
-#if defined(USE_OZONE)
-// TODO(rjkroege): Add cursor support in ozone: http://crbug.com/252315.
-TEST_F(WindowTest, DISABLED_MoveCursorToWithTransformRootWindow) {
-#else
TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {
-#endif
gfx::Transform transform;
transform.Translate(100.0, 100.0);
transform.Rotate(90.0);
// Test Window::ConvertPointToWindow() with complex transforms to both root and
// non-root windows.
// Test Window::ConvertPointToWindow() with transform to root_window.
-#if defined(USE_OZONE)
-// TODO(rjkroege): Add cursor support in ozone: http://crbug.com/252315.
-TEST_F(WindowTest, DISABLED_MoveCursorToWithComplexTransform) {
-#else
TEST_F(WindowTest, MoveCursorToWithComplexTransform) {
-#endif
scoped_ptr<Window> w1(
CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500),
root_window()));
EXPECT_TRUE(window->HasCapture());
EXPECT_EQ(0, delegate.capture_lost_count());
EXPECT_EQ(0, delegate.capture_changed_event_count());
- EventGenerator generator(root_window(), gfx::Point(50, 50));
+ ui::test::EventGenerator generator(root_window(), gfx::Point(50, 50));
generator.PressLeftButton();
EXPECT_EQ(1, delegate.mouse_event_count());
generator.ReleaseLeftButton();
&delegate2, 0, gfx::Rect(50, 50, 50, 50), root_window()));
// Press on w1.
- ui::TouchEvent press(
+ ui::TouchEvent press1(
ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
- DispatchEventUsingWindowDispatcher(&press);
+ DispatchEventUsingWindowDispatcher(&press1);
// We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
EXPECT_EQ(2, delegate1.gesture_event_count());
delegate1.ResetCounts();
CaptureWindowDelegateImpl delegate;
scoped_ptr<Window> window(CreateTestWindowWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 50, 50), root_window()));
+ base::TimeDelta time = getTime();
+ const int kTimeDelta = 100;
ui::TouchEvent press(
- ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, getTime());
+ ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time);
DispatchEventUsingWindowDispatcher(&press);
// We will get both GESTURE_BEGIN and GESTURE_TAP_DOWN.
// On move We will get TOUCH_MOVED, GESTURE_TAP_CANCEL,
// GESTURE_SCROLL_START and GESTURE_SCROLL_UPDATE.
- ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 20), 0, getTime());
+ time += base::TimeDelta::FromMilliseconds(kTimeDelta);
+ ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 20), 0, time);
DispatchEventUsingWindowDispatcher(&move);
EXPECT_EQ(1, delegate.touch_event_count());
EXPECT_EQ(3, delegate.gesture_event_count());
delegate.ResetCounts();
// On move we still get TOUCH_MOVED and GESTURE_SCROLL_UPDATE.
- ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(10, 30), 0, getTime());
+ time += base::TimeDelta::FromMilliseconds(kTimeDelta);
+ ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(10, 30), 0, time);
DispatchEventUsingWindowDispatcher(&move2);
EXPECT_EQ(1, delegate.touch_event_count());
EXPECT_EQ(1, delegate.gesture_event_count());
delegate.ResetCounts();
// And on release we get TOUCH_RELEASED, GESTURE_SCROLL_END, GESTURE_END
+ time += base::TimeDelta::FromMilliseconds(kTimeDelta);
ui::TouchEvent release(
- ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0, getTime());
+ ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 0, time);
DispatchEventUsingWindowDispatcher(&release);
EXPECT_EQ(1, delegate.touch_event_count());
EXPECT_EQ(2, delegate.gesture_event_count());
EXPECT_TRUE(window->HasCapture());
EXPECT_EQ(0, delegate.capture_lost_count());
EXPECT_EQ(0, delegate.capture_changed_event_count());
- EventGenerator generator(root_window(), gfx::Point(50, 50));
+ ui::test::EventGenerator generator(root_window(), gfx::Point(50, 50));
generator.PressLeftButton();
EXPECT_EQ(0, delegate.capture_lost_count());
EXPECT_EQ(0, delegate.capture_changed_event_count());
CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(70, 70, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
CreateTestWindowWithDelegate(&delegate, 1, gfx::Rect(10, 10, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(window.get());
EXPECT_TRUE(delegate.entered());
EXPECT_FALSE(delegate.exited());
CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50),
root_window()));
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w1.get());
EXPECT_TRUE(d1.entered());
EXPECT_FALSE(d1.exited());
MouseEnterExitWindowDelegate d2;
Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
w1.get());
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w2);
// Enters / exits can be send asynchronously.
RunAllPendingInMessageLoop();
MouseEnterExitWindowDelegate d2;
Window* w2 = CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(10, 10, 50, 50),
w1.get());
- test::EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseToCenterOf(w2);
// Enters / exits can be send asynchronously.
TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) {
// We cannot short-circuit animations in this test.
- ui::ScopedAnimationDurationScaleMode normal_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
scoped_ptr<Window> w1(
CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window()));
EXPECT_FALSE(!w1->layer());
w1->layer()->GetAnimator()->set_disable_timer_for_test(true);
- gfx::AnimationContainerElement* element = w1->layer()->GetAnimator();
+ ui::LayerAnimator* animator = w1->layer()->GetAnimator();
EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString());
base::TimeTicks start_time =
w1->layer()->GetAnimator()->last_step_time();
- element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
+ animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
}
w.SetBounds(gfx::Rect(0, 0, 100, 100));
ui::Layer* layer = w.layer();
- layer->set_scale_content(false);
layer->SetVisible(false);
layer->SetMasksToBounds(true);
scoped_ptr<ui::Layer> old_layer(w.RecreateLayer());
layer = w.layer();
EXPECT_EQ(ui::LAYER_SOLID_COLOR, layer->type());
- EXPECT_FALSE(layer->scale_content());
EXPECT_FALSE(layer->visible());
EXPECT_EQ(1u, layer->children().size());
EXPECT_TRUE(layer->GetMasksToBounds());
TEST_F(WindowTest, MouseEventsOnWindowChange) {
gfx::Size size = host()->GetBounds().size();
- EventGenerator generator(root_window());
+ ui::test::EventGenerator generator(root_window());
generator.MoveMouseTo(50, 50);
EventCountDelegate d1;
parent1.SetBounds(gfx::Rect(10, 10, 300, 300));
parent2.SetBounds(gfx::Rect(20, 20, 300, 300));
+ BoundsChangedWindowObserver observer;
Window child(NULL);
child.Init(aura::WINDOW_LAYER_NOT_DRAWN);
child.SetBounds(gfx::Rect(5, 5, 100, 100));
parent1.AddChild(&child);
// We need animations to start in order to observe the bounds changes.
- ui::ScopedAnimationDurationScaleMode animation_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
ui::ScopedLayerAnimationSettings settings1(child.layer()->GetAnimator());
settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
gfx::Rect new_bounds(gfx::Rect(35, 35, 50, 50));
child.SetBounds(new_bounds);
- BoundsChangedWindowObserver observer;
child.AddObserver(&observer);
// Reparenting the |child| will cause it to get moved. During this move
BoundsChangeDelegate delegate;
// We cannot short-circuit animations in this test.
- ui::ScopedAnimationDurationScaleMode normal_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
scoped_ptr<Window> window(
CreateTestWindowWithDelegate(&delegate, 1,
// Animate to the end, which should notify of the change.
base::TimeTicks start_time =
window->layer()->GetAnimator()->last_step_time();
- gfx::AnimationContainerElement* element = window->layer()->GetAnimator();
- element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
+ ui::LayerAnimator* animator = window->layer()->GetAnimator();
+ animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
EXPECT_TRUE(delegate.bounds_changed());
EXPECT_NE("0,0 100x100", window->bounds().ToString());
}
BoundsChangeDelegate delegate;
// We cannot short-circuit animations in this test.
- ui::ScopedAnimationDurationScaleMode normal_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
scoped_ptr<Window> window(
CreateTestWindowWithDelegate(&delegate, 1,
// Animate to the end: will *not* notify of the change since we are hidden.
base::TimeTicks start_time =
window->layer()->GetAnimator()->last_step_time();
- gfx::AnimationContainerElement* element = window->layer()->GetAnimator();
- element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
+ ui::LayerAnimator* animator = window->layer()->GetAnimator();
+ animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
// No bounds changed notification at the end of animation since layer
// delegate is NULL.
}
}
+namespace {
+
+class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
+ public:
+ TestLayerAnimationObserver()
+ : animation_completed_(false),
+ animation_aborted_(false) {}
+ virtual ~TestLayerAnimationObserver() {}
+
+ bool animation_completed() const { return animation_completed_; }
+ bool animation_aborted() const { return animation_aborted_; }
+
+ void Reset() {
+ animation_completed_ = false;
+ animation_aborted_ = false;
+ }
+
+ private:
+ // ui::LayerAnimationObserver:
+ virtual void OnLayerAnimationEnded(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ animation_completed_ = true;
+ }
+
+ virtual void OnLayerAnimationAborted(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ animation_aborted_ = true;
+ }
+
+ virtual void OnLayerAnimationScheduled(
+ ui::LayerAnimationSequence* sequence) OVERRIDE {
+ }
+
+ bool animation_completed_;
+ bool animation_aborted_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver);
+};
+
+}
+
+TEST_F(WindowTest, WindowDestroyCompletesAnimations) {
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
+ scoped_refptr<ui::LayerAnimator> animator =
+ ui::LayerAnimator::CreateImplicitAnimator();
+ TestLayerAnimationObserver observer;
+ animator->AddObserver(&observer);
+ // Make sure destroying a Window completes the animation.
+ {
+ scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
+ window->layer()->SetAnimator(animator);
+
+ gfx::Transform transform;
+ transform.Scale(0.5f, 0.5f);
+ window->SetTransform(transform);
+
+ EXPECT_TRUE(animator->is_animating());
+ EXPECT_FALSE(observer.animation_completed());
+ }
+ EXPECT_TRUE(animator);
+ EXPECT_FALSE(animator->is_animating());
+ EXPECT_TRUE(observer.animation_completed());
+ EXPECT_FALSE(observer.animation_aborted());
+ animator->RemoveObserver(&observer);
+ observer.Reset();
+
+ animator = ui::LayerAnimator::CreateImplicitAnimator();
+ animator->AddObserver(&observer);
+ ui::Layer layer;
+ layer.SetAnimator(animator);
+ {
+ scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
+ window->layer()->Add(&layer);
+
+ gfx::Transform transform;
+ transform.Scale(0.5f, 0.5f);
+ layer.SetTransform(transform);
+
+ EXPECT_TRUE(animator->is_animating());
+ EXPECT_FALSE(observer.animation_completed());
+ }
+
+ EXPECT_TRUE(animator);
+ EXPECT_FALSE(animator->is_animating());
+ EXPECT_TRUE(observer.animation_completed());
+ EXPECT_FALSE(observer.animation_aborted());
+ animator->RemoveObserver(&observer);
+}
+
} // namespace test
} // namespace aura