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

Side by Side 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 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 unified diff | Download patch | Annotate | Revision Log
« ui/aura/window.cc ('K') | « ui/aura/window.cc ('k') | no next file » | 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 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 EXPECT_EQ(2, observer.added_count()); 2199 EXPECT_EQ(2, observer.added_count());
2200 EXPECT_EQ(0, observer.removed_count()); 2200 EXPECT_EQ(0, observer.removed_count());
2201 2201
2202 w1.reset(); // Deletes w11 and w111. 2202 w1.reset(); // Deletes w11 and w111.
2203 w11 = NULL; 2203 w11 = NULL;
2204 w111 = NULL; 2204 w111 = NULL;
2205 EXPECT_EQ(2, observer.added_count()); 2205 EXPECT_EQ(2, observer.added_count());
2206 EXPECT_EQ(2, observer.removed_count()); 2206 EXPECT_EQ(2, observer.removed_count());
2207 } 2207 }
2208 2208
2209 class BoundsChangedWindowObserver : public WindowObserver {
2210 public:
2211 BoundsChangedWindowObserver() : root_set_(false) {}
2212
2213 virtual void OnWindowBoundsChanged(Window* window,
2214 const gfx::Rect& old_bounds,
2215 const gfx::Rect& new_bounds) OVERRIDE {
2216 root_set_ = window->GetRootWindow() != NULL;
2217 }
2218
2219 bool root_set() const { return root_set_; }
2220
2221 private:
2222 bool root_set_;
2223
2224 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver);
2225 };
2226
2227 TEST_F(WindowTest, RootWindowSetWhenReparenting) {
2228 Window parent1(NULL);
2229 parent1.Init(aura::WINDOW_LAYER_NOT_DRAWN);
2230 Window parent2(NULL);
2231 parent2.Init(aura::WINDOW_LAYER_NOT_DRAWN);
2232 ParentWindow(&parent1);
2233 ParentWindow(&parent2);
2234 parent1.SetBounds(gfx::Rect(10, 10, 300, 300));
2235 parent2.SetBounds(gfx::Rect(20, 20, 300, 300));
2236
2237 Window child(NULL);
2238 child.Init(aura::WINDOW_LAYER_NOT_DRAWN);
2239 child.SetBounds(gfx::Rect(5, 5, 100, 100));
2240 parent1.AddChild(&child);
2241
2242 // We need animations to start in order to observe the bounds changes.
2243 ui::ScopedAnimationDurationScaleMode animation_duration_mode(
2244 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
2245 ui::ScopedLayerAnimationSettings settings1(child.layer()->GetAnimator());
2246 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
2247 gfx::Rect new_bounds(gfx::Rect(35, 35, 100, 100));
2248 child.SetBounds(new_bounds);
2249
2250 BoundsChangedWindowObserver observer;
2251 child.AddObserver(&observer);
2252
2253 // Reparenting the |child| will cause it to get moved. During this move
2254 // the window should still have root window set.
2255 parent2.AddChild(&child);
2256 EXPECT_TRUE(observer.root_set());
2257
2258 // Target bounds should not change when the |child| got reparented.
2259 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString());
2260 }
2261
2209 TEST_F(WindowTest, OwnedByParentFalse) { 2262 TEST_F(WindowTest, OwnedByParentFalse) {
2210 // By default, a window is owned by its parent. If this is set to false, the 2263 // By default, a window is owned by its parent. If this is set to false, the
2211 // window will not be destroyed when its parent is. 2264 // window will not be destroyed when its parent is.
2212 2265
2213 scoped_ptr<Window> w1(new Window(NULL)); 2266 scoped_ptr<Window> w1(new Window(NULL));
2214 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); 2267 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN);
2215 scoped_ptr<Window> w2(new Window(NULL)); 2268 scoped_ptr<Window> w2(new Window(NULL));
2216 w2->set_owned_by_parent(false); 2269 w2->set_owned_by_parent(false);
2217 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); 2270 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN);
2218 w1->AddChild(w2.get()); 2271 w1->AddChild(w2.get());
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 BuildRootLayerTreeDescription(*root.layer())) 3344 BuildRootLayerTreeDescription(*root.layer()))
3292 << "layer tree doesn't match at " << i; 3345 << "layer tree doesn't match at " << i;
3293 EXPECT_EQ(data[i].expected_description, 3346 EXPECT_EQ(data[i].expected_description,
3294 BuildRootWindowTreeDescription(root)) 3347 BuildRootWindowTreeDescription(root))
3295 << "window tree doesn't match at " << i; 3348 << "window tree doesn't match at " << i;
3296 } 3349 }
3297 } 3350 }
3298 3351
3299 } // namespace test 3352 } // namespace test
3300 } // namespace aura 3353 } // namespace aura
OLDNEW
« 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