OLD | NEW |
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 Loading... |
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_(true) {} |
| 2212 |
| 2213 virtual void OnWindowBoundsChanged(Window* window, |
| 2214 const gfx::Rect& old_bounds, |
| 2215 const gfx::Rect& new_bounds) OVERRIDE { |
| 2216 if (!window->GetRootWindow()) |
| 2217 root_set_ = false; |
| 2218 } |
| 2219 |
| 2220 bool root_set() const { return root_set_; } |
| 2221 |
| 2222 private: |
| 2223 bool root_set_; |
| 2224 |
| 2225 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver); |
| 2226 }; |
| 2227 |
| 2228 TEST_F(WindowTest, RootWindowSetWhenReparenting) { |
| 2229 Window parent1(NULL); |
| 2230 parent1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 2231 Window parent2(NULL); |
| 2232 parent2.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 2233 ParentWindow(&parent1); |
| 2234 ParentWindow(&parent2); |
| 2235 parent1.SetBounds(gfx::Rect(10, 10, 300, 300)); |
| 2236 parent2.SetBounds(gfx::Rect(20, 20, 300, 300)); |
| 2237 |
| 2238 Window child(NULL); |
| 2239 child.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 2240 child.SetBounds(gfx::Rect(5, 5, 100, 100)); |
| 2241 parent1.AddChild(&child); |
| 2242 |
| 2243 // We need animations to start in order to observe the bounds changes. |
| 2244 ui::ScopedAnimationDurationScaleMode animation_duration_mode( |
| 2245 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
| 2246 ui::ScopedLayerAnimationSettings settings1(child.layer()->GetAnimator()); |
| 2247 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100)); |
| 2248 gfx::Rect new_bounds(gfx::Rect(35, 35, 50, 50)); |
| 2249 child.SetBounds(new_bounds); |
| 2250 |
| 2251 BoundsChangedWindowObserver observer; |
| 2252 child.AddObserver(&observer); |
| 2253 |
| 2254 // Reparenting the |child| will cause it to get moved. During this move |
| 2255 // the window should still have root window set. |
| 2256 parent2.AddChild(&child); |
| 2257 |
| 2258 // Target bounds should not have changed when the |child| got reparented. |
| 2259 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); |
| 2260 |
| 2261 // Animate to the end, which should notify of the change. |
| 2262 base::TimeTicks start_time = |
| 2263 child.layer()->GetAnimator()->last_step_time(); |
| 2264 gfx::AnimationContainerElement* element = child.layer()->GetAnimator(); |
| 2265 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
| 2266 |
| 2267 EXPECT_TRUE(observer.root_set()); |
| 2268 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); |
| 2269 } |
| 2270 |
2209 TEST_F(WindowTest, OwnedByParentFalse) { | 2271 TEST_F(WindowTest, OwnedByParentFalse) { |
2210 // By default, a window is owned by its parent. If this is set to false, the | 2272 // 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. | 2273 // window will not be destroyed when its parent is. |
2212 | 2274 |
2213 scoped_ptr<Window> w1(new Window(NULL)); | 2275 scoped_ptr<Window> w1(new Window(NULL)); |
2214 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2276 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2215 scoped_ptr<Window> w2(new Window(NULL)); | 2277 scoped_ptr<Window> w2(new Window(NULL)); |
2216 w2->set_owned_by_parent(false); | 2278 w2->set_owned_by_parent(false); |
2217 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2279 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2218 w1->AddChild(w2.get()); | 2280 w1->AddChild(w2.get()); |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3291 BuildRootLayerTreeDescription(*root.layer())) | 3353 BuildRootLayerTreeDescription(*root.layer())) |
3292 << "layer tree doesn't match at " << i; | 3354 << "layer tree doesn't match at " << i; |
3293 EXPECT_EQ(data[i].expected_description, | 3355 EXPECT_EQ(data[i].expected_description, |
3294 BuildRootWindowTreeDescription(root)) | 3356 BuildRootWindowTreeDescription(root)) |
3295 << "window tree doesn't match at " << i; | 3357 << "window tree doesn't match at " << i; |
3296 } | 3358 } |
3297 } | 3359 } |
3298 | 3360 |
3299 } // namespace test | 3361 } // namespace test |
3300 } // namespace aura | 3362 } // namespace aura |
OLD | NEW |