Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: ash/wm/window_positioner_unittest.cc

Issue 2194353002: mash: Migrate ScopedTargetRootWindow to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: non-virtual Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_root_window_for_new_windows.h"
10 #include "ash/common/wm/window_positioner.h" 11 #include "ash/common/wm/window_positioner.h"
11 #include "ash/common/wm/window_state.h" 12 #include "ash/common/wm/window_state.h"
12 #include "ash/common/wm_shell.h" 13 #include "ash/common/wm_shell.h"
14 #include "ash/common/wm_window.h"
13 #include "ash/shell.h" 15 #include "ash/shell.h"
14 #include "ash/shell/toplevel_window.h" 16 #include "ash/shell/toplevel_window.h"
15 #include "ash/test/ash_md_test_base.h" 17 #include "ash/test/ash_md_test_base.h"
16 #include "ash/test/test_shell_delegate.h" 18 #include "ash/test/test_shell_delegate.h"
17 #include "ash/wm/window_state_aura.h" 19 #include "ash/wm/window_state_aura.h"
18 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h" 23 #include "ui/views/widget/widget_delegate.h"
23 24
24 namespace ash { 25 namespace ash {
25 26
26 using WindowPositionerTest = test::AshMDTestBase; 27 using WindowPositionerTest = test::AshMDTestBase;
27 28
28 INSTANTIATE_TEST_CASE_P( 29 INSTANTIATE_TEST_CASE_P(
29 /* prefix intentionally left blank due to only one parameterization */, 30 /* prefix intentionally left blank due to only one parameterization */,
30 WindowPositionerTest, 31 WindowPositionerTest,
31 testing::Values(MaterialDesignController::NON_MATERIAL, 32 testing::Values(MaterialDesignController::NON_MATERIAL,
32 MaterialDesignController::MATERIAL_NORMAL, 33 MaterialDesignController::MATERIAL_NORMAL,
33 MaterialDesignController::MATERIAL_EXPERIMENTAL)); 34 MaterialDesignController::MATERIAL_EXPERIMENTAL));
34 35
35 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { 36 TEST_P(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) {
36 if (!SupportsMultipleDisplays()) 37 if (!SupportsMultipleDisplays())
37 return; 38 return;
38 const int height_offset = GetMdMaximizedWindowHeightOffset(); 39 const int height_offset = GetMdMaximizedWindowHeightOffset();
39 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit 40 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit
40 // a new window gets maximized. 41 // a new window gets maximized.
41 UpdateDisplay("400x400,500x500"); 42 UpdateDisplay("400x400,500x500");
42 Shell::GetInstance()->set_target_root_window(Shell::GetAllRootWindows()[1]); 43 ScopedRootWindowForNewWindows root_for_new_windows(
44 WmShell::Get()->GetAllRootWindows()[1]);
43 shell::ToplevelWindow::CreateParams params; 45 shell::ToplevelWindow::CreateParams params;
44 params.can_resize = true; 46 params.can_resize = true;
45 params.can_maximize = true; 47 params.can_maximize = true;
46 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); 48 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params);
47 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(), 49 EXPECT_EQ(gfx::Rect(400, 0, 500, 453 + height_offset).ToString(),
48 widget->GetWindowBoundsInScreen().ToString()); 50 widget->GetWindowBoundsInScreen().ToString());
49 } 51 }
50 52
51 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { 53 TEST_P(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) {
52 if (!SupportsMultipleDisplays()) 54 if (!SupportsMultipleDisplays())
53 return; 55 return;
54 #if defined(OS_WIN) 56 #if defined(OS_WIN)
55 ash::WindowPositioner::SetMaximizeFirstWindow(true); 57 ash::WindowPositioner::SetMaximizeFirstWindow(true);
56 #endif 58 #endif
57 UpdateDisplay("400x400,1400x900"); 59 UpdateDisplay("400x400,1400x900");
58 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; 60 WmWindow* second_root_window = WmShell::Get()->GetAllRootWindows()[1];
59 Shell::GetInstance()->set_target_root_window(second_root_window); 61 ScopedRootWindowForNewWindows root_for_new_windows(second_root_window);
60 shell::ToplevelWindow::CreateParams params; 62 shell::ToplevelWindow::CreateParams params;
61 params.can_resize = true; 63 params.can_resize = true;
62 params.can_maximize = true; 64 params.can_maximize = true;
63 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params); 65 views::Widget* widget = shell::ToplevelWindow::CreateToplevelWindow(params);
64 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); 66 gfx::Rect bounds = widget->GetWindowBoundsInScreen();
65 #if defined(OS_WIN) 67 #if defined(OS_WIN)
66 EXPECT_TRUE(widget->IsMaximized()); 68 EXPECT_TRUE(widget->IsMaximized());
67 #else 69 #else
68 // The window should be in the 2nd display with the default size. 70 // The window should be in the 2nd display with the default size.
69 EXPECT_EQ("300x300", bounds.size().ToString()); 71 EXPECT_EQ("300x300", bounds.size().ToString());
70 #endif 72 #endif
71 EXPECT_TRUE(display::Screen::GetScreen() 73
72 ->GetDisplayNearestWindow(second_root_window) 74 EXPECT_TRUE(
73 .bounds() 75 second_root_window->GetDisplayNearestWindow().bounds().Contains(bounds));
74 .Contains(bounds));
75 } 76 }
76 77
77 // Tests that second window inherits first window's maximized state as well as 78 // Tests that second window inherits first window's maximized state as well as
78 // its restore bounds. 79 // its restore bounds.
79 // TODO(msw): Broken on Windows. http://crbug.com/584038 80 // TODO(msw): Broken on Windows. http://crbug.com/584038
80 #if defined(OS_CHROMEOS) 81 #if defined(OS_CHROMEOS)
81 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) { 82 TEST_P(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) {
82 const int height_offset = GetMdMaximizedWindowHeightOffset(); 83 const int height_offset = GetMdMaximizedWindowHeightOffset();
83 UpdateDisplay("1400x900"); 84 UpdateDisplay("1400x900");
84 shell::ToplevelWindow::CreateParams params; 85 shell::ToplevelWindow::CreateParams params;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 widget1->SetFullscreen(false); 233 widget1->SetFullscreen(false);
233 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); 234 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString());
234 235
235 // Closing 2nd widget triggers the rearrange logic but the 1st 236 // Closing 2nd widget triggers the rearrange logic but the 1st
236 // widget should stay in the current size. 237 // widget should stay in the current size.
237 widget2->CloseNow(); 238 widget2->CloseNow();
238 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString()); 239 ASSERT_EQ("300x300", widget1->GetWindowBoundsInScreen().size().ToString());
239 } 240 }
240 241
241 } // namespace ash 242 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_controller_unittest.cc ('k') | chrome/browser/ui/window_sizer/window_sizer_ash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698