Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: ui/aura/window_unittest.cc

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.cc ('k') | ui/compositor/compositor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/window.h" 5 #include "ui/aura/window.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "ui/aura/test/test_window_delegate.h" 24 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/aura/test/test_windows.h" 25 #include "ui/aura/test/test_windows.h"
26 #include "ui/aura/test/window_test_api.h" 26 #include "ui/aura/test/window_test_api.h"
27 #include "ui/aura/window_delegate.h" 27 #include "ui/aura/window_delegate.h"
28 #include "ui/aura/window_event_dispatcher.h" 28 #include "ui/aura/window_event_dispatcher.h"
29 #include "ui/aura/window_observer.h" 29 #include "ui/aura/window_observer.h"
30 #include "ui/aura/window_property.h" 30 #include "ui/aura/window_property.h"
31 #include "ui/aura/window_tree_host.h" 31 #include "ui/aura/window_tree_host.h"
32 #include "ui/base/hit_test.h" 32 #include "ui/base/hit_test.h"
33 #include "ui/compositor/layer.h" 33 #include "ui/compositor/layer.h"
34 #include "ui/compositor/layer_animation_observer.h"
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
35 #include "ui/compositor/scoped_layer_animation_settings.h" 36 #include "ui/compositor/scoped_layer_animation_settings.h"
36 #include "ui/compositor/test/test_layers.h" 37 #include "ui/compositor/test/test_layers.h"
37 #include "ui/events/event.h" 38 #include "ui/events/event.h"
38 #include "ui/events/event_utils.h" 39 #include "ui/events/event_utils.h"
39 #include "ui/events/gestures/gesture_configuration.h" 40 #include "ui/events/gestures/gesture_configuration.h"
40 #include "ui/events/keycodes/keyboard_codes.h" 41 #include "ui/events/keycodes/keyboard_codes.h"
41 #include "ui/gfx/canvas.h" 42 #include "ui/gfx/canvas.h"
42 #include "ui/gfx/screen.h" 43 #include "ui/gfx/screen.h"
43 #include "ui/gfx/skia_util.h" 44 #include "ui/gfx/skia_util.h"
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) { 1619 TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) {
1619 // We cannot short-circuit animations in this test. 1620 // We cannot short-circuit animations in this test.
1620 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 1621 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
1621 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 1622 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
1622 1623
1623 scoped_ptr<Window> w1( 1624 scoped_ptr<Window> w1(
1624 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window())); 1625 CreateTestWindowWithBounds(gfx::Rect(0, 0, 100, 100), root_window()));
1625 1626
1626 EXPECT_FALSE(!w1->layer()); 1627 EXPECT_FALSE(!w1->layer());
1627 w1->layer()->GetAnimator()->set_disable_timer_for_test(true); 1628 w1->layer()->GetAnimator()->set_disable_timer_for_test(true);
1628 gfx::AnimationContainerElement* element = w1->layer()->GetAnimator(); 1629 ui::LayerAnimator* animator = w1->layer()->GetAnimator();
1629 1630
1630 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); 1631 EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
1631 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); 1632 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString());
1632 1633
1633 // Animate to a different position. 1634 // Animate to a different position.
1634 { 1635 {
1635 ui::ScopedLayerAnimationSettings settings(w1->layer()->GetAnimator()); 1636 ui::ScopedLayerAnimationSettings settings(w1->layer()->GetAnimator());
1636 w1->SetBounds(gfx::Rect(100, 100, 100, 100)); 1637 w1->SetBounds(gfx::Rect(100, 100, 100, 100));
1637 } 1638 }
1638 1639
1639 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); 1640 EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
1640 EXPECT_EQ("100,100 100x100", w1->layer()->GetTargetBounds().ToString()); 1641 EXPECT_EQ("100,100 100x100", w1->layer()->GetTargetBounds().ToString());
1641 1642
1642 // Animate back to the first position. The animation hasn't started yet, so 1643 // Animate back to the first position. The animation hasn't started yet, so
1643 // the current bounds are still (0, 0, 100, 100), but the target bounds are 1644 // the current bounds are still (0, 0, 100, 100), but the target bounds are
1644 // (100, 100, 100, 100). If we step the animator ahead, we should find that 1645 // (100, 100, 100, 100). If we step the animator ahead, we should find that
1645 // we're at (0, 0, 100, 100). That is, the second animation should be applied. 1646 // we're at (0, 0, 100, 100). That is, the second animation should be applied.
1646 { 1647 {
1647 ui::ScopedLayerAnimationSettings settings(w1->layer()->GetAnimator()); 1648 ui::ScopedLayerAnimationSettings settings(w1->layer()->GetAnimator());
1648 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 1649 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
1649 } 1650 }
1650 1651
1651 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); 1652 EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
1652 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString()); 1653 EXPECT_EQ("0,0 100x100", w1->layer()->GetTargetBounds().ToString());
1653 1654
1654 // Confirm that the target bounds are reached. 1655 // Confirm that the target bounds are reached.
1655 base::TimeTicks start_time = 1656 base::TimeTicks start_time =
1656 w1->layer()->GetAnimator()->last_step_time(); 1657 w1->layer()->GetAnimator()->last_step_time();
1657 1658
1658 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 1659 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
1659 1660
1660 EXPECT_EQ("0,0 100x100", w1->bounds().ToString()); 1661 EXPECT_EQ("0,0 100x100", w1->bounds().ToString());
1661 } 1662 }
1662 1663
1663 1664
1664 typedef std::pair<const void*, intptr_t> PropertyChangeInfo; 1665 typedef std::pair<const void*, intptr_t> PropertyChangeInfo;
1665 1666
1666 class WindowObserverTest : public WindowTest, 1667 class WindowObserverTest : public WindowTest,
1667 public WindowObserver { 1668 public WindowObserver {
1668 public: 1669 public:
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 window->SetBounds(gfx::Rect(100, 100, 100, 100)); 2368 window->SetBounds(gfx::Rect(100, 100, 100, 100));
2368 } 2369 }
2369 2370
2370 // Bounds shouldn't immediately have changed. 2371 // Bounds shouldn't immediately have changed.
2371 EXPECT_EQ("0,0 100x100", window->bounds().ToString()); 2372 EXPECT_EQ("0,0 100x100", window->bounds().ToString());
2372 EXPECT_FALSE(delegate.bounds_changed()); 2373 EXPECT_FALSE(delegate.bounds_changed());
2373 2374
2374 // Animate to the end, which should notify of the change. 2375 // Animate to the end, which should notify of the change.
2375 base::TimeTicks start_time = 2376 base::TimeTicks start_time =
2376 window->layer()->GetAnimator()->last_step_time(); 2377 window->layer()->GetAnimator()->last_step_time();
2377 gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); 2378 ui::LayerAnimator* animator = window->layer()->GetAnimator();
2378 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2379 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2379 EXPECT_TRUE(delegate.bounds_changed()); 2380 EXPECT_TRUE(delegate.bounds_changed());
2380 EXPECT_NE("0,0 100x100", window->bounds().ToString()); 2381 EXPECT_NE("0,0 100x100", window->bounds().ToString());
2381 } 2382 }
2382 2383
2383 // Verifies the delegate is notified when the actual bounds of the layer 2384 // Verifies the delegate is notified when the actual bounds of the layer
2384 // change even when the window is not the layer's delegate 2385 // change even when the window is not the layer's delegate
2385 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { 2386 TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) {
2386 BoundsChangeDelegate delegate; 2387 BoundsChangeDelegate delegate;
2387 2388
2388 // We cannot short-circuit animations in this test. 2389 // We cannot short-circuit animations in this test.
(...skipping 20 matching lines...) Expand all
2409 2410
2410 // Layer delegate is NULL but we should still get bounds changed notification. 2411 // Layer delegate is NULL but we should still get bounds changed notification.
2411 EXPECT_EQ("100,100 110x100", window->GetTargetBounds().ToString()); 2412 EXPECT_EQ("100,100 110x100", window->GetTargetBounds().ToString());
2412 EXPECT_TRUE(delegate.bounds_changed()); 2413 EXPECT_TRUE(delegate.bounds_changed());
2413 2414
2414 delegate.clear_bounds_changed(); 2415 delegate.clear_bounds_changed();
2415 2416
2416 // Animate to the end: will *not* notify of the change since we are hidden. 2417 // Animate to the end: will *not* notify of the change since we are hidden.
2417 base::TimeTicks start_time = 2418 base::TimeTicks start_time =
2418 window->layer()->GetAnimator()->last_step_time(); 2419 window->layer()->GetAnimator()->last_step_time();
2419 gfx::AnimationContainerElement* element = window->layer()->GetAnimator(); 2420 ui::LayerAnimator* animator = window->layer()->GetAnimator();
2420 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2421 animator->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2421 2422
2422 // No bounds changed notification at the end of animation since layer 2423 // No bounds changed notification at the end of animation since layer
2423 // delegate is NULL. 2424 // delegate is NULL.
2424 EXPECT_FALSE(delegate.bounds_changed()); 2425 EXPECT_FALSE(delegate.bounds_changed());
2425 EXPECT_NE("0,0 100x100", window->layer()->bounds().ToString()); 2426 EXPECT_NE("0,0 100x100", window->layer()->bounds().ToString());
2426 } 2427 }
2427 2428
2428 namespace { 2429 namespace {
2429 2430
2430 // Used by AddChildNotifications to track notification counts. 2431 // Used by AddChildNotifications to track notification counts.
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 } 3341 }
3341 EXPECT_EQ(data[i].expected_layer_description, 3342 EXPECT_EQ(data[i].expected_layer_description,
3342 BuildRootLayerTreeDescription(*root.layer())) 3343 BuildRootLayerTreeDescription(*root.layer()))
3343 << "layer tree doesn't match at " << i; 3344 << "layer tree doesn't match at " << i;
3344 EXPECT_EQ(data[i].expected_description, 3345 EXPECT_EQ(data[i].expected_description,
3345 BuildRootWindowTreeDescription(root)) 3346 BuildRootWindowTreeDescription(root))
3346 << "window tree doesn't match at " << i; 3347 << "window tree doesn't match at " << i;
3347 } 3348 }
3348 } 3349 }
3349 3350
3351 namespace {
3352
3353 class TestLayerAnimationObserver : public ui::LayerAnimationObserver {
3354 public:
3355 TestLayerAnimationObserver()
3356 : animation_completed_(false),
3357 animation_aborted_(false) {}
3358 virtual ~TestLayerAnimationObserver() {}
3359
3360 bool animation_completed() const { return animation_completed_; }
3361 bool animation_aborted() const { return animation_aborted_; }
3362
3363 void Reset() {
3364 animation_completed_ = false;
3365 animation_aborted_ = false;
3366 }
3367
3368 private:
3369 // ui::LayerAnimationObserver:
3370 virtual void OnLayerAnimationEnded(
3371 ui::LayerAnimationSequence* sequence) OVERRIDE {
3372 animation_completed_ = true;
3373 }
3374
3375 virtual void OnLayerAnimationAborted(
3376 ui::LayerAnimationSequence* sequence) OVERRIDE {
3377 animation_aborted_ = true;
3378 }
3379
3380 virtual void OnLayerAnimationScheduled(
3381 ui::LayerAnimationSequence* sequence) OVERRIDE {
3382 }
3383
3384 bool animation_completed_;
3385 bool animation_aborted_;
3386
3387 DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver);
3388 };
3389
3390 }
3391
3392 TEST_F(WindowTest, WindowDestroyCompletesAnimations) {
3393 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
3394 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
3395 scoped_refptr<ui::LayerAnimator> animator =
3396 ui::LayerAnimator::CreateImplicitAnimator();
3397 TestLayerAnimationObserver observer;
3398 animator->AddObserver(&observer);
3399 // Make sure destroying a Window completes the animation.
3400 {
3401 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
3402 window->layer()->SetAnimator(animator);
3403
3404 gfx::Transform transform;
3405 transform.Scale(0.5f, 0.5f);
3406 window->SetTransform(transform);
3407
3408 EXPECT_TRUE(animator->is_animating());
3409 EXPECT_FALSE(observer.animation_completed());
3410 }
3411 EXPECT_TRUE(animator);
3412 EXPECT_FALSE(animator->is_animating());
3413 EXPECT_TRUE(observer.animation_completed());
3414 EXPECT_FALSE(observer.animation_aborted());
3415 animator->RemoveObserver(&observer);
3416 observer.Reset();
3417
3418 animator = ui::LayerAnimator::CreateImplicitAnimator();
3419 animator->AddObserver(&observer);
3420 ui::Layer layer;
3421 layer.SetAnimator(animator);
3422 {
3423 scoped_ptr<Window> window(CreateTestWindowWithId(1, root_window()));
3424 window->layer()->Add(&layer);
3425
3426 gfx::Transform transform;
3427 transform.Scale(0.5f, 0.5f);
3428 layer.SetTransform(transform);
3429
3430 EXPECT_TRUE(animator->is_animating());
3431 EXPECT_FALSE(observer.animation_completed());
3432 }
3433
3434 EXPECT_TRUE(animator);
3435 EXPECT_FALSE(animator->is_animating());
3436 EXPECT_TRUE(observer.animation_completed());
3437 EXPECT_FALSE(observer.animation_aborted());
3438 animator->RemoveObserver(&observer);
3439 }
3440
3350 } // namespace test 3441 } // namespace test
3351 } // namespace aura 3442 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | ui/compositor/compositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698