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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 EXPECT_EQ(NULL, w1->GetChildById(57)); | 285 EXPECT_EQ(NULL, w1->GetChildById(57)); |
286 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 286 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
287 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 287 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
288 } | 288 } |
289 | 289 |
290 // Make sure that Window::Contains correctly handles children, grandchildren, | 290 // Make sure that Window::Contains correctly handles children, grandchildren, |
291 // and not containing NULL or parents. | 291 // and not containing NULL or parents. |
292 TEST_F(WindowTest, Contains) { | 292 TEST_F(WindowTest, Contains) { |
293 Window parent(NULL); | 293 Window parent(NULL); |
294 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 294 parent.Init(ui::LAYER_NOT_DRAWN); |
295 Window child1(NULL); | 295 Window child1(NULL); |
296 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 296 child1.Init(ui::LAYER_NOT_DRAWN); |
297 Window child2(NULL); | 297 Window child2(NULL); |
298 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 298 child2.Init(ui::LAYER_NOT_DRAWN); |
299 | 299 |
300 parent.AddChild(&child1); | 300 parent.AddChild(&child1); |
301 child1.AddChild(&child2); | 301 child1.AddChild(&child2); |
302 | 302 |
303 EXPECT_TRUE(parent.Contains(&parent)); | 303 EXPECT_TRUE(parent.Contains(&parent)); |
304 EXPECT_TRUE(parent.Contains(&child1)); | 304 EXPECT_TRUE(parent.Contains(&child1)); |
305 EXPECT_TRUE(parent.Contains(&child2)); | 305 EXPECT_TRUE(parent.Contains(&child2)); |
306 | 306 |
307 EXPECT_FALSE(parent.Contains(NULL)); | 307 EXPECT_FALSE(parent.Contains(NULL)); |
308 EXPECT_FALSE(child1.Contains(&parent)); | 308 EXPECT_FALSE(child1.Contains(&parent)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 bool called_; | 614 bool called_; |
615 | 615 |
616 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); | 616 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); |
617 }; | 617 }; |
618 | 618 |
619 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { | 619 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { |
620 AddedToRootWindowObserver parent_observer; | 620 AddedToRootWindowObserver parent_observer; |
621 AddedToRootWindowObserver child_observer; | 621 AddedToRootWindowObserver child_observer; |
622 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); | 622 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); |
623 scoped_ptr<Window> child_window(new Window(NULL)); | 623 scoped_ptr<Window> child_window(new Window(NULL)); |
624 child_window->Init(aura::WINDOW_LAYER_TEXTURED); | 624 child_window->Init(ui::LAYER_TEXTURED); |
625 child_window->Show(); | 625 child_window->Show(); |
626 | 626 |
627 parent_window->AddObserver(&parent_observer); | 627 parent_window->AddObserver(&parent_observer); |
628 child_window->AddObserver(&child_observer); | 628 child_window->AddObserver(&child_observer); |
629 | 629 |
630 parent_window->AddChild(child_window.get()); | 630 parent_window->AddChild(child_window.get()); |
631 | 631 |
632 EXPECT_FALSE(parent_observer.called()); | 632 EXPECT_FALSE(parent_observer.called()); |
633 EXPECT_TRUE(child_observer.called()); | 633 EXPECT_TRUE(child_observer.called()); |
634 | 634 |
(...skipping 28 matching lines...) Expand all Loading... |
663 root_window())); | 663 root_window())); |
664 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, | 664 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, |
665 gfx::Rect(), parent.get())); | 665 gfx::Rect(), parent.get())); |
666 child_delegate.set_window(child.get()); | 666 child_delegate.set_window(child.get()); |
667 } | 667 } |
668 } | 668 } |
669 | 669 |
670 // Make sure StackChildAtTop moves both the window and layer to the front. | 670 // Make sure StackChildAtTop moves both the window and layer to the front. |
671 TEST_F(WindowTest, StackChildAtTop) { | 671 TEST_F(WindowTest, StackChildAtTop) { |
672 Window parent(NULL); | 672 Window parent(NULL); |
673 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 673 parent.Init(ui::LAYER_NOT_DRAWN); |
674 Window child1(NULL); | 674 Window child1(NULL); |
675 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 675 child1.Init(ui::LAYER_NOT_DRAWN); |
676 Window child2(NULL); | 676 Window child2(NULL); |
677 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 677 child2.Init(ui::LAYER_NOT_DRAWN); |
678 | 678 |
679 parent.AddChild(&child1); | 679 parent.AddChild(&child1); |
680 parent.AddChild(&child2); | 680 parent.AddChild(&child2); |
681 ASSERT_EQ(2u, parent.children().size()); | 681 ASSERT_EQ(2u, parent.children().size()); |
682 EXPECT_EQ(&child1, parent.children()[0]); | 682 EXPECT_EQ(&child1, parent.children()[0]); |
683 EXPECT_EQ(&child2, parent.children()[1]); | 683 EXPECT_EQ(&child2, parent.children()[1]); |
684 ASSERT_EQ(2u, parent.layer()->children().size()); | 684 ASSERT_EQ(2u, parent.layer()->children().size()); |
685 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 685 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
686 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 686 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
687 | 687 |
688 parent.StackChildAtTop(&child1); | 688 parent.StackChildAtTop(&child1); |
689 ASSERT_EQ(2u, parent.children().size()); | 689 ASSERT_EQ(2u, parent.children().size()); |
690 EXPECT_EQ(&child1, parent.children()[1]); | 690 EXPECT_EQ(&child1, parent.children()[1]); |
691 EXPECT_EQ(&child2, parent.children()[0]); | 691 EXPECT_EQ(&child2, parent.children()[0]); |
692 ASSERT_EQ(2u, parent.layer()->children().size()); | 692 ASSERT_EQ(2u, parent.layer()->children().size()); |
693 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 693 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
694 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 694 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
695 } | 695 } |
696 | 696 |
697 // Make sure StackChildBelow works. | 697 // Make sure StackChildBelow works. |
698 TEST_F(WindowTest, StackChildBelow) { | 698 TEST_F(WindowTest, StackChildBelow) { |
699 Window parent(NULL); | 699 Window parent(NULL); |
700 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 700 parent.Init(ui::LAYER_NOT_DRAWN); |
701 Window child1(NULL); | 701 Window child1(NULL); |
702 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 702 child1.Init(ui::LAYER_NOT_DRAWN); |
703 child1.set_id(1); | 703 child1.set_id(1); |
704 Window child2(NULL); | 704 Window child2(NULL); |
705 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 705 child2.Init(ui::LAYER_NOT_DRAWN); |
706 child2.set_id(2); | 706 child2.set_id(2); |
707 Window child3(NULL); | 707 Window child3(NULL); |
708 child3.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 708 child3.Init(ui::LAYER_NOT_DRAWN); |
709 child3.set_id(3); | 709 child3.set_id(3); |
710 | 710 |
711 parent.AddChild(&child1); | 711 parent.AddChild(&child1); |
712 parent.AddChild(&child2); | 712 parent.AddChild(&child2); |
713 parent.AddChild(&child3); | 713 parent.AddChild(&child3); |
714 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 714 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
715 | 715 |
716 parent.StackChildBelow(&child1, &child2); | 716 parent.StackChildBelow(&child1, &child2); |
717 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 717 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
718 | 718 |
719 parent.StackChildBelow(&child2, &child1); | 719 parent.StackChildBelow(&child2, &child1); |
720 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); | 720 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); |
721 | 721 |
722 parent.StackChildBelow(&child3, &child2); | 722 parent.StackChildBelow(&child3, &child2); |
723 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); | 723 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); |
724 | 724 |
725 parent.StackChildBelow(&child3, &child1); | 725 parent.StackChildBelow(&child3, &child1); |
726 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); | 726 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); |
727 } | 727 } |
728 | 728 |
729 // Various assertions for StackChildAbove. | 729 // Various assertions for StackChildAbove. |
730 TEST_F(WindowTest, StackChildAbove) { | 730 TEST_F(WindowTest, StackChildAbove) { |
731 Window parent(NULL); | 731 Window parent(NULL); |
732 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 732 parent.Init(ui::LAYER_NOT_DRAWN); |
733 Window child1(NULL); | 733 Window child1(NULL); |
734 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 734 child1.Init(ui::LAYER_NOT_DRAWN); |
735 Window child2(NULL); | 735 Window child2(NULL); |
736 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 736 child2.Init(ui::LAYER_NOT_DRAWN); |
737 Window child3(NULL); | 737 Window child3(NULL); |
738 child3.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 738 child3.Init(ui::LAYER_NOT_DRAWN); |
739 | 739 |
740 parent.AddChild(&child1); | 740 parent.AddChild(&child1); |
741 parent.AddChild(&child2); | 741 parent.AddChild(&child2); |
742 | 742 |
743 // Move 1 in front of 2. | 743 // Move 1 in front of 2. |
744 parent.StackChildAbove(&child1, &child2); | 744 parent.StackChildAbove(&child1, &child2); |
745 ASSERT_EQ(2u, parent.children().size()); | 745 ASSERT_EQ(2u, parent.children().size()); |
746 EXPECT_EQ(&child2, parent.children()[0]); | 746 EXPECT_EQ(&child2, parent.children()[0]); |
747 EXPECT_EQ(&child1, parent.children()[1]); | 747 EXPECT_EQ(&child1, parent.children()[1]); |
748 ASSERT_EQ(2u, parent.layer()->children().size()); | 748 ASSERT_EQ(2u, parent.layer()->children().size()); |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2030 EXPECT_TRUE(window1_layer->delegate() == NULL); | 2030 EXPECT_TRUE(window1_layer->delegate() == NULL); |
2031 EXPECT_EQ(1U, parent->children().size()); | 2031 EXPECT_EQ(1U, parent->children().size()); |
2032 } | 2032 } |
2033 | 2033 |
2034 // Make sure that properties which should persist from the old layer to the new | 2034 // Make sure that properties which should persist from the old layer to the new |
2035 // layer actually do. | 2035 // layer actually do. |
2036 TEST_F(WindowTest, RecreateLayer) { | 2036 TEST_F(WindowTest, RecreateLayer) { |
2037 // Set properties to non default values. | 2037 // Set properties to non default values. |
2038 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); | 2038 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); |
2039 w.set_id(1); | 2039 w.set_id(1); |
2040 w.Init(aura::WINDOW_LAYER_SOLID_COLOR); | 2040 w.Init(ui::LAYER_SOLID_COLOR); |
2041 w.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2041 w.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2042 | 2042 |
2043 ui::Layer* layer = w.layer(); | 2043 ui::Layer* layer = w.layer(); |
2044 layer->SetVisible(false); | 2044 layer->SetVisible(false); |
2045 layer->SetMasksToBounds(true); | 2045 layer->SetMasksToBounds(true); |
2046 | 2046 |
2047 ui::Layer child_layer; | 2047 ui::Layer child_layer; |
2048 layer->Add(&child_layer); | 2048 layer->Add(&child_layer); |
2049 | 2049 |
2050 scoped_ptr<ui::Layer> old_layer(w.RecreateLayer()); | 2050 scoped_ptr<ui::Layer> old_layer(w.RecreateLayer()); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2295 int removed_count_; | 2295 int removed_count_; |
2296 | 2296 |
2297 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); | 2297 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); |
2298 }; | 2298 }; |
2299 | 2299 |
2300 TEST_F(WindowTest, RootWindowAttachment) { | 2300 TEST_F(WindowTest, RootWindowAttachment) { |
2301 RootWindowAttachmentObserver observer; | 2301 RootWindowAttachmentObserver observer; |
2302 | 2302 |
2303 // Test a direct add/remove from the RootWindow. | 2303 // Test a direct add/remove from the RootWindow. |
2304 scoped_ptr<Window> w1(new Window(NULL)); | 2304 scoped_ptr<Window> w1(new Window(NULL)); |
2305 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2305 w1->Init(ui::LAYER_NOT_DRAWN); |
2306 w1->AddObserver(&observer); | 2306 w1->AddObserver(&observer); |
2307 | 2307 |
2308 ParentWindow(w1.get()); | 2308 ParentWindow(w1.get()); |
2309 EXPECT_EQ(1, observer.added_count()); | 2309 EXPECT_EQ(1, observer.added_count()); |
2310 EXPECT_EQ(0, observer.removed_count()); | 2310 EXPECT_EQ(0, observer.removed_count()); |
2311 | 2311 |
2312 w1.reset(); | 2312 w1.reset(); |
2313 EXPECT_EQ(1, observer.added_count()); | 2313 EXPECT_EQ(1, observer.added_count()); |
2314 EXPECT_EQ(1, observer.removed_count()); | 2314 EXPECT_EQ(1, observer.removed_count()); |
2315 | 2315 |
2316 observer.Clear(); | 2316 observer.Clear(); |
2317 | 2317 |
2318 // Test an indirect add/remove from the RootWindow. | 2318 // Test an indirect add/remove from the RootWindow. |
2319 w1.reset(new Window(NULL)); | 2319 w1.reset(new Window(NULL)); |
2320 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2320 w1->Init(ui::LAYER_NOT_DRAWN); |
2321 Window* w11 = new Window(NULL); | 2321 Window* w11 = new Window(NULL); |
2322 w11->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2322 w11->Init(ui::LAYER_NOT_DRAWN); |
2323 w11->AddObserver(&observer); | 2323 w11->AddObserver(&observer); |
2324 w1->AddChild(w11); | 2324 w1->AddChild(w11); |
2325 EXPECT_EQ(0, observer.added_count()); | 2325 EXPECT_EQ(0, observer.added_count()); |
2326 EXPECT_EQ(0, observer.removed_count()); | 2326 EXPECT_EQ(0, observer.removed_count()); |
2327 | 2327 |
2328 ParentWindow(w1.get()); | 2328 ParentWindow(w1.get()); |
2329 EXPECT_EQ(1, observer.added_count()); | 2329 EXPECT_EQ(1, observer.added_count()); |
2330 EXPECT_EQ(0, observer.removed_count()); | 2330 EXPECT_EQ(0, observer.removed_count()); |
2331 | 2331 |
2332 w1.reset(); // Deletes w11. | 2332 w1.reset(); // Deletes w11. |
2333 w11 = NULL; | 2333 w11 = NULL; |
2334 EXPECT_EQ(1, observer.added_count()); | 2334 EXPECT_EQ(1, observer.added_count()); |
2335 EXPECT_EQ(1, observer.removed_count()); | 2335 EXPECT_EQ(1, observer.removed_count()); |
2336 | 2336 |
2337 observer.Clear(); | 2337 observer.Clear(); |
2338 | 2338 |
2339 // Test an indirect add/remove with nested observers. | 2339 // Test an indirect add/remove with nested observers. |
2340 w1.reset(new Window(NULL)); | 2340 w1.reset(new Window(NULL)); |
2341 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2341 w1->Init(ui::LAYER_NOT_DRAWN); |
2342 w11 = new Window(NULL); | 2342 w11 = new Window(NULL); |
2343 w11->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2343 w11->Init(ui::LAYER_NOT_DRAWN); |
2344 w11->AddObserver(&observer); | 2344 w11->AddObserver(&observer); |
2345 w1->AddChild(w11); | 2345 w1->AddChild(w11); |
2346 Window* w111 = new Window(NULL); | 2346 Window* w111 = new Window(NULL); |
2347 w111->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2347 w111->Init(ui::LAYER_NOT_DRAWN); |
2348 w111->AddObserver(&observer); | 2348 w111->AddObserver(&observer); |
2349 w11->AddChild(w111); | 2349 w11->AddChild(w111); |
2350 | 2350 |
2351 EXPECT_EQ(0, observer.added_count()); | 2351 EXPECT_EQ(0, observer.added_count()); |
2352 EXPECT_EQ(0, observer.removed_count()); | 2352 EXPECT_EQ(0, observer.removed_count()); |
2353 | 2353 |
2354 ParentWindow(w1.get()); | 2354 ParentWindow(w1.get()); |
2355 EXPECT_EQ(2, observer.added_count()); | 2355 EXPECT_EQ(2, observer.added_count()); |
2356 EXPECT_EQ(0, observer.removed_count()); | 2356 EXPECT_EQ(0, observer.removed_count()); |
2357 | 2357 |
(...skipping 17 matching lines...) Expand all Loading... |
2375 bool root_set() const { return root_set_; } | 2375 bool root_set() const { return root_set_; } |
2376 | 2376 |
2377 private: | 2377 private: |
2378 bool root_set_; | 2378 bool root_set_; |
2379 | 2379 |
2380 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver); | 2380 DISALLOW_COPY_AND_ASSIGN(BoundsChangedWindowObserver); |
2381 }; | 2381 }; |
2382 | 2382 |
2383 TEST_F(WindowTest, RootWindowSetWhenReparenting) { | 2383 TEST_F(WindowTest, RootWindowSetWhenReparenting) { |
2384 Window parent1(NULL); | 2384 Window parent1(NULL); |
2385 parent1.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2385 parent1.Init(ui::LAYER_NOT_DRAWN); |
2386 Window parent2(NULL); | 2386 Window parent2(NULL); |
2387 parent2.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2387 parent2.Init(ui::LAYER_NOT_DRAWN); |
2388 ParentWindow(&parent1); | 2388 ParentWindow(&parent1); |
2389 ParentWindow(&parent2); | 2389 ParentWindow(&parent2); |
2390 parent1.SetBounds(gfx::Rect(10, 10, 300, 300)); | 2390 parent1.SetBounds(gfx::Rect(10, 10, 300, 300)); |
2391 parent2.SetBounds(gfx::Rect(20, 20, 300, 300)); | 2391 parent2.SetBounds(gfx::Rect(20, 20, 300, 300)); |
2392 | 2392 |
2393 BoundsChangedWindowObserver observer; | 2393 BoundsChangedWindowObserver observer; |
2394 Window child(NULL); | 2394 Window child(NULL); |
2395 child.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2395 child.Init(ui::LAYER_NOT_DRAWN); |
2396 child.SetBounds(gfx::Rect(5, 5, 100, 100)); | 2396 child.SetBounds(gfx::Rect(5, 5, 100, 100)); |
2397 parent1.AddChild(&child); | 2397 parent1.AddChild(&child); |
2398 | 2398 |
2399 // We need animations to start in order to observe the bounds changes. | 2399 // We need animations to start in order to observe the bounds changes. |
2400 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 2400 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
2401 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 2401 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
2402 ui::ScopedLayerAnimationSettings settings1(child.layer()->GetAnimator()); | 2402 ui::ScopedLayerAnimationSettings settings1(child.layer()->GetAnimator()); |
2403 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100)); | 2403 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100)); |
2404 gfx::Rect new_bounds(gfx::Rect(35, 35, 50, 50)); | 2404 gfx::Rect new_bounds(gfx::Rect(35, 35, 50, 50)); |
2405 child.SetBounds(new_bounds); | 2405 child.SetBounds(new_bounds); |
(...skipping 10 matching lines...) Expand all Loading... |
2416 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); | 2416 EXPECT_EQ(new_bounds.ToString(), child.GetTargetBounds().ToString()); |
2417 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); | 2417 EXPECT_EQ(new_bounds.ToString(), child.bounds().ToString()); |
2418 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); | 2418 EXPECT_EQ("55,55 50x50", child.GetBoundsInRootWindow().ToString()); |
2419 } | 2419 } |
2420 | 2420 |
2421 TEST_F(WindowTest, OwnedByParentFalse) { | 2421 TEST_F(WindowTest, OwnedByParentFalse) { |
2422 // By default, a window is owned by its parent. If this is set to false, the | 2422 // By default, a window is owned by its parent. If this is set to false, the |
2423 // window will not be destroyed when its parent is. | 2423 // window will not be destroyed when its parent is. |
2424 | 2424 |
2425 scoped_ptr<Window> w1(new Window(NULL)); | 2425 scoped_ptr<Window> w1(new Window(NULL)); |
2426 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2426 w1->Init(ui::LAYER_NOT_DRAWN); |
2427 scoped_ptr<Window> w2(new Window(NULL)); | 2427 scoped_ptr<Window> w2(new Window(NULL)); |
2428 w2->set_owned_by_parent(false); | 2428 w2->set_owned_by_parent(false); |
2429 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2429 w2->Init(ui::LAYER_NOT_DRAWN); |
2430 w1->AddChild(w2.get()); | 2430 w1->AddChild(w2.get()); |
2431 | 2431 |
2432 w1.reset(); | 2432 w1.reset(); |
2433 | 2433 |
2434 // We should be able to deref w2 still, but its parent should now be NULL. | 2434 // We should be able to deref w2 still, but its parent should now be NULL. |
2435 EXPECT_EQ(NULL, w2->parent()); | 2435 EXPECT_EQ(NULL, w2->parent()); |
2436 } | 2436 } |
2437 | 2437 |
2438 namespace { | 2438 namespace { |
2439 | 2439 |
(...skipping 17 matching lines...) Expand all Loading... |
2457 | 2457 |
2458 } // namespace | 2458 } // namespace |
2459 | 2459 |
2460 // Creates a window with two child windows. When the first child window is | 2460 // Creates a window with two child windows. When the first child window is |
2461 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. | 2461 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. |
2462 // This synthesizes BrowserView and the status bubble. Both are children of the | 2462 // This synthesizes BrowserView and the status bubble. Both are children of the |
2463 // same parent and destroying BrowserView triggers it destroying the status | 2463 // same parent and destroying BrowserView triggers it destroying the status |
2464 // bubble. | 2464 // bubble. |
2465 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { | 2465 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { |
2466 scoped_ptr<Window> parent(new Window(NULL)); | 2466 scoped_ptr<Window> parent(new Window(NULL)); |
2467 parent->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2467 parent->Init(ui::LAYER_NOT_DRAWN); |
2468 OwningWindowDelegate delegate; | 2468 OwningWindowDelegate delegate; |
2469 Window* c1 = new Window(&delegate); | 2469 Window* c1 = new Window(&delegate); |
2470 c1->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2470 c1->Init(ui::LAYER_NOT_DRAWN); |
2471 parent->AddChild(c1); | 2471 parent->AddChild(c1); |
2472 Window* c2 = new Window(NULL); | 2472 Window* c2 = new Window(NULL); |
2473 c2->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 2473 c2->Init(ui::LAYER_NOT_DRAWN); |
2474 parent->AddChild(c2); | 2474 parent->AddChild(c2); |
2475 delegate.SetOwnedWindow(c2); | 2475 delegate.SetOwnedWindow(c2); |
2476 parent.reset(); | 2476 parent.reset(); |
2477 } | 2477 } |
2478 | 2478 |
2479 namespace { | 2479 namespace { |
2480 | 2480 |
2481 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is | 2481 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is |
2482 // invoked. | 2482 // invoked. |
2483 class BoundsChangeDelegate : public TestWindowDelegate { | 2483 class BoundsChangeDelegate : public TestWindowDelegate { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2831 o.ValidateState(index++, params); | 2831 o.ValidateState(index++, params); |
2832 params.receiver = root_window(); | 2832 params.receiver = root_window(); |
2833 o.ValidateState(index++, params); | 2833 o.ValidateState(index++, params); |
2834 | 2834 |
2835 w1.reset(); | 2835 w1.reset(); |
2836 w2.reset(); | 2836 w2.reset(); |
2837 } | 2837 } |
2838 | 2838 |
2839 } | 2839 } |
2840 | 2840 |
2841 // Verifies SchedulePaint() on a layerless window results in damaging the right | |
2842 // thing. | |
2843 TEST_F(WindowTest, LayerlessWindowSchedulePaint) { | |
2844 Window root(NULL); | |
2845 root.Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
2846 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
2847 | |
2848 Window* layerless_window = new Window(NULL); // Owned by |root|. | |
2849 layerless_window->Init(WINDOW_LAYER_NONE); | |
2850 layerless_window->SetBounds(gfx::Rect(10, 11, 12, 13)); | |
2851 root.AddChild(layerless_window); | |
2852 | |
2853 root.layer()->SendDamagedRects(); | |
2854 layerless_window->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); | |
2855 // Note the the region is clipped by the parent hence 100 going to 11. | |
2856 EXPECT_EQ("11,13 11x4", | |
2857 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). | |
2858 ToString()); | |
2859 | |
2860 Window* layerless_window2 = new Window(NULL); // Owned by |layerless_window|. | |
2861 layerless_window2->Init(WINDOW_LAYER_NONE); | |
2862 layerless_window2->SetBounds(gfx::Rect(1, 2, 3, 4)); | |
2863 layerless_window->AddChild(layerless_window2); | |
2864 | |
2865 root.layer()->SendDamagedRects(); | |
2866 layerless_window2->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); | |
2867 // Note the the region is clipped by the |layerless_window| hence 100 going to | |
2868 // 2. | |
2869 EXPECT_EQ("12,15 2x2", | |
2870 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). | |
2871 ToString()); | |
2872 } | |
2873 | |
2874 // Verifies bounds of layerless windows are correctly updated when adding | |
2875 // removing. | |
2876 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnAddRemove) { | |
2877 // Creates the following structure (all children owned by root): | |
2878 // root | |
2879 // w1ll 1,2 | |
2880 // w11ll 3,4 | |
2881 // w111 5,6 | |
2882 // w12 7,8 | |
2883 // w121 9,10 | |
2884 // | |
2885 // ll: layer less, eg no layer | |
2886 Window root(NULL); | |
2887 root.Init(WINDOW_LAYER_NOT_DRAWN); | |
2888 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
2889 | |
2890 Window* w1ll = new Window(NULL); | |
2891 w1ll->Init(WINDOW_LAYER_NONE); | |
2892 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | |
2893 | |
2894 Window* w11ll = new Window(NULL); | |
2895 w11ll->Init(WINDOW_LAYER_NONE); | |
2896 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | |
2897 w1ll->AddChild(w11ll); | |
2898 | |
2899 Window* w111 = new Window(NULL); | |
2900 w111->Init(WINDOW_LAYER_NOT_DRAWN); | |
2901 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
2902 w11ll->AddChild(w111); | |
2903 | |
2904 Window* w12 = new Window(NULL); | |
2905 w12->Init(WINDOW_LAYER_NOT_DRAWN); | |
2906 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | |
2907 w1ll->AddChild(w12); | |
2908 | |
2909 Window* w121 = new Window(NULL); | |
2910 w121->Init(WINDOW_LAYER_NOT_DRAWN); | |
2911 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | |
2912 w12->AddChild(w121); | |
2913 | |
2914 root.AddChild(w1ll); | |
2915 | |
2916 // All layers should be parented to the root. | |
2917 EXPECT_EQ(root.layer(), w111->layer()->parent()); | |
2918 EXPECT_EQ(root.layer(), w12->layer()->parent()); | |
2919 EXPECT_EQ(w12->layer(), w121->layer()->parent()); | |
2920 | |
2921 // Ensure bounds are what we expect. | |
2922 EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString()); | |
2923 EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString()); | |
2924 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); | |
2925 EXPECT_EQ("7,8 100x100", w12->bounds().ToString()); | |
2926 EXPECT_EQ("9,10 100x100", w121->bounds().ToString()); | |
2927 | |
2928 // Bounds of layers are relative to the nearest ancestor with a layer. | |
2929 EXPECT_EQ("8,10 100x100", w12->layer()->bounds().ToString()); | |
2930 EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString()); | |
2931 EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString()); | |
2932 | |
2933 // Remove and repeat. | |
2934 root.RemoveChild(w1ll); | |
2935 | |
2936 EXPECT_TRUE(w111->layer()->parent() == NULL); | |
2937 EXPECT_TRUE(w12->layer()->parent() == NULL); | |
2938 | |
2939 // Verify bounds haven't changed again. | |
2940 EXPECT_EQ("1,2 100x100", w1ll->bounds().ToString()); | |
2941 EXPECT_EQ("3,4 100x100", w11ll->bounds().ToString()); | |
2942 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); | |
2943 EXPECT_EQ("7,8 100x100", w12->bounds().ToString()); | |
2944 EXPECT_EQ("9,10 100x100", w121->bounds().ToString()); | |
2945 | |
2946 // Bounds of layers should now match that of windows. | |
2947 EXPECT_EQ("7,8 100x100", w12->layer()->bounds().ToString()); | |
2948 EXPECT_EQ("5,6 100x100", w111->layer()->bounds().ToString()); | |
2949 EXPECT_EQ("9,10 100x100", w121->layer()->bounds().ToString()); | |
2950 | |
2951 delete w1ll; | |
2952 } | |
2953 | |
2954 // Verifies bounds of layerless windows are correctly updated when bounds | |
2955 // of ancestor changes. | |
2956 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnSetBounds) { | |
2957 // Creates the following structure (all children owned by root): | |
2958 // root | |
2959 // w1ll 1,2 | |
2960 // w11ll 3,4 | |
2961 // w111 5,6 | |
2962 // w12 7,8 | |
2963 // w121 9,10 | |
2964 // | |
2965 // ll: layer less, eg no layer | |
2966 Window root(NULL); | |
2967 root.Init(WINDOW_LAYER_NOT_DRAWN); | |
2968 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
2969 | |
2970 Window* w1ll = new Window(NULL); | |
2971 w1ll->Init(WINDOW_LAYER_NONE); | |
2972 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | |
2973 | |
2974 Window* w11ll = new Window(NULL); | |
2975 w11ll->Init(WINDOW_LAYER_NONE); | |
2976 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | |
2977 w1ll->AddChild(w11ll); | |
2978 | |
2979 Window* w111 = new Window(NULL); | |
2980 w111->Init(WINDOW_LAYER_NOT_DRAWN); | |
2981 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
2982 w11ll->AddChild(w111); | |
2983 | |
2984 Window* w12 = new Window(NULL); | |
2985 w12->Init(WINDOW_LAYER_NOT_DRAWN); | |
2986 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | |
2987 w1ll->AddChild(w12); | |
2988 | |
2989 Window* w121 = new Window(NULL); | |
2990 w121->Init(WINDOW_LAYER_NOT_DRAWN); | |
2991 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | |
2992 w12->AddChild(w121); | |
2993 | |
2994 root.AddChild(w1ll); | |
2995 | |
2996 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); | |
2997 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); | |
2998 EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString()); | |
2999 EXPECT_EQ("11,14 11x12", w111->layer()->bounds().ToString()); | |
3000 | |
3001 // Set back. | |
3002 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
3003 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); | |
3004 EXPECT_EQ("5,6 100x100", w111->GetTargetBounds().ToString()); | |
3005 EXPECT_EQ("9,12 100x100", w111->layer()->bounds().ToString()); | |
3006 | |
3007 // Setting the bounds of a layerless window needs to adjust the bounds of | |
3008 // layered children. | |
3009 w11ll->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
3010 EXPECT_EQ("5,6 100x100", w11ll->bounds().ToString()); | |
3011 EXPECT_EQ("5,6 100x100", w11ll->GetTargetBounds().ToString()); | |
3012 EXPECT_EQ("5,6 100x100", w111->bounds().ToString()); | |
3013 EXPECT_EQ("5,6 100x100", w111->GetTargetBounds().ToString()); | |
3014 EXPECT_EQ("11,14 100x100", w111->layer()->bounds().ToString()); | |
3015 | |
3016 root.RemoveChild(w1ll); | |
3017 | |
3018 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); | |
3019 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); | |
3020 EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString()); | |
3021 EXPECT_EQ("7,8 11x12", w111->layer()->bounds().ToString()); | |
3022 | |
3023 delete w1ll; | |
3024 } | |
3025 | |
3026 namespace { | 2841 namespace { |
3027 | 2842 |
3028 // Tracks the number of times paint is invoked along with what the clip and | 2843 // Tracks the number of times paint is invoked along with what the clip and |
3029 // translate was. | 2844 // translate was. |
3030 class PaintWindowDelegate : public TestWindowDelegate { | 2845 class PaintWindowDelegate : public TestWindowDelegate { |
3031 public: | 2846 public: |
3032 PaintWindowDelegate() : paint_count_(0) {} | 2847 PaintWindowDelegate() : paint_count_(0) {} |
3033 ~PaintWindowDelegate() override {} | 2848 ~PaintWindowDelegate() override {} |
3034 | 2849 |
3035 const gfx::Rect& most_recent_paint_clip_bounds() const { | 2850 const gfx::Rect& most_recent_paint_clip_bounds() const { |
(...skipping 20 matching lines...) Expand all Loading... |
3056 private: | 2871 private: |
3057 int paint_count_; | 2872 int paint_count_; |
3058 gfx::Rect most_recent_paint_clip_bounds_; | 2873 gfx::Rect most_recent_paint_clip_bounds_; |
3059 gfx::Vector2d most_recent_paint_matrix_offset_; | 2874 gfx::Vector2d most_recent_paint_matrix_offset_; |
3060 | 2875 |
3061 DISALLOW_COPY_AND_ASSIGN(PaintWindowDelegate); | 2876 DISALLOW_COPY_AND_ASSIGN(PaintWindowDelegate); |
3062 }; | 2877 }; |
3063 | 2878 |
3064 } // namespace | 2879 } // namespace |
3065 | 2880 |
3066 // Assertions around layerless children being painted when non-layerless window | |
3067 // is painted. | |
3068 TEST_F(WindowTest, PaintLayerless) { | |
3069 // Creates the following structure (all children owned by root): | |
3070 // root | |
3071 // w1ll 1,2 40x50 | |
3072 // w11ll 3,4 11x12 | |
3073 // w111 5,6 | |
3074 // | |
3075 // ll: layer less, eg no layer | |
3076 PaintWindowDelegate w1ll_delegate; | |
3077 PaintWindowDelegate w11ll_delegate; | |
3078 PaintWindowDelegate w111_delegate; | |
3079 | |
3080 Window root(NULL); | |
3081 root.Init(WINDOW_LAYER_NOT_DRAWN); | |
3082 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
3083 | |
3084 Window* w1ll = new Window(&w1ll_delegate); | |
3085 w1ll->Init(WINDOW_LAYER_NONE); | |
3086 w1ll->SetBounds(gfx::Rect(1, 2, 40, 50)); | |
3087 w1ll->Show(); | |
3088 root.AddChild(w1ll); | |
3089 | |
3090 Window* w11ll = new Window(&w11ll_delegate); | |
3091 w11ll->Init(WINDOW_LAYER_NONE); | |
3092 w11ll->SetBounds(gfx::Rect(3, 4, 11, 12)); | |
3093 w11ll->Show(); | |
3094 w1ll->AddChild(w11ll); | |
3095 | |
3096 Window* w111 = new Window(&w111_delegate); | |
3097 w111->Init(WINDOW_LAYER_NOT_DRAWN); | |
3098 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
3099 w111->Show(); | |
3100 w11ll->AddChild(w111); | |
3101 | |
3102 EXPECT_EQ(0, w1ll_delegate.paint_count()); | |
3103 EXPECT_EQ(0, w11ll_delegate.paint_count()); | |
3104 EXPECT_EQ(0, w111_delegate.paint_count()); | |
3105 | |
3106 // Paint the root, this should trigger painting of the two layerless | |
3107 // descendants but not the layered descendant. | |
3108 gfx::Canvas canvas(gfx::Size(200, 200), 1.0f, true); | |
3109 static_cast<ui::LayerDelegate&>(root).OnPaintLayer(&canvas); | |
3110 | |
3111 // NOTE: SkCanvas::getClipBounds() extends the clip 1 pixel to the left and up | |
3112 // and 2 pixels down and to the right. | |
3113 EXPECT_EQ(1, w1ll_delegate.paint_count()); | |
3114 EXPECT_EQ("-1,-1 42x52", | |
3115 w1ll_delegate.most_recent_paint_clip_bounds().ToString()); | |
3116 EXPECT_EQ("[1 2]", | |
3117 w1ll_delegate.most_recent_paint_matrix_offset().ToString()); | |
3118 EXPECT_EQ(1, w11ll_delegate.paint_count()); | |
3119 EXPECT_EQ("-1,-1 13x14", | |
3120 w11ll_delegate.most_recent_paint_clip_bounds().ToString()); | |
3121 EXPECT_EQ("[4 6]", | |
3122 w11ll_delegate.most_recent_paint_matrix_offset().ToString()); | |
3123 EXPECT_EQ(0, w111_delegate.paint_count()); | |
3124 } | |
3125 | |
3126 namespace { | |
3127 | |
3128 std::string ConvertPointToTargetString(const Window* source, | |
3129 const Window* target) { | |
3130 gfx::Point location; | |
3131 Window::ConvertPointToTarget(source, target, &location); | |
3132 return location.ToString(); | |
3133 } | |
3134 | |
3135 } // namespace | |
3136 | |
3137 // Assertions around Window::ConvertPointToTarget() with layerless windows. | |
3138 TEST_F(WindowTest, ConvertPointToTargetLayerless) { | |
3139 // Creates the following structure (all children owned by root): | |
3140 // root | |
3141 // w1ll 1,2 | |
3142 // w11ll 3,4 | |
3143 // w111 5,6 | |
3144 // w12 7,8 | |
3145 // w121 9,10 | |
3146 // | |
3147 // ll: layer less, eg no layer | |
3148 Window root(NULL); | |
3149 root.Init(WINDOW_LAYER_NOT_DRAWN); | |
3150 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
3151 | |
3152 Window* w1ll = new Window(NULL); | |
3153 w1ll->Init(WINDOW_LAYER_NONE); | |
3154 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | |
3155 | |
3156 Window* w11ll = new Window(NULL); | |
3157 w11ll->Init(WINDOW_LAYER_NONE); | |
3158 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | |
3159 w1ll->AddChild(w11ll); | |
3160 | |
3161 Window* w111 = new Window(NULL); | |
3162 w111->Init(WINDOW_LAYER_NOT_DRAWN); | |
3163 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | |
3164 w11ll->AddChild(w111); | |
3165 | |
3166 Window* w12 = new Window(NULL); | |
3167 w12->Init(WINDOW_LAYER_NOT_DRAWN); | |
3168 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | |
3169 w1ll->AddChild(w12); | |
3170 | |
3171 Window* w121 = new Window(NULL); | |
3172 w121->Init(WINDOW_LAYER_NOT_DRAWN); | |
3173 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | |
3174 w12->AddChild(w121); | |
3175 | |
3176 root.AddChild(w1ll); | |
3177 | |
3178 // w111->w11ll | |
3179 EXPECT_EQ("5,6", ConvertPointToTargetString(w111, w11ll)); | |
3180 | |
3181 // w111->w1ll | |
3182 EXPECT_EQ("8,10", ConvertPointToTargetString(w111, w1ll)); | |
3183 | |
3184 // w111->root | |
3185 EXPECT_EQ("9,12", ConvertPointToTargetString(w111, &root)); | |
3186 | |
3187 // w111->w12 | |
3188 EXPECT_EQ("1,2", ConvertPointToTargetString(w111, w12)); | |
3189 | |
3190 // w111->w121 | |
3191 EXPECT_EQ("-8,-8", ConvertPointToTargetString(w111, w121)); | |
3192 | |
3193 // w11ll->w111 | |
3194 EXPECT_EQ("-5,-6", ConvertPointToTargetString(w11ll, w111)); | |
3195 | |
3196 // w11ll->w11ll | |
3197 EXPECT_EQ("3,4", ConvertPointToTargetString(w11ll, w1ll)); | |
3198 | |
3199 // w11ll->root | |
3200 EXPECT_EQ("4,6", ConvertPointToTargetString(w11ll, &root)); | |
3201 | |
3202 // w11ll->w12 | |
3203 EXPECT_EQ("-4,-4", ConvertPointToTargetString(w11ll, w12)); | |
3204 } | |
3205 | |
3206 #if !defined(NDEBUG) | |
3207 // Verifies PrintWindowHierarchy() doesn't crash with a layerless window. | |
3208 TEST_F(WindowTest, PrintWindowHierarchyNotCrashLayerless) { | |
3209 Window root(NULL); | |
3210 root.Init(WINDOW_LAYER_NONE); | |
3211 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
3212 root.PrintWindowHierarchy(0); | |
3213 } | |
3214 #endif | |
3215 | |
3216 namespace { | |
3217 | |
3218 // See AddWindowsFromString() for details. | |
3219 aura::Window* CreateWindowFromDescription(const std::string& description, | |
3220 WindowDelegate* delegate) { | |
3221 WindowLayerType window_type = WINDOW_LAYER_NOT_DRAWN; | |
3222 std::vector<std::string> tokens; | |
3223 Tokenize(description, ":", &tokens); | |
3224 DCHECK(!tokens.empty()); | |
3225 std::string name(tokens[0]); | |
3226 tokens.erase(tokens.begin()); | |
3227 if (!tokens.empty()) { | |
3228 if (tokens[0] == "ll") { | |
3229 window_type = WINDOW_LAYER_NONE; | |
3230 tokens.erase(tokens.begin()); | |
3231 } | |
3232 DCHECK(tokens.empty()) << "unknown tokens for creating window " | |
3233 << description; | |
3234 } | |
3235 Window* window = new Window(delegate); | |
3236 window->Init(window_type); | |
3237 window->SetName(name); | |
3238 // Window name is only propagated to layer in debug builds. | |
3239 if (window->layer()) | |
3240 window->layer()->set_name(name); | |
3241 return window; | |
3242 } | |
3243 | |
3244 // Creates and adds a tree of windows to |parent|. |description| consists | |
3245 // of the following pieces: | |
3246 // X: Identifies a new window. Consists of a name and optionally ":ll" to | |
3247 // specify WINDOW_LAYER_NONE, eg "w1:ll". | |
3248 // []: optionally used to specify the children of the window. Contains any | |
3249 // number of window identifiers and their corresponding children. | |
3250 // For example: "[ a [ a1 a2:ll ] b c [ c1 ] ]" creates the tree: | |
3251 // a | |
3252 // a1 | |
3253 // a2 -> WINDOW_LAYER_NONE. | |
3254 // b | |
3255 // c | |
3256 // c1 | |
3257 // NOTE: you must have a space after every token. | |
3258 std::string::size_type AddWindowsFromString(aura::Window* parent, | |
3259 const std::string& description, | |
3260 std::string::size_type start_pos, | |
3261 WindowDelegate* delegate) { | |
3262 DCHECK(parent); | |
3263 std::string::size_type end_pos = description.find(' ', start_pos); | |
3264 while (end_pos != std::string::npos) { | |
3265 const std::string::size_type part_length = end_pos - start_pos; | |
3266 const std::string window_description = | |
3267 description.substr(start_pos, part_length); | |
3268 if (window_description == "[") { | |
3269 start_pos = AddWindowsFromString(parent->children().back(), | |
3270 description, | |
3271 end_pos + 1, | |
3272 delegate); | |
3273 end_pos = description.find(' ', start_pos); | |
3274 if (end_pos == std::string::npos && start_pos != end_pos) | |
3275 end_pos = description.length(); | |
3276 } else if (window_description == "]") { | |
3277 ++end_pos; | |
3278 break; | |
3279 } else { | |
3280 Window* window = | |
3281 CreateWindowFromDescription(window_description, delegate); | |
3282 parent->AddChild(window); | |
3283 start_pos = ++end_pos; | |
3284 end_pos = description.find(' ', start_pos); | |
3285 } | |
3286 } | |
3287 return end_pos; | |
3288 } | |
3289 | |
3290 // Used by BuildRootWindowTreeDescription(). | |
3291 std::string BuildWindowTreeDescription(const aura::Window& window) { | |
3292 std::string result; | |
3293 result += window.name(); | |
3294 if (window.children().empty()) | |
3295 return result; | |
3296 | |
3297 result += " [ "; | |
3298 for (size_t i = 0; i < window.children().size(); ++i) { | |
3299 if (i != 0) | |
3300 result += " "; | |
3301 result += BuildWindowTreeDescription(*(window.children()[i])); | |
3302 } | |
3303 result += " ]"; | |
3304 return result; | |
3305 } | |
3306 | |
3307 // Creates a string from |window|. See AddWindowsFromString() for details of the | |
3308 // returned string. This does *not* include the layer type in the description, | |
3309 // on the name. | |
3310 std::string BuildRootWindowTreeDescription(const aura::Window& window) { | |
3311 std::string result; | |
3312 for (size_t i = 0; i < window.children().size(); ++i) { | |
3313 if (i != 0) | |
3314 result += " "; | |
3315 result += BuildWindowTreeDescription(*(window.children()[i])); | |
3316 } | |
3317 return result; | |
3318 } | |
3319 | |
3320 // Used by BuildRootWindowTreeDescription(). | |
3321 std::string BuildLayerTreeDescription(const ui::Layer& layer) { | |
3322 std::string result; | |
3323 result += layer.name(); | |
3324 if (layer.children().empty()) | |
3325 return result; | |
3326 | |
3327 result += " [ "; | |
3328 for (size_t i = 0; i < layer.children().size(); ++i) { | |
3329 if (i != 0) | |
3330 result += " "; | |
3331 result += BuildLayerTreeDescription(*(layer.children()[i])); | |
3332 } | |
3333 result += " ]"; | |
3334 return result; | |
3335 } | |
3336 | |
3337 // Builds a string for all the children of |layer|. The returned string is in | |
3338 // the same format as AddWindowsFromString() but only includes the name of the | |
3339 // layers. | |
3340 std::string BuildRootLayerTreeDescription(const ui::Layer& layer) { | |
3341 std::string result; | |
3342 for (size_t i = 0; i < layer.children().size(); ++i) { | |
3343 if (i != 0) | |
3344 result += " "; | |
3345 result += BuildLayerTreeDescription(*(layer.children()[i])); | |
3346 } | |
3347 return result; | |
3348 } | |
3349 | |
3350 // Returns the first window whose name matches |name| in |parent|. | |
3351 aura::Window* FindWindowByName(aura::Window* parent, | |
3352 const std::string& name) { | |
3353 if (parent->name() == name) | |
3354 return parent; | |
3355 for (size_t i = 0; i < parent->children().size(); ++i) { | |
3356 aura::Window* child = FindWindowByName(parent->children()[i], name); | |
3357 if (child) | |
3358 return child; | |
3359 } | |
3360 return NULL; | |
3361 } | |
3362 | |
3363 } // namespace | |
3364 | |
3365 // Direction to stack. | |
3366 enum StackType { | |
3367 STACK_ABOVE, | |
3368 STACK_BELOW, | |
3369 STACK_AT_BOTTOM, | |
3370 STACK_AT_TOP, | |
3371 }; | |
3372 | |
3373 // Permutations of StackChildAt with various data. | |
3374 TEST_F(WindowTest, StackChildAtLayerless) { | |
3375 struct TestData { | |
3376 // Describes the window tree to create. See AddWindowsFromString() for | |
3377 // details. | |
3378 const std::string initial_description; | |
3379 | |
3380 // Identifies the window to move. | |
3381 const std::string source_window; | |
3382 | |
3383 // Window to move |source_window| relative to. Not used for STACK_AT_BOTTOM | |
3384 // or STACK_AT_TOP. | |
3385 const std::string target_window; | |
3386 | |
3387 StackType stack_type; | |
3388 | |
3389 // Expected window and layer results. | |
3390 const std::string expected_description; | |
3391 const std::string expected_layer_description; | |
3392 } data[] = { | |
3393 // 1 at top. | |
3394 { | |
3395 "1:ll [ 11 12 ] 2:ll [ 21 ]", | |
3396 "1", | |
3397 "", | |
3398 STACK_AT_TOP, | |
3399 "2 [ 21 ] 1 [ 11 12 ]", | |
3400 "21 11 12", | |
3401 }, | |
3402 | |
3403 // 1 at bottom. | |
3404 { | |
3405 "1:ll [ 11 12 ] 2:ll [ 21 ]", | |
3406 "1", | |
3407 "", | |
3408 STACK_AT_BOTTOM, | |
3409 "1 [ 11 12 ] 2 [ 21 ]", | |
3410 "11 12 21", | |
3411 }, | |
3412 | |
3413 // 2 at bottom. | |
3414 { | |
3415 "1:ll [ 11 12 ] 2:ll [ 21 ]", | |
3416 "2", | |
3417 "", | |
3418 STACK_AT_BOTTOM, | |
3419 "2 [ 21 ] 1 [ 11 12 ]", | |
3420 "21 11 12", | |
3421 }, | |
3422 | |
3423 // 3 below 2. | |
3424 { | |
3425 "1:ll [ 11 12 ] 2:ll [ 21 ] 3:ll", | |
3426 "3", | |
3427 "2", | |
3428 STACK_BELOW, | |
3429 "1 [ 11 12 ] 3 2 [ 21 ]", | |
3430 "11 12 21", | |
3431 }, | |
3432 | |
3433 // 2 below 1. | |
3434 { | |
3435 "1:ll [ 11 12 ] 2:ll [ 21 ]", | |
3436 "2", | |
3437 "1", | |
3438 STACK_BELOW, | |
3439 "2 [ 21 ] 1 [ 11 12 ]", | |
3440 "21 11 12", | |
3441 }, | |
3442 | |
3443 // 1 above 3. | |
3444 { | |
3445 "1:ll [ 11 12 ] 2:ll [ 21 ] 3:ll", | |
3446 "1", | |
3447 "3", | |
3448 STACK_ABOVE, | |
3449 "2 [ 21 ] 3 1 [ 11 12 ]", | |
3450 "21 11 12", | |
3451 }, | |
3452 | |
3453 // 1 above 2. | |
3454 { | |
3455 "1:ll [ 11 12 ] 2:ll [ 21 ]", | |
3456 "1", | |
3457 "2", | |
3458 STACK_ABOVE, | |
3459 "2 [ 21 ] 1 [ 11 12 ]", | |
3460 "21 11 12", | |
3461 }, | |
3462 }; | |
3463 for (size_t i = 0; i < arraysize(data); ++i) { | |
3464 test::TestWindowDelegate delegate; | |
3465 Window root(NULL); | |
3466 root.Init(WINDOW_LAYER_NOT_DRAWN); | |
3467 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | |
3468 AddWindowsFromString( | |
3469 &root, | |
3470 data[i].initial_description, | |
3471 static_cast<std::string::size_type>(0), &delegate); | |
3472 aura::Window* source = FindWindowByName(&root, data[i].source_window); | |
3473 ASSERT_TRUE(source != NULL) << "unable to find source window " | |
3474 << data[i].source_window << " at " << i; | |
3475 aura::Window* target = FindWindowByName(&root, data[i].target_window); | |
3476 switch (data[i].stack_type) { | |
3477 case STACK_ABOVE: | |
3478 ASSERT_TRUE(target != NULL) << "unable to find target window " | |
3479 << data[i].target_window << " at " << i; | |
3480 source->parent()->StackChildAbove(source, target); | |
3481 break; | |
3482 case STACK_BELOW: | |
3483 ASSERT_TRUE(target != NULL) << "unable to find target window " | |
3484 << data[i].target_window << " at " << i; | |
3485 source->parent()->StackChildBelow(source, target); | |
3486 break; | |
3487 case STACK_AT_BOTTOM: | |
3488 source->parent()->StackChildAtBottom(source); | |
3489 break; | |
3490 case STACK_AT_TOP: | |
3491 source->parent()->StackChildAtTop(source); | |
3492 break; | |
3493 } | |
3494 EXPECT_EQ(data[i].expected_layer_description, | |
3495 BuildRootLayerTreeDescription(*root.layer())) | |
3496 << "layer tree doesn't match at " << i; | |
3497 EXPECT_EQ(data[i].expected_description, | |
3498 BuildRootWindowTreeDescription(root)) | |
3499 << "window tree doesn't match at " << i; | |
3500 } | |
3501 } | |
3502 | |
3503 namespace { | 2881 namespace { |
3504 | 2882 |
3505 class TestLayerAnimationObserver : public ui::LayerAnimationObserver { | 2883 class TestLayerAnimationObserver : public ui::LayerAnimationObserver { |
3506 public: | 2884 public: |
3507 TestLayerAnimationObserver() | 2885 TestLayerAnimationObserver() |
3508 : animation_completed_(false), | 2886 : animation_completed_(false), |
3509 animation_aborted_(false) {} | 2887 animation_aborted_(false) {} |
3510 ~TestLayerAnimationObserver() override {} | 2888 ~TestLayerAnimationObserver() override {} |
3511 | 2889 |
3512 bool animation_completed() const { return animation_completed_; } | 2890 bool animation_completed() const { return animation_completed_; } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 | 2960 |
3583 EXPECT_TRUE(animator.get()); | 2961 EXPECT_TRUE(animator.get()); |
3584 EXPECT_FALSE(animator->is_animating()); | 2962 EXPECT_FALSE(animator->is_animating()); |
3585 EXPECT_TRUE(observer.animation_completed()); | 2963 EXPECT_TRUE(observer.animation_completed()); |
3586 EXPECT_FALSE(observer.animation_aborted()); | 2964 EXPECT_FALSE(observer.animation_aborted()); |
3587 animator->RemoveObserver(&observer); | 2965 animator->RemoveObserver(&observer); |
3588 } | 2966 } |
3589 | 2967 |
3590 } // namespace test | 2968 } // namespace test |
3591 } // namespace aura | 2969 } // namespace aura |
OLD | NEW |