OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/wm/workspace_controller.h" | 5 #include "ash/wm/workspace_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 typedef std::map<const ui::Layer*, std::string> LayerToWindowNameMap; | 63 typedef std::map<const ui::Layer*, std::string> LayerToWindowNameMap; |
64 LayerToWindowNameMap window_names; | 64 LayerToWindowNameMap window_names; |
65 for (size_t i = 0; i < window->children().size(); ++i) { | 65 for (size_t i = 0; i < window->children().size(); ++i) { |
66 window_names[window->children()[i]->layer()] = | 66 window_names[window->children()[i]->layer()] = |
67 window->children()[i]->name(); | 67 window->children()[i]->name(); |
68 } | 68 } |
69 | 69 |
70 std::string result; | 70 std::string result; |
71 const std::vector<ui::Layer*>& layers(window->layer()->children()); | 71 const std::vector<ui::Layer*>& layers(window->layer()->children()); |
72 for (size_t i = 0; i < layers.size(); ++i) { | 72 for (size_t i = 0; i < layers.size(); ++i) { |
73 LayerToWindowNameMap::iterator layer_i = | 73 LayerToWindowNameMap::iterator layer_i = window_names.find(layers[i]); |
74 window_names.find(layers[i]); | |
75 if (layer_i != window_names.end()) { | 74 if (layer_i != window_names.end()) { |
76 if (!result.empty()) | 75 if (!result.empty()) |
77 result += " "; | 76 result += " "; |
78 result += layer_i->second; | 77 result += layer_i->second; |
79 } | 78 } |
80 } | 79 } |
81 return result; | 80 return result; |
82 } | 81 } |
83 | 82 |
84 class WorkspaceControllerTest : public test::AshTestBase { | 83 class WorkspaceControllerTest : public test::AshTestBase { |
(...skipping 29 matching lines...) Expand all Loading... |
114 | 113 |
115 aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) { | 114 aura::Window* CreatePopupLikeWindow(const gfx::Rect& bounds) { |
116 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); | 115 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); |
117 window->Show(); | 116 window->Show(); |
118 return window; | 117 return window; |
119 } | 118 } |
120 | 119 |
121 aura::Window* CreateTestPanel(aura::WindowDelegate* delegate, | 120 aura::Window* CreateTestPanel(aura::WindowDelegate* delegate, |
122 const gfx::Rect& bounds) { | 121 const gfx::Rect& bounds) { |
123 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 122 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
124 delegate, | 123 delegate, ui::wm::WINDOW_TYPE_PANEL, 0, bounds); |
125 ui::wm::WINDOW_TYPE_PANEL, | |
126 0, | |
127 bounds); | |
128 test::TestShelfDelegate* shelf_delegate = | 124 test::TestShelfDelegate* shelf_delegate = |
129 test::TestShelfDelegate::instance(); | 125 test::TestShelfDelegate::instance(); |
130 shelf_delegate->AddShelfItem(window); | 126 shelf_delegate->AddShelfItem(window); |
131 PanelLayoutManager* manager = | 127 PanelLayoutManager* manager = |
132 PanelLayoutManager::Get(WmWindowAura::Get(window)); | 128 PanelLayoutManager::Get(WmWindowAura::Get(window)); |
133 manager->Relayout(); | 129 manager->Relayout(); |
134 return window; | 130 return window; |
135 } | 131 } |
136 | 132 |
137 aura::Window* GetDesktop() { | 133 aura::Window* GetDesktop() { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 223 |
228 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); | 224 w2->SetBounds(gfx::Rect(0, 0, 50, 51)); |
229 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 225 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
230 w2->Show(); | 226 w2->Show(); |
231 wm::ActivateWindow(w2.get()); | 227 wm::ActivateWindow(w2.get()); |
232 | 228 |
233 // Both windows should be in the same workspace. | 229 // Both windows should be in the same workspace. |
234 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); | 230 EXPECT_EQ(w1.get(), GetDesktop()->children()[0]); |
235 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); | 231 EXPECT_EQ(w2.get(), GetDesktop()->children()[1]); |
236 | 232 |
237 gfx::Rect work_area( | 233 gfx::Rect work_area(ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get())); |
238 ScreenUtil::GetMaximizedWindowBoundsInParent(w1.get())); | |
239 EXPECT_EQ(work_area.width(), w2->bounds().width()); | 234 EXPECT_EQ(work_area.width(), w2->bounds().width()); |
240 EXPECT_EQ(work_area.height(), w2->bounds().height()); | 235 EXPECT_EQ(work_area.height(), w2->bounds().height()); |
241 | 236 |
242 // Restore w2, which should then go back to one workspace. | 237 // Restore w2, which should then go back to one workspace. |
243 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 238 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
244 EXPECT_EQ(50, w2->bounds().width()); | 239 EXPECT_EQ(50, w2->bounds().width()); |
245 EXPECT_EQ(51, w2->bounds().height()); | 240 EXPECT_EQ(51, w2->bounds().height()); |
246 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); | 241 EXPECT_TRUE(wm::IsActiveWindow(w2.get())); |
247 } | 242 } |
248 | 243 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 452 |
458 // Create another window, maximized. | 453 // Create another window, maximized. |
459 std::unique_ptr<Window> w2(CreateTestWindow()); | 454 std::unique_ptr<Window> w2(CreateTestWindow()); |
460 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 455 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
461 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 456 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
462 w2->Show(); | 457 w2->Show(); |
463 wm::ActivateWindow(w2.get()); | 458 wm::ActivateWindow(w2.get()); |
464 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 459 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
465 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 460 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
466 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 461 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
467 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent( | 462 EXPECT_EQ( |
468 w2->parent()).ToString(), | 463 ScreenUtil::GetMaximizedWindowBoundsInParent(w2->parent()).ToString(), |
469 w2->bounds().ToString()); | 464 w2->bounds().ToString()); |
470 | 465 |
471 // Switch to w1. | 466 // Switch to w1. |
472 wm::ActivateWindow(w1.get()); | 467 wm::ActivateWindow(w1.get()); |
473 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 468 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
474 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 469 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
475 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent( | 470 EXPECT_EQ( |
476 w2->parent()).ToString(), | 471 ScreenUtil::GetMaximizedWindowBoundsInParent(w2->parent()).ToString(), |
477 w2->bounds().ToString()); | 472 w2->bounds().ToString()); |
478 | 473 |
479 // Switch to w2. | 474 // Switch to w2. |
480 wm::ActivateWindow(w2.get()); | 475 wm::ActivateWindow(w2.get()); |
481 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); | 476 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); |
482 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 477 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
483 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); | 478 EXPECT_EQ("0,1 101x102", w1->bounds().ToString()); |
484 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w2.get()).ToString(), | 479 EXPECT_EQ(ScreenUtil::GetMaximizedWindowBoundsInParent(w2.get()).ToString(), |
485 w2->bounds().ToString()); | 480 w2->bounds().ToString()); |
486 | 481 |
487 // Turn off auto-hide, switch back to w2 (maximized) and verify overlap. | 482 // Turn off auto-hide, switch back to w2 (maximized) and verify overlap. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 TEST_F(WorkspaceControllerTest, TransientParent) { | 694 TEST_F(WorkspaceControllerTest, TransientParent) { |
700 // Normal window with no transient parent. | 695 // Normal window with no transient parent. |
701 std::unique_ptr<Window> w2(CreateTestWindow()); | 696 std::unique_ptr<Window> w2(CreateTestWindow()); |
702 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); | 697 w2->SetBounds(gfx::Rect(10, 11, 250, 251)); |
703 w2->Show(); | 698 w2->Show(); |
704 wm::ActivateWindow(w2.get()); | 699 wm::ActivateWindow(w2.get()); |
705 | 700 |
706 // Window with a transient parent. We set the transient parent to the root, | 701 // Window with a transient parent. We set the transient parent to the root, |
707 // which would never happen but is enough to exercise the bug. | 702 // which would never happen but is enough to exercise the bug. |
708 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); | 703 std::unique_ptr<Window> w1(CreateTestWindowUnparented()); |
709 ::wm::AddTransientChild( | 704 ::wm::AddTransientChild(Shell::GetInstance()->GetPrimaryRootWindow(), |
710 Shell::GetInstance()->GetPrimaryRootWindow(), w1.get()); | 705 w1.get()); |
711 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); | 706 w1->SetBounds(gfx::Rect(10, 11, 250, 251)); |
712 ParentWindowInPrimaryRootWindow(w1.get()); | 707 ParentWindowInPrimaryRootWindow(w1.get()); |
713 w1->Show(); | 708 w1->Show(); |
714 wm::ActivateWindow(w1.get()); | 709 wm::ActivateWindow(w1.get()); |
715 | 710 |
716 // The window with the transient parent should get added to the same parent as | 711 // The window with the transient parent should get added to the same parent as |
717 // the normal window. | 712 // the normal window. |
718 EXPECT_EQ(w2->parent(), w1->parent()); | 713 EXPECT_EQ(w2->parent(), w1->parent()); |
719 } | 714 } |
720 | 715 |
721 // Test the placement of newly created windows. | 716 // Test the placement of newly created windows. |
722 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { | 717 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) { |
723 if (!SupportsHostWindowResize()) | 718 if (!SupportsHostWindowResize()) |
724 return; | 719 return; |
725 UpdateDisplay("1600x1200"); | 720 UpdateDisplay("1600x1200"); |
726 // Creating a popup handler here to make sure it does not interfere with the | 721 // Creating a popup handler here to make sure it does not interfere with the |
727 // existing windows. | 722 // existing windows. |
728 gfx::Rect source_browser_bounds(16, 32, 640, 320); | 723 gfx::Rect source_browser_bounds(16, 32, 640, 320); |
729 std::unique_ptr<aura::Window> browser_window( | 724 std::unique_ptr<aura::Window> browser_window( |
730 CreateBrowserLikeWindow(source_browser_bounds)); | 725 CreateBrowserLikeWindow(source_browser_bounds)); |
731 | 726 |
732 // Creating a popup to make sure it does not interfere with the positioning. | 727 // Creating a popup to make sure it does not interfere with the positioning. |
733 std::unique_ptr<aura::Window> browser_popup( | 728 std::unique_ptr<aura::Window> browser_popup( |
734 CreatePopupLikeWindow(gfx::Rect(16, 32, 128, 256))); | 729 CreatePopupLikeWindow(gfx::Rect(16, 32, 128, 256))); |
735 | 730 |
736 browser_window->Show(); | 731 browser_window->Show(); |
737 browser_popup->Show(); | 732 browser_popup->Show(); |
738 | 733 |
739 { // With a shown window it's size should get returned. | 734 { // With a shown window it's size should get returned. |
740 std::unique_ptr<aura::Window> new_browser_window( | 735 std::unique_ptr<aura::Window> new_browser_window( |
741 CreateBrowserLikeWindow(source_browser_bounds)); | 736 CreateBrowserLikeWindow(source_browser_bounds)); |
742 // The position should be right flush. | 737 // The position should be right flush. |
743 EXPECT_EQ("960,32 640x320", new_browser_window->bounds().ToString()); | 738 EXPECT_EQ("960,32 640x320", new_browser_window->bounds().ToString()); |
744 } | 739 } |
745 | 740 |
746 { // With the window shown - but more on the right side then on the left | 741 { // With the window shown - but more on the right side then on the left |
747 // side (and partially out of the screen), it should default to the other | 742 // side (and partially out of the screen), it should default to the other |
748 // side and inside the screen. | 743 // side and inside the screen. |
749 gfx::Rect source_browser_bounds(gfx::Rect(1000, 600, 640, 320)); | 744 gfx::Rect source_browser_bounds(gfx::Rect(1000, 600, 640, 320)); |
750 browser_window->SetBounds(source_browser_bounds); | 745 browser_window->SetBounds(source_browser_bounds); |
751 | 746 |
752 std::unique_ptr<aura::Window> new_browser_window( | 747 std::unique_ptr<aura::Window> new_browser_window( |
753 CreateBrowserLikeWindow(source_browser_bounds)); | 748 CreateBrowserLikeWindow(source_browser_bounds)); |
754 // The position should be left & bottom flush. | 749 // The position should be left & bottom flush. |
755 EXPECT_EQ("0,600 640x320", new_browser_window->bounds().ToString()); | 750 EXPECT_EQ("0,600 640x320", new_browser_window->bounds().ToString()); |
756 | 751 |
757 // If the other window was already beyond the point to get right flush | 752 // If the other window was already beyond the point to get right flush |
758 // it will remain where it is. | 753 // it will remain where it is. |
759 EXPECT_EQ("1000,600 640x320", browser_window->bounds().ToString()); | 754 EXPECT_EQ("1000,600 640x320", browser_window->bounds().ToString()); |
760 } | 755 } |
761 | 756 |
762 { // Make sure that popups do not get changed. | 757 { // Make sure that popups do not get changed. |
763 std::unique_ptr<aura::Window> new_popup_window( | 758 std::unique_ptr<aura::Window> new_popup_window( |
764 CreatePopupLikeWindow(gfx::Rect(50, 100, 300, 150))); | 759 CreatePopupLikeWindow(gfx::Rect(50, 100, 300, 150))); |
765 EXPECT_EQ("50,100 300x150", new_popup_window->bounds().ToString()); | 760 EXPECT_EQ("50,100 300x150", new_popup_window->bounds().ToString()); |
766 } | 761 } |
767 | 762 |
768 browser_window->Hide(); | 763 browser_window->Hide(); |
769 { // If a window is there but not shown the default should be centered. | 764 { // If a window is there but not shown the default should be centered. |
770 std::unique_ptr<aura::Window> new_browser_window( | 765 std::unique_ptr<aura::Window> new_browser_window( |
771 CreateBrowserLikeWindow(gfx::Rect(50, 100, 300, 150))); | 766 CreateBrowserLikeWindow(gfx::Rect(50, 100, 300, 150))); |
772 EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString()); | 767 EXPECT_EQ("650,100 300x150", new_browser_window->bounds().ToString()); |
773 } | 768 } |
774 } | 769 } |
775 | 770 |
776 // Test that adding a second window shifts both the first window and its | 771 // Test that adding a second window shifts both the first window and its |
777 // transient child. | 772 // transient child. |
778 TEST_F(WorkspaceControllerTest, AutoPlacingMovesTransientChild) { | 773 TEST_F(WorkspaceControllerTest, AutoPlacingMovesTransientChild) { |
779 // Create an auto-positioned window. | 774 // Create an auto-positioned window. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 847 |
853 std::unique_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2)); | 848 std::unique_ptr<aura::Window> window3(CreateTestWindowInShellWithId(2)); |
854 wm::GetWindowState(window3.get())->set_window_position_managed(true); | 849 wm::GetWindowState(window3.get())->set_window_position_managed(true); |
855 // To avoid any auto window manager changes due to SetBounds, the window | 850 // To avoid any auto window manager changes due to SetBounds, the window |
856 // gets first hidden and then shown again. | 851 // gets first hidden and then shown again. |
857 window3->Hide(); | 852 window3->Hide(); |
858 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); | 853 window3->SetBounds(gfx::Rect(32, 48, 256, 512)); |
859 window3->Show(); | 854 window3->Show(); |
860 // |window1| should be flush left and |window3| flush right. | 855 // |window1| should be flush left and |window3| flush right. |
861 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 856 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
862 EXPECT_EQ(base::IntToString( | 857 EXPECT_EQ( |
863 desktop_area.width() - window3->bounds().width()) + | 858 base::IntToString(desktop_area.width() - window3->bounds().width()) + |
864 ",48 256x512", window3->bounds().ToString()); | 859 ",48 256x512", |
| 860 window3->bounds().ToString()); |
865 | 861 |
866 // After removing |window3|, |window1| should be centered again. | 862 // After removing |window3|, |window1| should be centered again. |
867 window3.reset(); | 863 window3.reset(); |
868 EXPECT_EQ( | 864 EXPECT_EQ(base::IntToString( |
869 base::IntToString( | 865 (desktop_area.width() - window1->bounds().width()) / 2) + |
870 (desktop_area.width() - window1->bounds().width()) / 2) + | 866 ",32 640x320", |
871 ",32 640x320", window1->bounds().ToString()); | 867 window1->bounds().ToString()); |
872 | 868 |
873 // Test 3: Set up a manageable and a non manageable window and check | 869 // Test 3: Set up a manageable and a non manageable window and check |
874 // positioning. | 870 // positioning. |
875 std::unique_ptr<aura::Window> window4(CreateTestWindowInShellWithId(3)); | 871 std::unique_ptr<aura::Window> window4(CreateTestWindowInShellWithId(3)); |
876 // To avoid any auto window manager changes due to SetBounds, the window | 872 // To avoid any auto window manager changes due to SetBounds, the window |
877 // gets first hidden and then shown again. | 873 // gets first hidden and then shown again. |
878 window1->Hide(); | 874 window1->Hide(); |
879 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 875 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
880 window4->SetBounds(gfx::Rect(32, 48, 256, 512)); | 876 window4->SetBounds(gfx::Rect(32, 48, 256, 512)); |
881 window1->Show(); | 877 window1->Show(); |
882 // |window1| should be centered and |window4| untouched. | 878 // |window1| should be centered and |window4| untouched. |
883 EXPECT_EQ( | 879 EXPECT_EQ(base::IntToString( |
884 base::IntToString( | 880 (desktop_area.width() - window1->bounds().width()) / 2) + |
885 (desktop_area.width() - window1->bounds().width()) / 2) + | 881 ",32 640x320", |
886 ",32 640x320", window1->bounds().ToString()); | 882 window1->bounds().ToString()); |
887 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); | 883 EXPECT_EQ("32,48 256x512", window4->bounds().ToString()); |
888 | 884 |
889 // Test4: A single manageable window should get centered. | 885 // Test4: A single manageable window should get centered. |
890 window4.reset(); | 886 window4.reset(); |
891 window1_state->set_bounds_changed_by_user(false); | 887 window1_state->set_bounds_changed_by_user(false); |
892 // Trigger the auto window placement function by showing (and hiding) it. | 888 // Trigger the auto window placement function by showing (and hiding) it. |
893 window1->Hide(); | 889 window1->Hide(); |
894 window1->Show(); | 890 window1->Show(); |
895 // |window1| should be centered. | 891 // |window1| should be centered. |
896 EXPECT_EQ( | 892 EXPECT_EQ(base::IntToString( |
897 base::IntToString( | 893 (desktop_area.width() - window1->bounds().width()) / 2) + |
898 (desktop_area.width() - window1->bounds().width()) / 2) + | 894 ",32 640x320", |
899 ",32 640x320", window1->bounds().ToString()); | 895 window1->bounds().ToString()); |
900 } | 896 } |
901 | 897 |
902 // Test the proper usage of user window movement interaction. | 898 // Test the proper usage of user window movement interaction. |
903 TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { | 899 TEST_F(WorkspaceControllerTest, TestUserMovedWindowRepositioning) { |
904 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 900 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
905 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 901 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
906 gfx::Rect desktop_area = window1->parent()->bounds(); | 902 gfx::Rect desktop_area = window1->parent()->bounds(); |
907 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 903 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
908 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 904 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
909 window1->Hide(); | 905 window1->Hide(); |
(...skipping 16 matching lines...) Expand all Loading... |
926 EXPECT_FALSE(window2_state->bounds_changed_by_user()); | 922 EXPECT_FALSE(window2_state->bounds_changed_by_user()); |
927 | 923 |
928 // Turn on the second window and make sure that both windows are now | 924 // Turn on the second window and make sure that both windows are now |
929 // positionable again (user movement cleared). | 925 // positionable again (user movement cleared). |
930 window2->Show(); | 926 window2->Show(); |
931 | 927 |
932 // |window1| should be flush left and |window2| flush right. | 928 // |window1| should be flush left and |window2| flush right. |
933 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 929 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
934 EXPECT_EQ( | 930 EXPECT_EQ( |
935 base::IntToString(desktop_area.width() - window2->bounds().width()) + | 931 base::IntToString(desktop_area.width() - window2->bounds().width()) + |
936 ",48 256x512", window2->bounds().ToString()); | 932 ",48 256x512", |
| 933 window2->bounds().ToString()); |
937 // FLag should now be reset. | 934 // FLag should now be reset. |
938 EXPECT_FALSE(window1_state->bounds_changed_by_user()); | 935 EXPECT_FALSE(window1_state->bounds_changed_by_user()); |
939 EXPECT_FALSE(window2_state->bounds_changed_by_user()); | 936 EXPECT_FALSE(window2_state->bounds_changed_by_user()); |
940 | 937 |
941 // Going back to one shown window should keep the state. | 938 // Going back to one shown window should keep the state. |
942 window1_state->set_bounds_changed_by_user(true); | 939 window1_state->set_bounds_changed_by_user(true); |
943 window2->Hide(); | 940 window2->Hide(); |
944 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); | 941 EXPECT_EQ("0,32 640x320", window1->bounds().ToString()); |
945 EXPECT_TRUE(window1_state->bounds_changed_by_user()); | 942 EXPECT_TRUE(window1_state->bounds_changed_by_user()); |
946 } | 943 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1006 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
1010 window1->Hide(); | 1007 window1->Hide(); |
1011 window2->Hide(); | 1008 window2->Hide(); |
1012 wm::GetWindowState(window1.get())->set_window_position_managed(true); | 1009 wm::GetWindowState(window1.get())->set_window_position_managed(true); |
1013 wm::GetWindowState(window2.get())->set_window_position_managed(true); | 1010 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
1014 window1->Show(); | 1011 window1->Show(); |
1015 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); | 1012 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); |
1016 window2->Show(); | 1013 window2->Show(); |
1017 | 1014 |
1018 // |window1| should be flush left and |window2| flush right. | 1015 // |window1| should be flush left and |window2| flush right. |
1019 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + | 1016 EXPECT_EQ("0," + base::IntToString(user_pos.y()) + " 640x320", |
1020 " 640x320", window1->bounds().ToString()); | 1017 window1->bounds().ToString()); |
1021 EXPECT_EQ( | 1018 EXPECT_EQ( |
1022 base::IntToString(desktop_area.width() - window2->bounds().width()) + | 1019 base::IntToString(desktop_area.width() - window2->bounds().width()) + |
1023 ",48 256x512", window2->bounds().ToString()); | 1020 ",48 256x512", |
| 1021 window2->bounds().ToString()); |
1024 window2->Hide(); | 1022 window2->Hide(); |
1025 | 1023 |
1026 // After the other window get hidden the window has to move back to the | 1024 // After the other window get hidden the window has to move back to the |
1027 // previous position and the bounds should still be set and unchanged. | 1025 // previous position and the bounds should still be set and unchanged. |
1028 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); | 1026 EXPECT_EQ(user_pos.ToString(), window1->bounds().ToString()); |
1029 ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds()); | 1027 ASSERT_TRUE(window1_state->pre_auto_manage_window_bounds()); |
1030 EXPECT_EQ(user_pos.ToString(), | 1028 EXPECT_EQ(user_pos.ToString(), |
1031 window1_state->pre_auto_manage_window_bounds()->ToString()); | 1029 window1_state->pre_auto_manage_window_bounds()->ToString()); |
1032 } | 1030 } |
1033 | 1031 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 window2_state->set_window_position_managed(true); | 1094 window2_state->set_window_position_managed(true); |
1097 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1095 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
1098 | 1096 |
1099 window1_state->Minimize(); | 1097 window1_state->Minimize(); |
1100 | 1098 |
1101 // |window2| should be centered now. | 1099 // |window2| should be centered now. |
1102 EXPECT_TRUE(window2->IsVisible()); | 1100 EXPECT_TRUE(window2->IsVisible()); |
1103 EXPECT_TRUE(window2_state->IsNormalStateType()); | 1101 EXPECT_TRUE(window2_state->IsNormalStateType()); |
1104 EXPECT_EQ(base::IntToString( | 1102 EXPECT_EQ(base::IntToString( |
1105 (desktop_area.width() - window2->bounds().width()) / 2) + | 1103 (desktop_area.width() - window2->bounds().width()) / 2) + |
1106 ",48 256x512", window2->bounds().ToString()); | 1104 ",48 256x512", |
| 1105 window2->bounds().ToString()); |
1107 | 1106 |
1108 window1_state->Restore(); | 1107 window1_state->Restore(); |
1109 // |window1| should be flush right and |window3| flush left. | 1108 // |window1| should be flush right and |window3| flush left. |
1110 EXPECT_EQ(base::IntToString( | 1109 EXPECT_EQ( |
1111 desktop_area.width() - window1->bounds().width()) + | 1110 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
1112 ",32 640x320", window1->bounds().ToString()); | 1111 ",32 640x320", |
| 1112 window1->bounds().ToString()); |
1113 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); | 1113 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
1114 } | 1114 } |
1115 | 1115 |
1116 // Test that minimizing an initially maximized window will repos the remaining. | 1116 // Test that minimizing an initially maximized window will repos the remaining. |
1117 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { | 1117 TEST_F(WorkspaceControllerTest, MaxToMinRepositionsRemaining) { |
1118 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1118 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1119 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1119 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1120 window1_state->set_window_position_managed(true); | 1120 window1_state->set_window_position_managed(true); |
1121 gfx::Rect desktop_area = window1->parent()->bounds(); | 1121 gfx::Rect desktop_area = window1->parent()->bounds(); |
1122 | 1122 |
1123 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1123 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1124 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 1124 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
1125 window2_state->set_window_position_managed(true); | 1125 window2_state->set_window_position_managed(true); |
1126 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); | 1126 window2->SetBounds(gfx::Rect(32, 48, 256, 512)); |
1127 | 1127 |
1128 window1_state->Maximize(); | 1128 window1_state->Maximize(); |
1129 window1_state->Minimize(); | 1129 window1_state->Minimize(); |
1130 | 1130 |
1131 // |window2| should be centered now. | 1131 // |window2| should be centered now. |
1132 EXPECT_TRUE(window2->IsVisible()); | 1132 EXPECT_TRUE(window2->IsVisible()); |
1133 EXPECT_TRUE(window2_state->IsNormalStateType()); | 1133 EXPECT_TRUE(window2_state->IsNormalStateType()); |
1134 EXPECT_EQ(base::IntToString( | 1134 EXPECT_EQ(base::IntToString( |
1135 (desktop_area.width() - window2->bounds().width()) / 2) + | 1135 (desktop_area.width() - window2->bounds().width()) / 2) + |
1136 ",48 256x512", window2->bounds().ToString()); | 1136 ",48 256x512", |
| 1137 window2->bounds().ToString()); |
1137 } | 1138 } |
1138 | 1139 |
1139 // Test that nomral, maximize, minimizing will repos the remaining. | 1140 // Test that nomral, maximize, minimizing will repos the remaining. |
1140 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { | 1141 TEST_F(WorkspaceControllerTest, NormToMaxToMinRepositionsRemaining) { |
1141 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1142 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1142 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1143 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
1143 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1144 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1144 window1_state->set_window_position_managed(true); | 1145 window1_state->set_window_position_managed(true); |
1145 gfx::Rect desktop_area = window1->parent()->bounds(); | 1146 gfx::Rect desktop_area = window1->parent()->bounds(); |
1146 | 1147 |
1147 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1148 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1148 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); | 1149 wm::WindowState* window2_state = wm::GetWindowState(window2.get()); |
1149 window2_state->set_window_position_managed(true); | 1150 window2_state->set_window_position_managed(true); |
1150 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1151 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
1151 | 1152 |
1152 // Trigger the auto window placement function by showing (and hiding) it. | 1153 // Trigger the auto window placement function by showing (and hiding) it. |
1153 window1->Hide(); | 1154 window1->Hide(); |
1154 window1->Show(); | 1155 window1->Show(); |
1155 | 1156 |
1156 // |window1| should be flush right and |window3| flush left. | 1157 // |window1| should be flush right and |window3| flush left. |
1157 EXPECT_EQ(base::IntToString( | 1158 EXPECT_EQ( |
1158 desktop_area.width() - window1->bounds().width()) + | 1159 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
1159 ",32 640x320", window1->bounds().ToString()); | 1160 ",32 640x320", |
| 1161 window1->bounds().ToString()); |
1160 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1162 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1161 | 1163 |
1162 window1_state->Maximize(); | 1164 window1_state->Maximize(); |
1163 window1_state->Minimize(); | 1165 window1_state->Minimize(); |
1164 | 1166 |
1165 // |window2| should be centered now. | 1167 // |window2| should be centered now. |
1166 EXPECT_TRUE(window2->IsVisible()); | 1168 EXPECT_TRUE(window2->IsVisible()); |
1167 EXPECT_TRUE(window2_state->IsNormalStateType()); | 1169 EXPECT_TRUE(window2_state->IsNormalStateType()); |
1168 EXPECT_EQ(base::IntToString( | 1170 EXPECT_EQ(base::IntToString( |
1169 (desktop_area.width() - window2->bounds().width()) / 2) + | 1171 (desktop_area.width() - window2->bounds().width()) / 2) + |
1170 ",40 256x512", window2->bounds().ToString()); | 1172 ",40 256x512", |
| 1173 window2->bounds().ToString()); |
1171 } | 1174 } |
1172 | 1175 |
1173 // Test that nomral, maximize, normal will repos the remaining. | 1176 // Test that nomral, maximize, normal will repos the remaining. |
1174 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { | 1177 TEST_F(WorkspaceControllerTest, NormToMaxToNormRepositionsRemaining) { |
1175 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1178 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1176 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1179 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
1177 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 1180 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
1178 window1_state->set_window_position_managed(true); | 1181 window1_state->set_window_position_managed(true); |
1179 gfx::Rect desktop_area = window1->parent()->bounds(); | 1182 gfx::Rect desktop_area = window1->parent()->bounds(); |
1180 | 1183 |
1181 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); | 1184 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1)); |
1182 wm::GetWindowState(window2.get())->set_window_position_managed(true); | 1185 wm::GetWindowState(window2.get())->set_window_position_managed(true); |
1183 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); | 1186 window2->SetBounds(gfx::Rect(32, 40, 256, 512)); |
1184 | 1187 |
1185 // Trigger the auto window placement function by showing (and hiding) it. | 1188 // Trigger the auto window placement function by showing (and hiding) it. |
1186 window1->Hide(); | 1189 window1->Hide(); |
1187 window1->Show(); | 1190 window1->Show(); |
1188 | 1191 |
1189 // |window1| should be flush right and |window3| flush left. | 1192 // |window1| should be flush right and |window3| flush left. |
1190 EXPECT_EQ(base::IntToString( | 1193 EXPECT_EQ( |
1191 desktop_area.width() - window1->bounds().width()) + | 1194 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
1192 ",32 640x320", window1->bounds().ToString()); | 1195 ",32 640x320", |
| 1196 window1->bounds().ToString()); |
1193 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1197 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1194 | 1198 |
1195 window1_state->Maximize(); | 1199 window1_state->Maximize(); |
1196 window1_state->Restore(); | 1200 window1_state->Restore(); |
1197 | 1201 |
1198 // |window1| should be flush right and |window2| flush left. | 1202 // |window1| should be flush right and |window2| flush left. |
1199 EXPECT_EQ(base::IntToString( | 1203 EXPECT_EQ( |
1200 desktop_area.width() - window1->bounds().width()) + | 1204 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
1201 ",32 640x320", window1->bounds().ToString()); | 1205 ",32 640x320", |
| 1206 window1->bounds().ToString()); |
1202 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); | 1207 EXPECT_EQ("0,40 256x512", window2->bounds().ToString()); |
1203 } | 1208 } |
1204 | 1209 |
1205 // Test that animations are triggered. | 1210 // Test that animations are triggered. |
1206 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { | 1211 TEST_F(WorkspaceControllerTest, AnimatedNormToMaxToNormRepositionsRemaining) { |
1207 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 1212 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
1208 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 1213 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
1209 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); | 1214 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0)); |
1210 window1->Hide(); | 1215 window1->Hide(); |
1211 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); | 1216 window1->SetBounds(gfx::Rect(16, 32, 640, 320)); |
(...skipping 14 matching lines...) Expand all Loading... |
1226 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); | 1231 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); |
1227 window2->layer()->GetAnimator()->StopAnimating(); | 1232 window2->layer()->GetAnimator()->StopAnimating(); |
1228 | 1233 |
1229 window1->Show(); | 1234 window1->Show(); |
1230 EXPECT_TRUE(window1->layer()->GetAnimator()->is_animating()); | 1235 EXPECT_TRUE(window1->layer()->GetAnimator()->is_animating()); |
1231 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); | 1236 EXPECT_TRUE(window2->layer()->GetAnimator()->is_animating()); |
1232 | 1237 |
1233 window1->layer()->GetAnimator()->StopAnimating(); | 1238 window1->layer()->GetAnimator()->StopAnimating(); |
1234 window2->layer()->GetAnimator()->StopAnimating(); | 1239 window2->layer()->GetAnimator()->StopAnimating(); |
1235 // |window1| should be flush right and |window2| flush left. | 1240 // |window1| should be flush right and |window2| flush left. |
1236 EXPECT_EQ(base::IntToString( | 1241 EXPECT_EQ( |
1237 desktop_area.width() - window1->bounds().width()) + | 1242 base::IntToString(desktop_area.width() - window1->bounds().width()) + |
1238 ",32 640x320", window1->bounds().ToString()); | 1243 ",32 640x320", |
| 1244 window1->bounds().ToString()); |
1239 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); | 1245 EXPECT_EQ("0,48 256x512", window2->bounds().ToString()); |
1240 } | 1246 } |
1241 | 1247 |
1242 // This tests simulates a browser and an app and verifies the ordering of the | 1248 // This tests simulates a browser and an app and verifies the ordering of the |
1243 // windows and layers doesn't get out of sync as various operations occur. Its | 1249 // windows and layers doesn't get out of sync as various operations occur. Its |
1244 // really testing code in FocusController, but easier to simulate here. Just as | 1250 // really testing code in FocusController, but easier to simulate here. Just as |
1245 // with a real browser the browser here has a transient child window | 1251 // with a real browser the browser here has a transient child window |
1246 // (corresponds to the status bubble). | 1252 // (corresponds to the status bubble). |
1247 TEST_F(WorkspaceControllerTest, VerifyLayerOrdering) { | 1253 TEST_F(WorkspaceControllerTest, VerifyLayerOrdering) { |
1248 std::unique_ptr<Window> browser(aura::test::CreateTestWindowWithDelegate( | 1254 std::unique_ptr<Window> browser(aura::test::CreateTestWindowWithDelegate( |
1249 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); | 1255 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); |
1250 browser->SetName("browser"); | 1256 browser->SetName("browser"); |
1251 ParentWindowInPrimaryRootWindow(browser.get()); | 1257 ParentWindowInPrimaryRootWindow(browser.get()); |
1252 browser->Show(); | 1258 browser->Show(); |
1253 wm::ActivateWindow(browser.get()); | 1259 wm::ActivateWindow(browser.get()); |
1254 | 1260 |
1255 // |status_bubble| is made a transient child of |browser| and as a result | 1261 // |status_bubble| is made a transient child of |browser| and as a result |
1256 // owned by |browser|. | 1262 // owned by |browser|. |
1257 aura::test::TestWindowDelegate* status_bubble_delegate = | 1263 aura::test::TestWindowDelegate* status_bubble_delegate = |
1258 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(); | 1264 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(); |
1259 status_bubble_delegate->set_can_focus(false); | 1265 status_bubble_delegate->set_can_focus(false); |
1260 Window* status_bubble = | 1266 Window* status_bubble = aura::test::CreateTestWindowWithDelegate( |
1261 aura::test::CreateTestWindowWithDelegate(status_bubble_delegate, | 1267 status_bubble_delegate, ui::wm::WINDOW_TYPE_POPUP, gfx::Rect(5, 6, 7, 8), |
1262 ui::wm::WINDOW_TYPE_POPUP, | 1268 NULL); |
1263 gfx::Rect(5, 6, 7, 8), | |
1264 NULL); | |
1265 ::wm::AddTransientChild(browser.get(), status_bubble); | 1269 ::wm::AddTransientChild(browser.get(), status_bubble); |
1266 ParentWindowInPrimaryRootWindow(status_bubble); | 1270 ParentWindowInPrimaryRootWindow(status_bubble); |
1267 status_bubble->SetName("status_bubble"); | 1271 status_bubble->SetName("status_bubble"); |
1268 | 1272 |
1269 std::unique_ptr<Window> app(aura::test::CreateTestWindowWithDelegate( | 1273 std::unique_ptr<Window> app(aura::test::CreateTestWindowWithDelegate( |
1270 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); | 1274 NULL, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 6, 7, 8), NULL)); |
1271 app->SetName("app"); | 1275 app->SetName("app"); |
1272 ParentWindowInPrimaryRootWindow(app.get()); | 1276 ParentWindowInPrimaryRootWindow(app.get()); |
1273 | 1277 |
1274 aura::Window* parent = browser->parent(); | 1278 aura::Window* parent = browser->parent(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 // Activate the app. | 1310 // Activate the app. |
1307 ash::wm::ActivateWindow(app.get()); | 1311 ash::wm::ActivateWindow(app.get()); |
1308 EXPECT_TRUE(wm::IsActiveWindow(app.get())); | 1312 EXPECT_TRUE(wm::IsActiveWindow(app.get())); |
1309 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent)); | 1313 EXPECT_EQ(GetWindowNames(parent), GetLayerNames(parent)); |
1310 } | 1314 } |
1311 | 1315 |
1312 namespace { | 1316 namespace { |
1313 | 1317 |
1314 // Used by DragMaximizedNonTrackedWindow to track how many times the window | 1318 // Used by DragMaximizedNonTrackedWindow to track how many times the window |
1315 // hierarchy changes affecting the specified window. | 1319 // hierarchy changes affecting the specified window. |
1316 class DragMaximizedNonTrackedWindowObserver | 1320 class DragMaximizedNonTrackedWindowObserver : public aura::WindowObserver { |
1317 : public aura::WindowObserver { | |
1318 public: | 1321 public: |
1319 DragMaximizedNonTrackedWindowObserver(aura::Window* window) | 1322 DragMaximizedNonTrackedWindowObserver(aura::Window* window) |
1320 : change_count_(0), | 1323 : change_count_(0), window_(window) {} |
1321 window_(window) { | |
1322 } | |
1323 | 1324 |
1324 // Number of times OnWindowHierarchyChanged() has been received. | 1325 // Number of times OnWindowHierarchyChanged() has been received. |
1325 void clear_change_count() { change_count_ = 0; } | 1326 void clear_change_count() { change_count_ = 0; } |
1326 int change_count() const { | 1327 int change_count() const { return change_count_; } |
1327 return change_count_; | |
1328 } | |
1329 | 1328 |
1330 // aura::WindowObserver overrides: | 1329 // aura::WindowObserver overrides: |
1331 // Counts number of times a window is reparented. Ignores reparenting into and | 1330 // Counts number of times a window is reparented. Ignores reparenting into and |
1332 // from a docked container which is expected when a tab is dragged. | 1331 // from a docked container which is expected when a tab is dragged. |
1333 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { | 1332 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { |
1334 if (params.target != window_ || | 1333 if (params.target != window_ || |
1335 (params.old_parent->id() == kShellWindowId_DefaultContainer && | 1334 (params.old_parent->id() == kShellWindowId_DefaultContainer && |
1336 params.new_parent->id() == kShellWindowId_DockedContainer) || | 1335 params.new_parent->id() == kShellWindowId_DockedContainer) || |
1337 (params.old_parent->id() == kShellWindowId_DockedContainer && | 1336 (params.old_parent->id() == kShellWindowId_DockedContainer && |
1338 params.new_parent->id() == kShellWindowId_DefaultContainer)) { | 1337 params.new_parent->id() == kShellWindowId_DefaultContainer)) { |
(...skipping 16 matching lines...) Expand all Loading... |
1355 // modal window is active. | 1354 // modal window is active. |
1356 TEST_F(WorkspaceControllerTest, SwitchFromModal) { | 1355 TEST_F(WorkspaceControllerTest, SwitchFromModal) { |
1357 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented()); | 1356 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented()); |
1358 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); | 1357 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); |
1359 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 1358 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
1360 ParentWindowInPrimaryRootWindow(modal_window.get()); | 1359 ParentWindowInPrimaryRootWindow(modal_window.get()); |
1361 modal_window->Show(); | 1360 modal_window->Show(); |
1362 wm::ActivateWindow(modal_window.get()); | 1361 wm::ActivateWindow(modal_window.get()); |
1363 | 1362 |
1364 std::unique_ptr<Window> maximized_window(CreateTestWindow()); | 1363 std::unique_ptr<Window> maximized_window(CreateTestWindow()); |
1365 maximized_window->SetProperty( | 1364 maximized_window->SetProperty(aura::client::kShowStateKey, |
1366 aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 1365 ui::SHOW_STATE_MAXIMIZED); |
1367 maximized_window->Show(); | 1366 maximized_window->Show(); |
1368 wm::ActivateWindow(maximized_window.get()); | 1367 wm::ActivateWindow(maximized_window.get()); |
1369 EXPECT_TRUE(maximized_window->IsVisible()); | 1368 EXPECT_TRUE(maximized_window->IsVisible()); |
1370 } | 1369 } |
1371 | 1370 |
1372 namespace { | 1371 namespace { |
1373 | 1372 |
1374 // Subclass of WorkspaceControllerTest that runs tests with docked windows | 1373 // Subclass of WorkspaceControllerTest that runs tests with docked windows |
1375 // enabled and disabled. | 1374 // enabled and disabled. |
1376 class WorkspaceControllerTestDragging : public WorkspaceControllerTest { | 1375 class WorkspaceControllerTestDragging : public WorkspaceControllerTest { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 | 1457 |
1459 // The windows overlap, and |second| is on top of |first|. Events targeted | 1458 // The windows overlap, and |second| is on top of |first|. Events targeted |
1460 // slightly outside the edges of the |second| window should still be targeted | 1459 // slightly outside the edges of the |second| window should still be targeted |
1461 // to |second| to allow resizing the windows easily. | 1460 // to |second| to allow resizing the windows easily. |
1462 | 1461 |
1463 const int kNumPoints = 4; | 1462 const int kNumPoints = 4; |
1464 struct { | 1463 struct { |
1465 const char* direction; | 1464 const char* direction; |
1466 gfx::Point location; | 1465 gfx::Point location; |
1467 } points[kNumPoints] = { | 1466 } points[kNumPoints] = { |
1468 { "left", gfx::Point(28, 45) }, // outside the left edge. | 1467 {"left", gfx::Point(28, 45)}, // outside the left edge. |
1469 { "top", gfx::Point(50, 38) }, // outside the top edge. | 1468 {"top", gfx::Point(50, 38)}, // outside the top edge. |
1470 { "right", gfx::Point(72, 45) }, // outside the right edge. | 1469 {"right", gfx::Point(72, 45)}, // outside the right edge. |
1471 { "bottom", gfx::Point(50, 52) }, // outside the bottom edge. | 1470 {"bottom", gfx::Point(50, 52)}, // outside the bottom edge. |
1472 }; | 1471 }; |
1473 // Do two iterations, first without any transform on |second|, and the second | 1472 // Do two iterations, first without any transform on |second|, and the second |
1474 // time after applying some transform on |second| so that it doesn't get | 1473 // time after applying some transform on |second| so that it doesn't get |
1475 // targeted. | 1474 // targeted. |
1476 for (int times = 0; times < 2; ++times) { | 1475 for (int times = 0; times < 2; ++times) { |
1477 SCOPED_TRACE(times == 0 ? "Without transform" : "With transform"); | 1476 SCOPED_TRACE(times == 0 ? "Without transform" : "With transform"); |
1478 aura::Window* expected_target = times == 0 ? second.get() : first.get(); | 1477 aura::Window* expected_target = times == 0 ? second.get() : first.get(); |
1479 for (int i = 0; i < kNumPoints; ++i) { | 1478 for (int i = 0; i < kNumPoints; ++i) { |
1480 SCOPED_TRACE(points[i].direction); | 1479 SCOPED_TRACE(points[i].direction); |
1481 const gfx::Point& location = points[i].location; | 1480 const gfx::Point& location = points[i].location; |
(...skipping 22 matching lines...) Expand all Loading... |
1504 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); | 1503 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); |
1505 ui::EventTarget* root = window->GetRootWindow(); | 1504 ui::EventTarget* root = window->GetRootWindow(); |
1506 ui::EventTargeter* targeter = root->GetEventTargeter(); | 1505 ui::EventTargeter* targeter = root->GetEventTargeter(); |
1507 const gfx::Rect bounds = window->bounds(); | 1506 const gfx::Rect bounds = window->bounds(); |
1508 const int kNumPoints = 5; | 1507 const int kNumPoints = 5; |
1509 struct { | 1508 struct { |
1510 const char* direction; | 1509 const char* direction; |
1511 gfx::Point location; | 1510 gfx::Point location; |
1512 bool is_target_hit; | 1511 bool is_target_hit; |
1513 } points[kNumPoints] = { | 1512 } points[kNumPoints] = { |
1514 { "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true }, | 1513 {"left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true}, |
1515 { "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true }, | 1514 {"top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true}, |
1516 { "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true }, | 1515 {"right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true}, |
1517 { "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true }, | 1516 {"bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true}, |
1518 { "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false }, | 1517 {"outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false}, |
1519 }; | 1518 }; |
1520 for (int i = 0; i < kNumPoints; ++i) { | 1519 for (int i = 0; i < kNumPoints; ++i) { |
1521 SCOPED_TRACE(points[i].direction); | 1520 SCOPED_TRACE(points[i].direction); |
1522 const gfx::Point& location = points[i].location; | 1521 const gfx::Point& location = points[i].location; |
1523 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, | 1522 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, |
1524 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 1523 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
1525 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 1524 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
1526 if (points[i].is_target_hit) | 1525 if (points[i].is_target_hit) |
1527 EXPECT_EQ(window.get(), target); | 1526 EXPECT_EQ(window.get(), target); |
1528 else | 1527 else |
(...skipping 11 matching lines...) Expand all Loading... |
1540 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); | 1539 CreateTestPanel(&delegate, gfx::Rect(20, 10, 100, 50))); |
1541 ui::EventTarget* root = window->GetRootWindow(); | 1540 ui::EventTarget* root = window->GetRootWindow(); |
1542 ui::EventTargeter* targeter = root->GetEventTargeter(); | 1541 ui::EventTargeter* targeter = root->GetEventTargeter(); |
1543 const gfx::Rect bounds = window->bounds(); | 1542 const gfx::Rect bounds = window->bounds(); |
1544 const int kNumPoints = 5; | 1543 const int kNumPoints = 5; |
1545 struct { | 1544 struct { |
1546 const char* direction; | 1545 const char* direction; |
1547 gfx::Point location; | 1546 gfx::Point location; |
1548 bool is_target_hit; | 1547 bool is_target_hit; |
1549 } points[kNumPoints] = { | 1548 } points[kNumPoints] = { |
1550 { "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true }, | 1549 {"left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true}, |
1551 { "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true }, | 1550 {"top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true}, |
1552 { "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true }, | 1551 {"right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true}, |
1553 { "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), false }, | 1552 {"bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), false}, |
1554 { "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false }, | 1553 {"outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false}, |
1555 }; | 1554 }; |
1556 for (int i = 0; i < kNumPoints; ++i) { | 1555 for (int i = 0; i < kNumPoints; ++i) { |
1557 SCOPED_TRACE(points[i].direction); | 1556 SCOPED_TRACE(points[i].direction); |
1558 const gfx::Point& location = points[i].location; | 1557 const gfx::Point& location = points[i].location; |
1559 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, | 1558 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, |
1560 ui::EventTimeForNow()); | 1559 ui::EventTimeForNow()); |
1561 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); | 1560 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); |
1562 if (points[i].is_target_hit) | 1561 if (points[i].is_target_hit) |
1563 EXPECT_EQ(window.get(), target); | 1562 EXPECT_EQ(window.get(), target); |
1564 else | 1563 else |
(...skipping 16 matching lines...) Expand all Loading... |
1581 window->Show(); | 1580 window->Show(); |
1582 ui::EventTarget* root = window->GetRootWindow(); | 1581 ui::EventTarget* root = window->GetRootWindow(); |
1583 ui::EventTargeter* targeter = root->GetEventTargeter(); | 1582 ui::EventTargeter* targeter = root->GetEventTargeter(); |
1584 const gfx::Rect bounds = window->bounds(); | 1583 const gfx::Rect bounds = window->bounds(); |
1585 const int kNumPoints = 5; | 1584 const int kNumPoints = 5; |
1586 struct { | 1585 struct { |
1587 const char* direction; | 1586 const char* direction; |
1588 gfx::Point location; | 1587 gfx::Point location; |
1589 bool is_target_hit; | 1588 bool is_target_hit; |
1590 } points[kNumPoints] = { | 1589 } points[kNumPoints] = { |
1591 { "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true }, | 1590 {"left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true}, |
1592 { "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true }, | 1591 {"top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true}, |
1593 { "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true }, | 1592 {"right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true}, |
1594 { "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true }, | 1593 {"bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true}, |
1595 { "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false }, | 1594 {"outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false}, |
1596 }; | 1595 }; |
1597 for (int i = 0; i < kNumPoints; ++i) { | 1596 for (int i = 0; i < kNumPoints; ++i) { |
1598 SCOPED_TRACE(points[i].direction); | 1597 SCOPED_TRACE(points[i].direction); |
1599 const gfx::Point& location = points[i].location; | 1598 const gfx::Point& location = points[i].location; |
1600 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, | 1599 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, |
1601 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 1600 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
1602 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | 1601 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); |
1603 if (points[i].is_target_hit) | 1602 if (points[i].is_target_hit) |
1604 EXPECT_EQ(window.get(), target); | 1603 EXPECT_EQ(window.get(), target); |
1605 else | 1604 else |
1606 EXPECT_NE(window.get(), target); | 1605 EXPECT_NE(window.get(), target); |
1607 | 1606 |
1608 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, | 1607 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, |
1609 ui::EventTimeForNow()); | 1608 ui::EventTimeForNow()); |
1610 target = targeter->FindTargetForEvent(root, &touch); | 1609 target = targeter->FindTargetForEvent(root, &touch); |
1611 if (points[i].is_target_hit) | 1610 if (points[i].is_target_hit) |
1612 EXPECT_EQ(window.get(), target); | 1611 EXPECT_EQ(window.get(), target); |
1613 else | 1612 else |
1614 EXPECT_NE(window.get(), target); | 1613 EXPECT_NE(window.get(), target); |
1615 } | 1614 } |
1616 } | 1615 } |
1617 | 1616 |
1618 } // namespace ash | 1617 } // namespace ash |
OLD | NEW |