| 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/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell/toplevel_window.h" | 8 #include "ash/shell/toplevel_window.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/window_positioner.h" |
| 10 #include "ash/wm/window_state.h" | 11 #include "ash/wm/window_state.h" |
| 11 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 12 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
| 13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 14 #include "ui/views/widget/widget_delegate.h" | 15 #include "ui/views/widget/widget_delegate.h" |
| 15 | 16 |
| 16 namespace ash { | 17 namespace ash { |
| 17 | 18 |
| 18 typedef test::AshTestBase WindowPositionerTest; | 19 typedef test::AshTestBase WindowPositionerTest; |
| 19 | 20 |
| 20 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { | 21 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) { |
| 21 if (!SupportsMultipleDisplays()) | 22 if (!SupportsMultipleDisplays()) |
| 22 return; | 23 return; |
| 23 UpdateDisplay("400x400,500x500"); | 24 UpdateDisplay("400x400,500x500"); |
| 24 Shell::GetInstance()->set_target_root_window( | 25 Shell::GetInstance()->set_target_root_window( |
| 25 Shell::GetAllRootWindows()[1]); | 26 Shell::GetAllRootWindows()[1]); |
| 26 shell::ToplevelWindow::CreateParams params; | 27 shell::ToplevelWindow::CreateParams params; |
| 27 params.can_resize = true; | 28 params.can_resize = true; |
| 28 params.can_maximize = true; | 29 params.can_maximize = true; |
| 29 views::Widget* widget = | 30 views::Widget* widget = |
| 30 shell::ToplevelWindow::CreateToplevelWindow(params); | 31 shell::ToplevelWindow::CreateToplevelWindow(params); |
| 31 EXPECT_EQ("400,0 500x453", widget->GetWindowBoundsInScreen().ToString()); | 32 EXPECT_EQ("400,0 500x453", widget->GetWindowBoundsInScreen().ToString()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { | 35 TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) { |
| 35 if (!SupportsMultipleDisplays()) | 36 if (!SupportsMultipleDisplays()) |
| 36 return; | 37 return; |
| 38 #if defined(OS_WIN) |
| 39 ash::WindowPositioner::SetMaximizeFirstWindow(true); |
| 40 #endif |
| 37 UpdateDisplay("400x400,1400x900"); | 41 UpdateDisplay("400x400,1400x900"); |
| 38 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; | 42 aura::Window* second_root_window = Shell::GetAllRootWindows()[1]; |
| 39 Shell::GetInstance()->set_target_root_window( | 43 Shell::GetInstance()->set_target_root_window( |
| 40 second_root_window); | 44 second_root_window); |
| 41 shell::ToplevelWindow::CreateParams params; | 45 shell::ToplevelWindow::CreateParams params; |
| 42 params.can_resize = true; | 46 params.can_resize = true; |
| 43 params.can_maximize = true; | 47 params.can_maximize = true; |
| 44 views::Widget* widget = | 48 views::Widget* widget = |
| 45 shell::ToplevelWindow::CreateToplevelWindow(params); | 49 shell::ToplevelWindow::CreateToplevelWindow(params); |
| 46 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); | 50 gfx::Rect bounds = widget->GetWindowBoundsInScreen(); |
| 51 #if defined(OS_WIN) |
| 52 EXPECT_TRUE(widget->IsMaximized()); |
| 53 #else |
| 47 // The window should be in the 2nd display with the default size. | 54 // The window should be in the 2nd display with the default size. |
| 48 EXPECT_EQ("300x300", bounds.size().ToString()); | 55 EXPECT_EQ("300x300", bounds.size().ToString()); |
| 56 #endif |
| 49 EXPECT_TRUE(Shell::GetScreen()->GetDisplayNearestWindow( | 57 EXPECT_TRUE(Shell::GetScreen()->GetDisplayNearestWindow( |
| 50 second_root_window).bounds().Contains(bounds)); | 58 second_root_window).bounds().Contains(bounds)); |
| 51 } | 59 } |
| 52 | 60 |
| 53 namespace { | 61 namespace { |
| 54 | 62 |
| 55 // A WidgetDelegate that returns the out of display saved bounds. | 63 // A WidgetDelegate that returns the out of display saved bounds. |
| 56 class OutOfDisplayDelegate : public views::WidgetDelegate { | 64 class OutOfDisplayDelegate : public views::WidgetDelegate { |
| 57 public: | 65 public: |
| 58 explicit OutOfDisplayDelegate(views::Widget* widget) : widget_(widget) {} | 66 explicit OutOfDisplayDelegate(views::Widget* widget) : widget_(widget) {} |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 widget->Init(params); | 105 widget->Init(params); |
| 98 widget->SetBounds(gfx::Rect(450,10, 100, 100)); | 106 widget->SetBounds(gfx::Rect(450,10, 100, 100)); |
| 99 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); | 107 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true); |
| 100 widget->Show(); | 108 widget->Show(); |
| 101 // Make sure the bounds is adjusted to be inside the work area. | 109 // Make sure the bounds is adjusted to be inside the work area. |
| 102 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString()); | 110 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString()); |
| 103 widget->CloseNow(); | 111 widget->CloseNow(); |
| 104 } | 112 } |
| 105 | 113 |
| 106 } // namespace | 114 } // namespace |
| OLD | NEW |