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_(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 child.SetBounds(gfx::Rect(35, 35, 100, 100)); |
| 2248 |
| 2249 BoundsChangedWindowObserver observer; |
| 2250 child.AddObserver(&observer); |
| 2251 |
| 2252 // Reparenting the |child| will cause it to get moved. During this move |
| 2253 // the window should still have root window set. |
| 2254 parent2.AddChild(&child); |
| 2255 EXPECT_TRUE(observer.root_set()); |
| 2256 |
| 2257 // TODO(varkha): Check that the target bounds didn't change after reparenting. |
| 2258 } |
| 2259 |
2209 TEST_F(WindowTest, OwnedByParentFalse) { | 2260 TEST_F(WindowTest, OwnedByParentFalse) { |
2210 // By default, a window is owned by its parent. If this is set to false, the | 2261 // 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. | 2262 // window will not be destroyed when its parent is. |
2212 | 2263 |
2213 scoped_ptr<Window> w1(new Window(NULL)); | 2264 scoped_ptr<Window> w1(new Window(NULL)); |
2214 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2265 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2215 scoped_ptr<Window> w2(new Window(NULL)); | 2266 scoped_ptr<Window> w2(new Window(NULL)); |
2216 w2->set_owned_by_parent(false); | 2267 w2->set_owned_by_parent(false); |
2217 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2268 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2218 w1->AddChild(w2.get()); | 2269 w1->AddChild(w2.get()); |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3291 BuildRootLayerTreeDescription(*root.layer())) | 3342 BuildRootLayerTreeDescription(*root.layer())) |
3292 << "layer tree doesn't match at " << i; | 3343 << "layer tree doesn't match at " << i; |
3293 EXPECT_EQ(data[i].expected_description, | 3344 EXPECT_EQ(data[i].expected_description, |
3294 BuildRootWindowTreeDescription(root)) | 3345 BuildRootWindowTreeDescription(root)) |
3295 << "window tree doesn't match at " << i; | 3346 << "window tree doesn't match at " << i; |
3296 } | 3347 } |
3297 } | 3348 } |
3298 | 3349 |
3299 } // namespace test | 3350 } // namespace test |
3300 } // namespace aura | 3351 } // namespace aura |
OLD | NEW |