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/common/wm/window_positioner.h" | 5 #include "ash/common/wm/window_positioner.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
10 #include "ash/common/wm/window_positioner.h" | 10 #include "ash/common/wm/window_positioner.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 MaterialDesignController::MATERIAL_NORMAL, | 31 MaterialDesignController::MATERIAL_NORMAL, |
32 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | 32 MaterialDesignController::MATERIAL_EXPERIMENTAL)); |
33 | 33 |
34 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { | 34 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { |
35 if (!SupportsMultipleDisplays()) | 35 if (!SupportsMultipleDisplays()) |
36 return; | 36 return; |
37 const int height_offset = GetMdMaximizedWindowHeightOffset(); | 37 const int height_offset = GetMdMaximizedWindowHeightOffset(); |
38 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit | 38 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit |
39 // a new window gets maximized. | 39 // a new window gets maximized. |
40 UpdateDisplay("400x400,500x500"); | 40 UpdateDisplay("400x400,500x500"); |
41 Shell::GetInstance()->set_target_root_window( | 41 Shell::GetInstance()->set_target_root_window(Shell::GetAllRootWindows()[1]); |
42 Shell::GetAllRootWindows()[1]); | |
43 shell::ToplevelWindow::CreateParams params; | 42 shell::ToplevelWindow::CreateParams params; |
44 params.can_resize = true; | 43 params.can_resize = true; |
45 params.can_maximize = true; | 44 params.can_maximize = true; |
46 views::Widget* widget = | 45 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); |
47 shell::ToplevelWindow::CreateToplevelWindow(params); | |
48 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(), | 46 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(), |
49 widget->GetWindowBoundsInScreen().ToString()); | 47 widget->GetWindowBoundsInScreen().ToString()); |
50 } | 48 } |
51 | 49 |
52 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { | 50 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { |
53 if (!SupportsMultipleDisplays()) | 51 if (!SupportsMultipleDisplays()) |
54 return; | 52 return; |
55 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
56 ash::WindowPositioner::SetMaximizeFirstWindow(true); | 54 ash::WindowPositioner::SetMaximizeFirstWindow(true); |
57 #endif | 55 #endif |
58 UpdateDisplay("400x400,1400x900"); | 56 UpdateDisplay("400x400,1400x900"); |
59 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; | 57 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; |
60 Shell::GetInstance()->set_target_root_window( | 58 Shell::GetInstance()->set_target_root_window(second_root_window); |
61 second_root_window); | |
62 shell::ToplevelWindow::CreateParams params; | 59 shell::ToplevelWindow::CreateParams params; |
63 params.can_resize = true; | 60 params.can_resize = true; |
64 params.can_maximize = true; | 61 params.can_maximize = true; |
65 views::Widget* widget = | 62 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); |
66 shell::ToplevelWindow::CreateToplevelWindow(params); | |
67 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); | 63 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); |
68 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
69 EXPECT_TRUE(widget->IsMaximized()); | 65 EXPECT_TRUE(widget->IsMaximized()); |
70 #else | 66 #else |
71 // The window should be in the 2nd display with the default size. | 67 // The window should be in the 2nd display with the default size. |
72 EXPECT_EQ("300x300", bounds.size().ToString()); | 68 EXPECT_EQ("300x300", bounds.size().ToString()); |
73 #endif | 69 #endif |
74 EXPECT_TRUE(display::Screen::GetScreen() | 70 EXPECT_TRUE(display::Screen::GetScreen() |
75 ->GetDisplayNearestWindow(second_root_window) | 71 ->GetDisplayNearestWindow(second_root_window) |
76 .bounds() | 72 .bounds() |
77 .Contains(bounds)); | 73 .Contains(bounds)); |
78 } | 74 } |
79 | 75 |
80 // Tests that second window inherits first window's maximized state as well as | 76 // Tests that second window inherits first window's maximized state as well as |
81 // its restore bounds. | 77 // its restore bounds. |
82 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 78 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
83 #if defined(OS_CHROMEOS) | 79 #if defined(OS_CHROMEOS) |
84 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) { | 80 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) { |
85 const int height_offset = GetMdMaximizedWindowHeightOffset(); | 81 const int height_offset = GetMdMaximizedWindowHeightOffset(); |
86 UpdateDisplay("1400x900"); | 82 UpdateDisplay("1400x900"); |
87 shell::ToplevelWindow::CreateParams params; | 83 shell::ToplevelWindow::CreateParams params; |
88 params.can_resize = true; | 84 params.can_resize = true; |
89 params.can_maximize = true; | 85 params.can_maximize = true; |
90 views::Widget* widget1 = | 86 views::Widget* widget1 = shell::ToplevelWindow::CreateToplevelWindow(params); |
91 shell::ToplevelWindow::CreateToplevelWindow(params); | |
92 gfx::Rect bounds = widget1->GetWindowBoundsInScreen(); | 87 gfx::Rect bounds = widget1->GetWindowBoundsInScreen(); |
93 | 88 |
94 // The window should have default size. | 89 // The window should have default size. |
95 EXPECT_FALSE(widget1->IsMaximized()); | 90 EXPECT_FALSE(widget1->IsMaximized()); |
96 EXPECT_EQ("300x300", bounds.size().ToString()); | 91 EXPECT_EQ("300x300", bounds.size().ToString()); |
97 widget1->Maximize(); | 92 widget1->Maximize(); |
98 | 93 |
99 // The window should be maximized. | 94 // The window should be maximized. |
100 bounds = widget1->GetWindowBoundsInScreen(); | 95 bounds = widget1->GetWindowBoundsInScreen(); |
101 EXPECT_TRUE(widget1->IsMaximized()); | 96 EXPECT_TRUE(widget1->IsMaximized()); |
102 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), | 97 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), |
103 bounds.ToString()); | 98 bounds.ToString()); |
104 | 99 |
105 // Create another window | 100 // Create another window |
106 views::Widget* widget2 = | 101 views::Widget* widget2 = shell::ToplevelWindow::CreateToplevelWindow(params); |
107 shell::ToplevelWindow::CreateToplevelWindow(params); | |
108 | 102 |
109 // The second window should be maximized. | 103 // The second window should be maximized. |
110 bounds = widget2->GetWindowBoundsInScreen(); | 104 bounds = widget2->GetWindowBoundsInScreen(); |
111 EXPECT_TRUE(widget2->IsMaximized()); | 105 EXPECT_TRUE(widget2->IsMaximized()); |
112 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), | 106 EXPECT_EQ(gfx::Rect(0, 0, 1400, 853 + height_offset).ToString(), |
113 bounds.ToString()); | 107 bounds.ToString()); |
114 | 108 |
115 widget2->Restore(); | 109 widget2->Restore(); |
116 // Second window's restored size should be set to default size. | 110 // Second window's restored size should be set to default size. |
117 bounds = widget2->GetWindowBoundsInScreen(); | 111 bounds = widget2->GetWindowBoundsInScreen(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 TEST_P(WindowPositionerTest, EnsureMinimumVisibility) { | 144 TEST_P(WindowPositionerTest, EnsureMinimumVisibility) { |
151 if (!SupportsHostWindowResize()) | 145 if (!SupportsHostWindowResize()) |
152 return; | 146 return; |
153 | 147 |
154 UpdateDisplay("400x400"); | 148 UpdateDisplay("400x400"); |
155 views::Widget* widget = new views::Widget(); | 149 views::Widget* widget = new views::Widget(); |
156 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 150 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
157 params.delegate = new OutOfDisplayDelegate(widget); | 151 params.delegate = new OutOfDisplayDelegate(widget); |
158 params.context = Shell::GetPrimaryRootWindow(); | 152 params.context = Shell::GetPrimaryRootWindow(); |
159 widget->Init(params); | 153 widget->Init(params); |
160 widget->SetBounds(gfx::Rect(450,10, 100, 100)); | 154 widget->SetBounds(gfx::Rect(450, 10, 100, 100)); |
161 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); | 155 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); |
162 widget->Show(); | 156 widget->Show(); |
163 // Make sure the bounds is adjusted to be inside the work area. | 157 // Make sure the bounds is adjusted to be inside the work area. |
164 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString()); | 158 EXPECT_EQ("375,10 100x100", widget->GetWindowBoundsInScreen().ToString()); |
165 widget->CloseNow(); | 159 widget->CloseNow(); |
166 } | 160 } |
167 | 161 |
168 // In general case on first run the browser window will be maximized only for | 162 // In general case on first run the browser window will be maximized only for |
169 // low resolution screens (width < 1366). In case of big screens the browser is | 163 // low resolution screens (width < 1366). In case of big screens the browser is |
170 // opened being not maximized. To enforce maximization for all screen | 164 // opened being not maximized. To enforce maximization for all screen |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 widget1->SetFullscreen(false); | 231 widget1->SetFullscreen(false); |
238 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); | 232 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); |
239 | 233 |
240 // Closing 2nd widget triggers the rearrange logic but the 1st | 234 // Closing 2nd widget triggers the rearrange logic but the 1st |
241 // widget should stay in the current size. | 235 // widget should stay in the current size. |
242 widget2->CloseNow(); | 236 widget2->CloseNow(); |
243 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); | 237 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); |
244 } | 238 } |
245 | 239 |
246 } // namespace ash | 240 } // namespace ash |
OLD | NEW |