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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 EXPECT_EQ(NULL, w1->GetChildById(57)); | 262 EXPECT_EQ(NULL, w1->GetChildById(57)); |
263 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 263 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
264 EXPECT_EQ(w111.get(), w1->GetChildById(111)); | 264 EXPECT_EQ(w111.get(), w1->GetChildById(111)); |
265 } | 265 } |
266 | 266 |
267 // Make sure that Window::Contains correctly handles children, grandchildren, | 267 // Make sure that Window::Contains correctly handles children, grandchildren, |
268 // and not containing NULL or parents. | 268 // and not containing NULL or parents. |
269 TEST_F(WindowTest, Contains) { | 269 TEST_F(WindowTest, Contains) { |
270 Window parent(NULL); | 270 Window parent(NULL); |
271 parent.Init(ui::LAYER_NOT_DRAWN); | 271 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
272 Window child1(NULL); | 272 Window child1(NULL); |
273 child1.Init(ui::LAYER_NOT_DRAWN); | 273 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
274 Window child2(NULL); | 274 Window child2(NULL); |
275 child2.Init(ui::LAYER_NOT_DRAWN); | 275 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
276 | 276 |
277 parent.AddChild(&child1); | 277 parent.AddChild(&child1); |
278 child1.AddChild(&child2); | 278 child1.AddChild(&child2); |
279 | 279 |
280 EXPECT_TRUE(parent.Contains(&parent)); | 280 EXPECT_TRUE(parent.Contains(&parent)); |
281 EXPECT_TRUE(parent.Contains(&child1)); | 281 EXPECT_TRUE(parent.Contains(&child1)); |
282 EXPECT_TRUE(parent.Contains(&child2)); | 282 EXPECT_TRUE(parent.Contains(&child2)); |
283 | 283 |
284 EXPECT_FALSE(parent.Contains(NULL)); | 284 EXPECT_FALSE(parent.Contains(NULL)); |
285 EXPECT_FALSE(child1.Contains(&parent)); | 285 EXPECT_FALSE(child1.Contains(&parent)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 EXPECT_TRUE(dispatcher()->host()->QueryMouseLocation(&mouse_location)); | 466 EXPECT_TRUE(dispatcher()->host()->QueryMouseLocation(&mouse_location)); |
467 EXPECT_EQ("169,80", mouse_location.ToString()); | 467 EXPECT_EQ("169,80", mouse_location.ToString()); |
468 #endif | 468 #endif |
469 EXPECT_EQ("20,53", | 469 EXPECT_EQ("20,53", |
470 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 470 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
471 } | 471 } |
472 | 472 |
473 TEST_F(WindowTest, HitTest) { | 473 TEST_F(WindowTest, HitTest) { |
474 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 474 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
475 w1.set_id(1); | 475 w1.set_id(1); |
476 w1.Init(ui::LAYER_TEXTURED); | 476 w1.Init(aura::WINDOW_LAYER_TEXTURED); |
477 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 477 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
478 w1.Show(); | 478 w1.Show(); |
479 ParentWindow(&w1); | 479 ParentWindow(&w1); |
480 | 480 |
481 // Points are in the Window's coordinates. | 481 // Points are in the Window's coordinates. |
482 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); | 482 EXPECT_TRUE(w1.HitTest(gfx::Point(1, 1))); |
483 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); | 483 EXPECT_FALSE(w1.HitTest(gfx::Point(-1, -1))); |
484 | 484 |
485 // We can expand the bounds slightly to track events outside our border. | 485 // We can expand the bounds slightly to track events outside our border. |
486 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), | 486 w1.SetHitTestBoundsOverrideOuter(gfx::Insets(-1, -1, -1, -1), |
(...skipping 11 matching lines...) Expand all Loading... |
498 ui::ET_TOUCH_RELEASED, gfx::Point(50, 50), 0, getTime()); | 498 ui::ET_TOUCH_RELEASED, gfx::Point(50, 50), 0, getTime()); |
499 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&released); | 499 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&released); |
500 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); | 500 EXPECT_FALSE(w1.HitTest(gfx::Point(-2, -2))); |
501 | 501 |
502 // TODO(beng): clip Window to parent. | 502 // TODO(beng): clip Window to parent. |
503 } | 503 } |
504 | 504 |
505 TEST_F(WindowTest, HitTestMask) { | 505 TEST_F(WindowTest, HitTestMask) { |
506 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); | 506 MaskedWindowDelegate d1(gfx::Rect(5, 6, 20, 30)); |
507 Window w1(&d1); | 507 Window w1(&d1); |
508 w1.Init(ui::LAYER_NOT_DRAWN); | 508 w1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
509 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 509 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
510 w1.Show(); | 510 w1.Show(); |
511 ParentWindow(&w1); | 511 ParentWindow(&w1); |
512 | 512 |
513 // Points inside the mask. | 513 // Points inside the mask. |
514 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left | 514 EXPECT_TRUE(w1.HitTest(gfx::Point(5, 6))); // top-left |
515 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center | 515 EXPECT_TRUE(w1.HitTest(gfx::Point(15, 21))); // center |
516 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right | 516 EXPECT_TRUE(w1.HitTest(gfx::Point(24, 35))); // bottom-right |
517 | 517 |
518 // Points outside the mask. | 518 // Points outside the mask. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 bool called_; | 652 bool called_; |
653 | 653 |
654 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); | 654 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); |
655 }; | 655 }; |
656 | 656 |
657 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { | 657 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { |
658 AddedToRootWindowObserver parent_observer; | 658 AddedToRootWindowObserver parent_observer; |
659 AddedToRootWindowObserver child_observer; | 659 AddedToRootWindowObserver child_observer; |
660 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); | 660 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, root_window())); |
661 scoped_ptr<Window> child_window(new Window(NULL)); | 661 scoped_ptr<Window> child_window(new Window(NULL)); |
662 child_window->Init(ui::LAYER_TEXTURED); | 662 child_window->Init(aura::WINDOW_LAYER_TEXTURED); |
663 child_window->Show(); | 663 child_window->Show(); |
664 | 664 |
665 parent_window->AddObserver(&parent_observer); | 665 parent_window->AddObserver(&parent_observer); |
666 child_window->AddObserver(&child_observer); | 666 child_window->AddObserver(&child_observer); |
667 | 667 |
668 parent_window->AddChild(child_window.get()); | 668 parent_window->AddChild(child_window.get()); |
669 | 669 |
670 EXPECT_FALSE(parent_observer.called()); | 670 EXPECT_FALSE(parent_observer.called()); |
671 EXPECT_TRUE(child_observer.called()); | 671 EXPECT_TRUE(child_observer.called()); |
672 | 672 |
(...skipping 28 matching lines...) Expand all Loading... |
701 root_window())); | 701 root_window())); |
702 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, | 702 scoped_ptr<Window> child(CreateTestWindowWithDelegate(&child_delegate, 0, |
703 gfx::Rect(), parent.get())); | 703 gfx::Rect(), parent.get())); |
704 child_delegate.set_window(child.get()); | 704 child_delegate.set_window(child.get()); |
705 } | 705 } |
706 } | 706 } |
707 | 707 |
708 // Make sure StackChildAtTop moves both the window and layer to the front. | 708 // Make sure StackChildAtTop moves both the window and layer to the front. |
709 TEST_F(WindowTest, StackChildAtTop) { | 709 TEST_F(WindowTest, StackChildAtTop) { |
710 Window parent(NULL); | 710 Window parent(NULL); |
711 parent.Init(ui::LAYER_NOT_DRAWN); | 711 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
712 Window child1(NULL); | 712 Window child1(NULL); |
713 child1.Init(ui::LAYER_NOT_DRAWN); | 713 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
714 Window child2(NULL); | 714 Window child2(NULL); |
715 child2.Init(ui::LAYER_NOT_DRAWN); | 715 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
716 | 716 |
717 parent.AddChild(&child1); | 717 parent.AddChild(&child1); |
718 parent.AddChild(&child2); | 718 parent.AddChild(&child2); |
719 ASSERT_EQ(2u, parent.children().size()); | 719 ASSERT_EQ(2u, parent.children().size()); |
720 EXPECT_EQ(&child1, parent.children()[0]); | 720 EXPECT_EQ(&child1, parent.children()[0]); |
721 EXPECT_EQ(&child2, parent.children()[1]); | 721 EXPECT_EQ(&child2, parent.children()[1]); |
722 ASSERT_EQ(2u, parent.layer()->children().size()); | 722 ASSERT_EQ(2u, parent.layer()->children().size()); |
723 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); | 723 EXPECT_EQ(child1.layer(), parent.layer()->children()[0]); |
724 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); | 724 EXPECT_EQ(child2.layer(), parent.layer()->children()[1]); |
725 | 725 |
726 parent.StackChildAtTop(&child1); | 726 parent.StackChildAtTop(&child1); |
727 ASSERT_EQ(2u, parent.children().size()); | 727 ASSERT_EQ(2u, parent.children().size()); |
728 EXPECT_EQ(&child1, parent.children()[1]); | 728 EXPECT_EQ(&child1, parent.children()[1]); |
729 EXPECT_EQ(&child2, parent.children()[0]); | 729 EXPECT_EQ(&child2, parent.children()[0]); |
730 ASSERT_EQ(2u, parent.layer()->children().size()); | 730 ASSERT_EQ(2u, parent.layer()->children().size()); |
731 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); | 731 EXPECT_EQ(child1.layer(), parent.layer()->children()[1]); |
732 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); | 732 EXPECT_EQ(child2.layer(), parent.layer()->children()[0]); |
733 } | 733 } |
734 | 734 |
735 // Make sure StackChildBelow works. | 735 // Make sure StackChildBelow works. |
736 TEST_F(WindowTest, StackChildBelow) { | 736 TEST_F(WindowTest, StackChildBelow) { |
737 Window parent(NULL); | 737 Window parent(NULL); |
738 parent.Init(ui::LAYER_NOT_DRAWN); | 738 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
739 Window child1(NULL); | 739 Window child1(NULL); |
740 child1.Init(ui::LAYER_NOT_DRAWN); | 740 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
741 child1.set_id(1); | 741 child1.set_id(1); |
742 Window child2(NULL); | 742 Window child2(NULL); |
743 child2.Init(ui::LAYER_NOT_DRAWN); | 743 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
744 child2.set_id(2); | 744 child2.set_id(2); |
745 Window child3(NULL); | 745 Window child3(NULL); |
746 child3.Init(ui::LAYER_NOT_DRAWN); | 746 child3.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
747 child3.set_id(3); | 747 child3.set_id(3); |
748 | 748 |
749 parent.AddChild(&child1); | 749 parent.AddChild(&child1); |
750 parent.AddChild(&child2); | 750 parent.AddChild(&child2); |
751 parent.AddChild(&child3); | 751 parent.AddChild(&child3); |
752 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 752 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
753 | 753 |
754 parent.StackChildBelow(&child1, &child2); | 754 parent.StackChildBelow(&child1, &child2); |
755 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); | 755 EXPECT_EQ("1 2 3", ChildWindowIDsAsString(&parent)); |
756 | 756 |
757 parent.StackChildBelow(&child2, &child1); | 757 parent.StackChildBelow(&child2, &child1); |
758 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); | 758 EXPECT_EQ("2 1 3", ChildWindowIDsAsString(&parent)); |
759 | 759 |
760 parent.StackChildBelow(&child3, &child2); | 760 parent.StackChildBelow(&child3, &child2); |
761 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); | 761 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(&parent)); |
762 | 762 |
763 parent.StackChildBelow(&child3, &child1); | 763 parent.StackChildBelow(&child3, &child1); |
764 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); | 764 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(&parent)); |
765 } | 765 } |
766 | 766 |
767 // Various assertions for StackChildAbove. | 767 // Various assertions for StackChildAbove. |
768 TEST_F(WindowTest, StackChildAbove) { | 768 TEST_F(WindowTest, StackChildAbove) { |
769 Window parent(NULL); | 769 Window parent(NULL); |
770 parent.Init(ui::LAYER_NOT_DRAWN); | 770 parent.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
771 Window child1(NULL); | 771 Window child1(NULL); |
772 child1.Init(ui::LAYER_NOT_DRAWN); | 772 child1.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
773 Window child2(NULL); | 773 Window child2(NULL); |
774 child2.Init(ui::LAYER_NOT_DRAWN); | 774 child2.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
775 Window child3(NULL); | 775 Window child3(NULL); |
776 child3.Init(ui::LAYER_NOT_DRAWN); | 776 child3.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
777 | 777 |
778 parent.AddChild(&child1); | 778 parent.AddChild(&child1); |
779 parent.AddChild(&child2); | 779 parent.AddChild(&child2); |
780 | 780 |
781 // Move 1 in front of 2. | 781 // Move 1 in front of 2. |
782 parent.StackChildAbove(&child1, &child2); | 782 parent.StackChildAbove(&child1, &child2); |
783 ASSERT_EQ(2u, parent.children().size()); | 783 ASSERT_EQ(2u, parent.children().size()); |
784 EXPECT_EQ(&child2, parent.children()[0]); | 784 EXPECT_EQ(&child2, parent.children()[0]); |
785 EXPECT_EQ(&child1, parent.children()[1]); | 785 EXPECT_EQ(&child1, parent.children()[1]); |
786 ASSERT_EQ(2u, parent.layer()->children().size()); | 786 ASSERT_EQ(2u, parent.layer()->children().size()); |
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 EXPECT_TRUE(window1_layer->delegate() == NULL); | 1944 EXPECT_TRUE(window1_layer->delegate() == NULL); |
1945 EXPECT_EQ(1U, parent->children().size()); | 1945 EXPECT_EQ(1U, parent->children().size()); |
1946 } | 1946 } |
1947 | 1947 |
1948 // Make sure that properties which should persist from the old layer to the new | 1948 // Make sure that properties which should persist from the old layer to the new |
1949 // layer actually do. | 1949 // layer actually do. |
1950 TEST_F(WindowTest, RecreateLayer) { | 1950 TEST_F(WindowTest, RecreateLayer) { |
1951 // Set properties to non default values. | 1951 // Set properties to non default values. |
1952 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); | 1952 Window w(new ColorTestWindowDelegate(SK_ColorWHITE)); |
1953 w.set_id(1); | 1953 w.set_id(1); |
1954 w.Init(ui::LAYER_SOLID_COLOR); | 1954 w.Init(aura::WINDOW_LAYER_SOLID_COLOR); |
1955 w.SetBounds(gfx::Rect(0, 0, 100, 100)); | 1955 w.SetBounds(gfx::Rect(0, 0, 100, 100)); |
1956 | 1956 |
1957 ui::Layer* layer = w.layer(); | 1957 ui::Layer* layer = w.layer(); |
1958 layer->set_scale_content(false); | 1958 layer->set_scale_content(false); |
1959 layer->SetVisible(false); | 1959 layer->SetVisible(false); |
1960 layer->SetMasksToBounds(true); | 1960 layer->SetMasksToBounds(true); |
1961 | 1961 |
1962 ui::Layer child_layer; | 1962 ui::Layer child_layer; |
1963 layer->Add(&child_layer); | 1963 layer->Add(&child_layer); |
1964 | 1964 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 int removed_count_; | 2183 int removed_count_; |
2184 | 2184 |
2185 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); | 2185 DISALLOW_COPY_AND_ASSIGN(RootWindowAttachmentObserver); |
2186 }; | 2186 }; |
2187 | 2187 |
2188 TEST_F(WindowTest, RootWindowAttachment) { | 2188 TEST_F(WindowTest, RootWindowAttachment) { |
2189 RootWindowAttachmentObserver observer; | 2189 RootWindowAttachmentObserver observer; |
2190 | 2190 |
2191 // Test a direct add/remove from the RootWindow. | 2191 // Test a direct add/remove from the RootWindow. |
2192 scoped_ptr<Window> w1(new Window(NULL)); | 2192 scoped_ptr<Window> w1(new Window(NULL)); |
2193 w1->Init(ui::LAYER_NOT_DRAWN); | 2193 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2194 w1->AddObserver(&observer); | 2194 w1->AddObserver(&observer); |
2195 | 2195 |
2196 ParentWindow(w1.get()); | 2196 ParentWindow(w1.get()); |
2197 EXPECT_EQ(1, observer.added_count()); | 2197 EXPECT_EQ(1, observer.added_count()); |
2198 EXPECT_EQ(0, observer.removed_count()); | 2198 EXPECT_EQ(0, observer.removed_count()); |
2199 | 2199 |
2200 w1.reset(); | 2200 w1.reset(); |
2201 EXPECT_EQ(1, observer.added_count()); | 2201 EXPECT_EQ(1, observer.added_count()); |
2202 EXPECT_EQ(1, observer.removed_count()); | 2202 EXPECT_EQ(1, observer.removed_count()); |
2203 | 2203 |
2204 observer.Clear(); | 2204 observer.Clear(); |
2205 | 2205 |
2206 // Test an indirect add/remove from the RootWindow. | 2206 // Test an indirect add/remove from the RootWindow. |
2207 w1.reset(new Window(NULL)); | 2207 w1.reset(new Window(NULL)); |
2208 w1->Init(ui::LAYER_NOT_DRAWN); | 2208 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2209 Window* w11 = new Window(NULL); | 2209 Window* w11 = new Window(NULL); |
2210 w11->Init(ui::LAYER_NOT_DRAWN); | 2210 w11->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2211 w11->AddObserver(&observer); | 2211 w11->AddObserver(&observer); |
2212 w1->AddChild(w11); | 2212 w1->AddChild(w11); |
2213 EXPECT_EQ(0, observer.added_count()); | 2213 EXPECT_EQ(0, observer.added_count()); |
2214 EXPECT_EQ(0, observer.removed_count()); | 2214 EXPECT_EQ(0, observer.removed_count()); |
2215 | 2215 |
2216 ParentWindow(w1.get()); | 2216 ParentWindow(w1.get()); |
2217 EXPECT_EQ(1, observer.added_count()); | 2217 EXPECT_EQ(1, observer.added_count()); |
2218 EXPECT_EQ(0, observer.removed_count()); | 2218 EXPECT_EQ(0, observer.removed_count()); |
2219 | 2219 |
2220 w1.reset(); // Deletes w11. | 2220 w1.reset(); // Deletes w11. |
2221 w11 = NULL; | 2221 w11 = NULL; |
2222 EXPECT_EQ(1, observer.added_count()); | 2222 EXPECT_EQ(1, observer.added_count()); |
2223 EXPECT_EQ(1, observer.removed_count()); | 2223 EXPECT_EQ(1, observer.removed_count()); |
2224 | 2224 |
2225 observer.Clear(); | 2225 observer.Clear(); |
2226 | 2226 |
2227 // Test an indirect add/remove with nested observers. | 2227 // Test an indirect add/remove with nested observers. |
2228 w1.reset(new Window(NULL)); | 2228 w1.reset(new Window(NULL)); |
2229 w1->Init(ui::LAYER_NOT_DRAWN); | 2229 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2230 w11 = new Window(NULL); | 2230 w11 = new Window(NULL); |
2231 w11->Init(ui::LAYER_NOT_DRAWN); | 2231 w11->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2232 w11->AddObserver(&observer); | 2232 w11->AddObserver(&observer); |
2233 w1->AddChild(w11); | 2233 w1->AddChild(w11); |
2234 Window* w111 = new Window(NULL); | 2234 Window* w111 = new Window(NULL); |
2235 w111->Init(ui::LAYER_NOT_DRAWN); | 2235 w111->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2236 w111->AddObserver(&observer); | 2236 w111->AddObserver(&observer); |
2237 w11->AddChild(w111); | 2237 w11->AddChild(w111); |
2238 | 2238 |
2239 EXPECT_EQ(0, observer.added_count()); | 2239 EXPECT_EQ(0, observer.added_count()); |
2240 EXPECT_EQ(0, observer.removed_count()); | 2240 EXPECT_EQ(0, observer.removed_count()); |
2241 | 2241 |
2242 ParentWindow(w1.get()); | 2242 ParentWindow(w1.get()); |
2243 EXPECT_EQ(2, observer.added_count()); | 2243 EXPECT_EQ(2, observer.added_count()); |
2244 EXPECT_EQ(0, observer.removed_count()); | 2244 EXPECT_EQ(0, observer.removed_count()); |
2245 | 2245 |
2246 w1.reset(); // Deletes w11 and w111. | 2246 w1.reset(); // Deletes w11 and w111. |
2247 w11 = NULL; | 2247 w11 = NULL; |
2248 w111 = NULL; | 2248 w111 = NULL; |
2249 EXPECT_EQ(2, observer.added_count()); | 2249 EXPECT_EQ(2, observer.added_count()); |
2250 EXPECT_EQ(2, observer.removed_count()); | 2250 EXPECT_EQ(2, observer.removed_count()); |
2251 } | 2251 } |
2252 | 2252 |
2253 TEST_F(WindowTest, OwnedByParentFalse) { | 2253 TEST_F(WindowTest, OwnedByParentFalse) { |
2254 // By default, a window is owned by its parent. If this is set to false, the | 2254 // By default, a window is owned by its parent. If this is set to false, the |
2255 // window will not be destroyed when its parent is. | 2255 // window will not be destroyed when its parent is. |
2256 | 2256 |
2257 scoped_ptr<Window> w1(new Window(NULL)); | 2257 scoped_ptr<Window> w1(new Window(NULL)); |
2258 w1->Init(ui::LAYER_NOT_DRAWN); | 2258 w1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2259 scoped_ptr<Window> w2(new Window(NULL)); | 2259 scoped_ptr<Window> w2(new Window(NULL)); |
2260 w2->set_owned_by_parent(false); | 2260 w2->set_owned_by_parent(false); |
2261 w2->Init(ui::LAYER_NOT_DRAWN); | 2261 w2->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2262 w1->AddChild(w2.get()); | 2262 w1->AddChild(w2.get()); |
2263 | 2263 |
2264 w1.reset(); | 2264 w1.reset(); |
2265 | 2265 |
2266 // We should be able to deref w2 still, but its parent should now be NULL. | 2266 // We should be able to deref w2 still, but its parent should now be NULL. |
2267 EXPECT_EQ(NULL, w2->parent()); | 2267 EXPECT_EQ(NULL, w2->parent()); |
2268 } | 2268 } |
2269 | 2269 |
2270 namespace { | 2270 namespace { |
2271 | 2271 |
(...skipping 19 matching lines...) Expand all Loading... |
2291 | 2291 |
2292 } // namespace | 2292 } // namespace |
2293 | 2293 |
2294 // Creates a window with two child windows. When the first child window is | 2294 // Creates a window with two child windows. When the first child window is |
2295 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. | 2295 // destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child. |
2296 // This synthesizes BrowserView and the status bubble. Both are children of the | 2296 // This synthesizes BrowserView and the status bubble. Both are children of the |
2297 // same parent and destroying BrowserView triggers it destroying the status | 2297 // same parent and destroying BrowserView triggers it destroying the status |
2298 // bubble. | 2298 // bubble. |
2299 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { | 2299 TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) { |
2300 scoped_ptr<Window> parent(new Window(NULL)); | 2300 scoped_ptr<Window> parent(new Window(NULL)); |
2301 parent->Init(ui::LAYER_NOT_DRAWN); | 2301 parent->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2302 OwningWindowDelegate delegate; | 2302 OwningWindowDelegate delegate; |
2303 Window* c1 = new Window(&delegate); | 2303 Window* c1 = new Window(&delegate); |
2304 c1->Init(ui::LAYER_NOT_DRAWN); | 2304 c1->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2305 parent->AddChild(c1); | 2305 parent->AddChild(c1); |
2306 Window* c2 = new Window(NULL); | 2306 Window* c2 = new Window(NULL); |
2307 c2->Init(ui::LAYER_NOT_DRAWN); | 2307 c2->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2308 parent->AddChild(c2); | 2308 parent->AddChild(c2); |
2309 delegate.SetOwnedWindow(c2); | 2309 delegate.SetOwnedWindow(c2); |
2310 parent.reset(); | 2310 parent.reset(); |
2311 } | 2311 } |
2312 | 2312 |
2313 namespace { | 2313 namespace { |
2314 | 2314 |
2315 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is | 2315 // Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is |
2316 // invoked. | 2316 // invoked. |
2317 class BoundsChangeDelegate : public TestWindowDelegate { | 2317 class BoundsChangeDelegate : public TestWindowDelegate { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2674 w1.reset(); | 2674 w1.reset(); |
2675 w2.reset(); | 2675 w2.reset(); |
2676 } | 2676 } |
2677 | 2677 |
2678 } | 2678 } |
2679 | 2679 |
2680 // Verifies SchedulePaint() on a layerless window results in damaging the right | 2680 // Verifies SchedulePaint() on a layerless window results in damaging the right |
2681 // thing. | 2681 // thing. |
2682 TEST_F(WindowTest, LayerlessWindowSchedulePaint) { | 2682 TEST_F(WindowTest, LayerlessWindowSchedulePaint) { |
2683 Window root(NULL); | 2683 Window root(NULL); |
2684 root.Init(ui::LAYER_NOT_DRAWN); | 2684 root.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
2685 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2685 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2686 | 2686 |
2687 Window* layerless_window = new Window(NULL); // Owned by |root|. | 2687 Window* layerless_window = new Window(NULL); // Owned by |root|. |
2688 layerless_window->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2688 layerless_window->Init(WINDOW_LAYER_NONE); |
2689 layerless_window->SetBounds(gfx::Rect(10, 11, 12, 13)); | 2689 layerless_window->SetBounds(gfx::Rect(10, 11, 12, 13)); |
2690 root.AddChild(layerless_window); | 2690 root.AddChild(layerless_window); |
2691 | 2691 |
2692 root.layer()->SendDamagedRects(); | 2692 root.layer()->SendDamagedRects(); |
2693 layerless_window->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); | 2693 layerless_window->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); |
2694 // Note the the region is clipped by the parent hence 100 going to 11. | 2694 // Note the the region is clipped by the parent hence 100 going to 11. |
2695 EXPECT_EQ("11,13 11x4", | 2695 EXPECT_EQ("11,13 11x4", |
2696 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). | 2696 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). |
2697 ToString()); | 2697 ToString()); |
2698 | 2698 |
2699 Window* layerless_window2 = new Window(NULL); // Owned by |layerless_window|. | 2699 Window* layerless_window2 = new Window(NULL); // Owned by |layerless_window|. |
2700 layerless_window2->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2700 layerless_window2->Init(WINDOW_LAYER_NONE); |
2701 layerless_window2->SetBounds(gfx::Rect(1, 2, 3, 4)); | 2701 layerless_window2->SetBounds(gfx::Rect(1, 2, 3, 4)); |
2702 layerless_window->AddChild(layerless_window2); | 2702 layerless_window->AddChild(layerless_window2); |
2703 | 2703 |
2704 root.layer()->SendDamagedRects(); | 2704 root.layer()->SendDamagedRects(); |
2705 layerless_window2->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); | 2705 layerless_window2->SchedulePaintInRect(gfx::Rect(1, 2, 100, 4)); |
2706 // Note the the region is clipped by the |layerless_window| hence 100 going to | 2706 // Note the the region is clipped by the |layerless_window| hence 100 going to |
2707 // 2. | 2707 // 2. |
2708 EXPECT_EQ("12,15 2x2", | 2708 EXPECT_EQ("12,15 2x2", |
2709 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). | 2709 gfx::SkIRectToRect(root.layer()->damaged_region().getBounds()). |
2710 ToString()); | 2710 ToString()); |
2711 } | 2711 } |
2712 | 2712 |
2713 // Verifies bounds of layerless windows are correctly updated when adding | 2713 // Verifies bounds of layerless windows are correctly updated when adding |
2714 // removing. | 2714 // removing. |
2715 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnAddRemove) { | 2715 TEST_F(WindowTest, NestedLayerlessWindowsBoundsOnAddRemove) { |
2716 // Creates the following structure (all children owned by root): | 2716 // Creates the following structure (all children owned by root): |
2717 // root | 2717 // root |
2718 // w1ll 1,2 | 2718 // w1ll 1,2 |
2719 // w11ll 3,4 | 2719 // w11ll 3,4 |
2720 // w111 5,6 | 2720 // w111 5,6 |
2721 // w12 7,8 | 2721 // w12 7,8 |
2722 // w121 9,10 | 2722 // w121 9,10 |
2723 // | 2723 // |
2724 // ll: layer less, eg no layer | 2724 // ll: layer less, eg no layer |
2725 Window root(NULL); | 2725 Window root(NULL); |
2726 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2726 root.Init(WINDOW_LAYER_NOT_DRAWN); |
2727 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2727 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2728 | 2728 |
2729 Window* w1ll = new Window(NULL); | 2729 Window* w1ll = new Window(NULL); |
2730 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2730 w1ll->Init(WINDOW_LAYER_NONE); |
2731 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | 2731 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); |
2732 | 2732 |
2733 Window* w11ll = new Window(NULL); | 2733 Window* w11ll = new Window(NULL); |
2734 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2734 w11ll->Init(WINDOW_LAYER_NONE); |
2735 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | 2735 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); |
2736 w1ll->AddChild(w11ll); | 2736 w1ll->AddChild(w11ll); |
2737 | 2737 |
2738 Window* w111 = new Window(NULL); | 2738 Window* w111 = new Window(NULL); |
2739 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2739 w111->Init(WINDOW_LAYER_NOT_DRAWN); |
2740 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | 2740 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
2741 w11ll->AddChild(w111); | 2741 w11ll->AddChild(w111); |
2742 | 2742 |
2743 Window* w12 = new Window(NULL); | 2743 Window* w12 = new Window(NULL); |
2744 w12->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2744 w12->Init(WINDOW_LAYER_NOT_DRAWN); |
2745 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | 2745 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); |
2746 w1ll->AddChild(w12); | 2746 w1ll->AddChild(w12); |
2747 | 2747 |
2748 Window* w121 = new Window(NULL); | 2748 Window* w121 = new Window(NULL); |
2749 w121->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2749 w121->Init(WINDOW_LAYER_NOT_DRAWN); |
2750 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | 2750 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); |
2751 w12->AddChild(w121); | 2751 w12->AddChild(w121); |
2752 | 2752 |
2753 root.AddChild(w1ll); | 2753 root.AddChild(w1ll); |
2754 | 2754 |
2755 // All layers should be parented to the root. | 2755 // All layers should be parented to the root. |
2756 EXPECT_EQ(root.layer(), w111->layer()->parent()); | 2756 EXPECT_EQ(root.layer(), w111->layer()->parent()); |
2757 EXPECT_EQ(root.layer(), w12->layer()->parent()); | 2757 EXPECT_EQ(root.layer(), w12->layer()->parent()); |
2758 EXPECT_EQ(w12->layer(), w121->layer()->parent()); | 2758 EXPECT_EQ(w12->layer(), w121->layer()->parent()); |
2759 | 2759 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2796 // Creates the following structure (all children owned by root): | 2796 // Creates the following structure (all children owned by root): |
2797 // root | 2797 // root |
2798 // w1ll 1,2 | 2798 // w1ll 1,2 |
2799 // w11ll 3,4 | 2799 // w11ll 3,4 |
2800 // w111 5,6 | 2800 // w111 5,6 |
2801 // w12 7,8 | 2801 // w12 7,8 |
2802 // w121 9,10 | 2802 // w121 9,10 |
2803 // | 2803 // |
2804 // ll: layer less, eg no layer | 2804 // ll: layer less, eg no layer |
2805 Window root(NULL); | 2805 Window root(NULL); |
2806 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2806 root.Init(WINDOW_LAYER_NOT_DRAWN); |
2807 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2807 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2808 | 2808 |
2809 Window* w1ll = new Window(NULL); | 2809 Window* w1ll = new Window(NULL); |
2810 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2810 w1ll->Init(WINDOW_LAYER_NONE); |
2811 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | 2811 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); |
2812 | 2812 |
2813 Window* w11ll = new Window(NULL); | 2813 Window* w11ll = new Window(NULL); |
2814 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2814 w11ll->Init(WINDOW_LAYER_NONE); |
2815 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | 2815 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); |
2816 w1ll->AddChild(w11ll); | 2816 w1ll->AddChild(w11ll); |
2817 | 2817 |
2818 Window* w111 = new Window(NULL); | 2818 Window* w111 = new Window(NULL); |
2819 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2819 w111->Init(WINDOW_LAYER_NOT_DRAWN); |
2820 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | 2820 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
2821 w11ll->AddChild(w111); | 2821 w11ll->AddChild(w111); |
2822 | 2822 |
2823 Window* w12 = new Window(NULL); | 2823 Window* w12 = new Window(NULL); |
2824 w12->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2824 w12->Init(WINDOW_LAYER_NOT_DRAWN); |
2825 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | 2825 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); |
2826 w1ll->AddChild(w12); | 2826 w1ll->AddChild(w12); |
2827 | 2827 |
2828 Window* w121 = new Window(NULL); | 2828 Window* w121 = new Window(NULL); |
2829 w121->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2829 w121->Init(WINDOW_LAYER_NOT_DRAWN); |
2830 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | 2830 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); |
2831 w12->AddChild(w121); | 2831 w12->AddChild(w121); |
2832 | 2832 |
2833 root.AddChild(w1ll); | 2833 root.AddChild(w1ll); |
2834 | 2834 |
2835 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); | 2835 w111->SetBounds(gfx::Rect(7, 8, 11, 12)); |
2836 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); | 2836 EXPECT_EQ("7,8 11x12", w111->bounds().ToString()); |
2837 EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString()); | 2837 EXPECT_EQ("7,8 11x12", w111->GetTargetBounds().ToString()); |
2838 EXPECT_EQ("11,14 11x12", w111->layer()->bounds().ToString()); | 2838 EXPECT_EQ("11,14 11x12", w111->layer()->bounds().ToString()); |
2839 | 2839 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2910 // w1ll 1,2 40x50 | 2910 // w1ll 1,2 40x50 |
2911 // w11ll 3,4 11x12 | 2911 // w11ll 3,4 11x12 |
2912 // w111 5,6 | 2912 // w111 5,6 |
2913 // | 2913 // |
2914 // ll: layer less, eg no layer | 2914 // ll: layer less, eg no layer |
2915 PaintWindowDelegate w1ll_delegate; | 2915 PaintWindowDelegate w1ll_delegate; |
2916 PaintWindowDelegate w11ll_delegate; | 2916 PaintWindowDelegate w11ll_delegate; |
2917 PaintWindowDelegate w111_delegate; | 2917 PaintWindowDelegate w111_delegate; |
2918 | 2918 |
2919 Window root(NULL); | 2919 Window root(NULL); |
2920 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2920 root.Init(WINDOW_LAYER_NOT_DRAWN); |
2921 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2921 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2922 | 2922 |
2923 Window* w1ll = new Window(&w1ll_delegate); | 2923 Window* w1ll = new Window(&w1ll_delegate); |
2924 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2924 w1ll->Init(WINDOW_LAYER_NONE); |
2925 w1ll->SetBounds(gfx::Rect(1, 2, 40, 50)); | 2925 w1ll->SetBounds(gfx::Rect(1, 2, 40, 50)); |
2926 w1ll->Show(); | 2926 w1ll->Show(); |
2927 root.AddChild(w1ll); | 2927 root.AddChild(w1ll); |
2928 | 2928 |
2929 Window* w11ll = new Window(&w11ll_delegate); | 2929 Window* w11ll = new Window(&w11ll_delegate); |
2930 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2930 w11ll->Init(WINDOW_LAYER_NONE); |
2931 w11ll->SetBounds(gfx::Rect(3, 4, 11, 12)); | 2931 w11ll->SetBounds(gfx::Rect(3, 4, 11, 12)); |
2932 w11ll->Show(); | 2932 w11ll->Show(); |
2933 w1ll->AddChild(w11ll); | 2933 w1ll->AddChild(w11ll); |
2934 | 2934 |
2935 Window* w111 = new Window(&w111_delegate); | 2935 Window* w111 = new Window(&w111_delegate); |
2936 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2936 w111->Init(WINDOW_LAYER_NOT_DRAWN); |
2937 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | 2937 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
2938 w111->Show(); | 2938 w111->Show(); |
2939 w11ll->AddChild(w111); | 2939 w11ll->AddChild(w111); |
2940 | 2940 |
2941 EXPECT_EQ(0, w1ll_delegate.paint_count()); | 2941 EXPECT_EQ(0, w1ll_delegate.paint_count()); |
2942 EXPECT_EQ(0, w11ll_delegate.paint_count()); | 2942 EXPECT_EQ(0, w11ll_delegate.paint_count()); |
2943 EXPECT_EQ(0, w111_delegate.paint_count()); | 2943 EXPECT_EQ(0, w111_delegate.paint_count()); |
2944 | 2944 |
2945 // Paint the root, this should trigger painting of the two layerless | 2945 // Paint the root, this should trigger painting of the two layerless |
2946 // descendants but not the layered descendant. | 2946 // descendants but not the layered descendant. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2978 // Creates the following structure (all children owned by root): | 2978 // Creates the following structure (all children owned by root): |
2979 // root | 2979 // root |
2980 // w1ll 1,2 | 2980 // w1ll 1,2 |
2981 // w11ll 3,4 | 2981 // w11ll 3,4 |
2982 // w111 5,6 | 2982 // w111 5,6 |
2983 // w12 7,8 | 2983 // w12 7,8 |
2984 // w121 9,10 | 2984 // w121 9,10 |
2985 // | 2985 // |
2986 // ll: layer less, eg no layer | 2986 // ll: layer less, eg no layer |
2987 Window root(NULL); | 2987 Window root(NULL); |
2988 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 2988 root.Init(WINDOW_LAYER_NOT_DRAWN); |
2989 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 2989 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
2990 | 2990 |
2991 Window* w1ll = new Window(NULL); | 2991 Window* w1ll = new Window(NULL); |
2992 w1ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2992 w1ll->Init(WINDOW_LAYER_NONE); |
2993 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); | 2993 w1ll->SetBounds(gfx::Rect(1, 2, 100, 100)); |
2994 | 2994 |
2995 Window* w11ll = new Window(NULL); | 2995 Window* w11ll = new Window(NULL); |
2996 w11ll->InitWithWindowLayerType(WINDOW_LAYER_NONE); | 2996 w11ll->Init(WINDOW_LAYER_NONE); |
2997 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); | 2997 w11ll->SetBounds(gfx::Rect(3, 4, 100, 100)); |
2998 w1ll->AddChild(w11ll); | 2998 w1ll->AddChild(w11ll); |
2999 | 2999 |
3000 Window* w111 = new Window(NULL); | 3000 Window* w111 = new Window(NULL); |
3001 w111->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 3001 w111->Init(WINDOW_LAYER_NOT_DRAWN); |
3002 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); | 3002 w111->SetBounds(gfx::Rect(5, 6, 100, 100)); |
3003 w11ll->AddChild(w111); | 3003 w11ll->AddChild(w111); |
3004 | 3004 |
3005 Window* w12 = new Window(NULL); | 3005 Window* w12 = new Window(NULL); |
3006 w12->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 3006 w12->Init(WINDOW_LAYER_NOT_DRAWN); |
3007 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); | 3007 w12->SetBounds(gfx::Rect(7, 8, 100, 100)); |
3008 w1ll->AddChild(w12); | 3008 w1ll->AddChild(w12); |
3009 | 3009 |
3010 Window* w121 = new Window(NULL); | 3010 Window* w121 = new Window(NULL); |
3011 w121->InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 3011 w121->Init(WINDOW_LAYER_NOT_DRAWN); |
3012 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); | 3012 w121->SetBounds(gfx::Rect(9, 10, 100, 100)); |
3013 w12->AddChild(w121); | 3013 w12->AddChild(w121); |
3014 | 3014 |
3015 root.AddChild(w1ll); | 3015 root.AddChild(w1ll); |
3016 | 3016 |
3017 // w111->w11ll | 3017 // w111->w11ll |
3018 EXPECT_EQ("5,6", ConvertPointToTargetString(w111, w11ll)); | 3018 EXPECT_EQ("5,6", ConvertPointToTargetString(w111, w11ll)); |
3019 | 3019 |
3020 // w111->w1ll | 3020 // w111->w1ll |
3021 EXPECT_EQ("8,10", ConvertPointToTargetString(w111, w1ll)); | 3021 EXPECT_EQ("8,10", ConvertPointToTargetString(w111, w1ll)); |
(...skipping 17 matching lines...) Expand all Loading... |
3039 EXPECT_EQ("4,6", ConvertPointToTargetString(w11ll, &root)); | 3039 EXPECT_EQ("4,6", ConvertPointToTargetString(w11ll, &root)); |
3040 | 3040 |
3041 // w11ll->w12 | 3041 // w11ll->w12 |
3042 EXPECT_EQ("-4,-4", ConvertPointToTargetString(w11ll, w12)); | 3042 EXPECT_EQ("-4,-4", ConvertPointToTargetString(w11ll, w12)); |
3043 } | 3043 } |
3044 | 3044 |
3045 #if !defined(NDEBUG) | 3045 #if !defined(NDEBUG) |
3046 // Verifies PrintWindowHierarchy() doesn't crash with a layerless window. | 3046 // Verifies PrintWindowHierarchy() doesn't crash with a layerless window. |
3047 TEST_F(WindowTest, PrintWindowHierarchyNotCrashLayerless) { | 3047 TEST_F(WindowTest, PrintWindowHierarchyNotCrashLayerless) { |
3048 Window root(NULL); | 3048 Window root(NULL); |
3049 root.InitWithWindowLayerType(WINDOW_LAYER_NONE); | 3049 root.Init(WINDOW_LAYER_NONE); |
3050 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 3050 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
3051 root.PrintWindowHierarchy(0); | 3051 root.PrintWindowHierarchy(0); |
3052 } | 3052 } |
3053 #endif | 3053 #endif |
3054 | 3054 |
3055 namespace { | 3055 namespace { |
3056 | 3056 |
3057 // See AddWindowsFromString() for details. | 3057 // See AddWindowsFromString() for details. |
3058 aura::Window* CreateWindowFromDescription(const std::string& description, | 3058 aura::Window* CreateWindowFromDescription(const std::string& description, |
3059 WindowDelegate* delegate) { | 3059 WindowDelegate* delegate) { |
3060 WindowLayerType window_type = WINDOW_LAYER_NOT_DRAWN; | 3060 WindowLayerType window_type = WINDOW_LAYER_NOT_DRAWN; |
3061 std::vector<std::string> tokens; | 3061 std::vector<std::string> tokens; |
3062 Tokenize(description, ":", &tokens); | 3062 Tokenize(description, ":", &tokens); |
3063 DCHECK(!tokens.empty()); | 3063 DCHECK(!tokens.empty()); |
3064 std::string name(tokens[0]); | 3064 std::string name(tokens[0]); |
3065 tokens.erase(tokens.begin()); | 3065 tokens.erase(tokens.begin()); |
3066 if (!tokens.empty()) { | 3066 if (!tokens.empty()) { |
3067 if (tokens[0] == "ll") { | 3067 if (tokens[0] == "ll") { |
3068 window_type = WINDOW_LAYER_NONE; | 3068 window_type = WINDOW_LAYER_NONE; |
3069 tokens.erase(tokens.begin()); | 3069 tokens.erase(tokens.begin()); |
3070 } | 3070 } |
3071 DCHECK(tokens.empty()) << "unknown tokens for creating window " | 3071 DCHECK(tokens.empty()) << "unknown tokens for creating window " |
3072 << description; | 3072 << description; |
3073 } | 3073 } |
3074 Window* window = new Window(delegate); | 3074 Window* window = new Window(delegate); |
3075 window->InitWithWindowLayerType(window_type); | 3075 window->Init(window_type); |
3076 window->SetName(name); | 3076 window->SetName(name); |
3077 // Window name is only propagated to layer in debug builds. | 3077 // Window name is only propagated to layer in debug builds. |
3078 if (window->layer()) | 3078 if (window->layer()) |
3079 window->layer()->set_name(name); | 3079 window->layer()->set_name(name); |
3080 return window; | 3080 return window; |
3081 } | 3081 } |
3082 | 3082 |
3083 // Creates and adds a tree of windows to |parent|. |description| consists | 3083 // Creates and adds a tree of windows to |parent|. |description| consists |
3084 // of the following pieces: | 3084 // of the following pieces: |
3085 // X: Identifies a new window. Consists of a name and optionally ":ll" to | 3085 // X: Identifies a new window. Consists of a name and optionally ":ll" to |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3295 "1", | 3295 "1", |
3296 "2", | 3296 "2", |
3297 STACK_ABOVE, | 3297 STACK_ABOVE, |
3298 "2 [ 21 ] 1 [ 11 12 ]", | 3298 "2 [ 21 ] 1 [ 11 12 ]", |
3299 "21 11 12", | 3299 "21 11 12", |
3300 }, | 3300 }, |
3301 }; | 3301 }; |
3302 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 3302 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
3303 test::TestWindowDelegate delegate; | 3303 test::TestWindowDelegate delegate; |
3304 Window root(NULL); | 3304 Window root(NULL); |
3305 root.InitWithWindowLayerType(WINDOW_LAYER_NOT_DRAWN); | 3305 root.Init(WINDOW_LAYER_NOT_DRAWN); |
3306 root.SetBounds(gfx::Rect(0, 0, 100, 100)); | 3306 root.SetBounds(gfx::Rect(0, 0, 100, 100)); |
3307 AddWindowsFromString( | 3307 AddWindowsFromString( |
3308 &root, | 3308 &root, |
3309 data[i].initial_description, | 3309 data[i].initial_description, |
3310 static_cast<std::string::size_type>(0), &delegate); | 3310 static_cast<std::string::size_type>(0), &delegate); |
3311 aura::Window* source = FindWindowByName(&root, data[i].source_window); | 3311 aura::Window* source = FindWindowByName(&root, data[i].source_window); |
3312 ASSERT_TRUE(source != NULL) << "unable to find source window " | 3312 ASSERT_TRUE(source != NULL) << "unable to find source window " |
3313 << data[i].source_window << " at " << i; | 3313 << data[i].source_window << " at " << i; |
3314 aura::Window* target = FindWindowByName(&root, data[i].target_window); | 3314 aura::Window* target = FindWindowByName(&root, data[i].target_window); |
3315 switch (data[i].stack_type) { | 3315 switch (data[i].stack_type) { |
(...skipping 18 matching lines...) Expand all Loading... |
3334 BuildRootLayerTreeDescription(*root.layer())) | 3334 BuildRootLayerTreeDescription(*root.layer())) |
3335 << "layer tree doesn't match at " << i; | 3335 << "layer tree doesn't match at " << i; |
3336 EXPECT_EQ(data[i].expected_description, | 3336 EXPECT_EQ(data[i].expected_description, |
3337 BuildRootWindowTreeDescription(root)) | 3337 BuildRootWindowTreeDescription(root)) |
3338 << "window tree doesn't match at " << i; | 3338 << "window tree doesn't match at " << i; |
3339 } | 3339 } |
3340 } | 3340 } |
3341 | 3341 |
3342 } // namespace test | 3342 } // namespace test |
3343 } // namespace aura | 3343 } // namespace aura |
OLD | NEW |