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

Unified Diff: ui/aura/window_unittest.cc

Issue 241983003: Stops animations when removing a window from its parent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Uses GetTargetBounds() in place of bounds() when reparenting layers (retargeting animations) Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« ui/aura/window.cc ('K') | « ui/aura/window.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_unittest.cc
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 3087723e4ccade9f18214fcde4302f1b54ac774f..780661d694d4937cc2c7288a2ca0766b67b40711 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -2206,6 +2206,68 @@ TEST_F(WindowTest, RootWindowAttachment) {
EXPECT_EQ(2, observer.removed_count());
}
+class BoundsChangedWindowObserver : public WindowObserver {
+ public:
+ BoundsChangedWindowObserver() : root_set_(true) {}
+
+ virtual void OnWindowBoundsChanged(Window* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) OVERRIDE {
+ if (!window->GetRootWindow())
+ root_set_ = false;
+ }
+
+ bool root_set() const { return root_set_; }
+
+ private:
+ bool root_set_;
+
+ DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver);
+};
+
+TEST_F(WindowTest, RootWindowSetWhenReparenting) {
+ Window parent1(NULL);
+ parent1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ Window parent2(NULL);
+ parent2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
+ ParentWindow(&parent1);
+ ParentWindow(&parent2);
+ parent1.SetBounds(gfx::Rect(10, 10, 300, 300));
+ parent2.SetBounds(gfx::Rect(20, 20, 300, 300));
+
+ 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::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
+ // the window should still have root window set.
+ parent2.AddChild(&child);
+
+ // Target bounds should not have changed when the |child| got reparented.
+ EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString());
+
+ // Animate to the end, which should notify of the change.
+ base::TimeTicks start_time =
+ child.layer()->GetAnimator()->last_step_time();
+ gfx::AnimationContainerElement* element = child.layer()->GetAnimator();
+ element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
+
+ EXPECT_TRUE(observer.root_set());
+ EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString());
+}
+
TEST_F(WindowTest, OwnedByParentFalse) {
// By default, a window is owned by its parent. If this is set to false, the
// window will not be destroyed when its parent is.
« ui/aura/window.cc ('K') | « ui/aura/window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698