platformKeys: Add per-extension sign permissions.
[chromium-blink-merge.git] / ash / wm / window_positioner_unittest.cc
blobaf320bc209fe4bb0d8cdf86aca9e6fa20b098555
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
3 // found in the LICENSE file.
5 #include "ash/wm/window_positioner.h"
7 #include "ash/shell.h"
8 #include "ash/shell/toplevel_window.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_positioner.h"
11 #include "ash/wm/window_state.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/gfx/screen.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_delegate.h"
17 namespace ash {
19 typedef test::AshTestBase WindowPositionerTest;
21 TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) {
22 if (!SupportsMultipleDisplays())
23 return;
24 // Tests that for a screen that is narrower than kForceMaximizeWidthLimit
25 // a new window gets maximized.
26 UpdateDisplay("400x400,500x500");
27 Shell::GetInstance()->set_target_root_window(
28 Shell::GetAllRootWindows()[1]);
29 shell::ToplevelWindow::CreateParams params;
30 params.can_resize = true;
31 params.can_maximize = true;
32 views::Widget* widget =
33 shell::ToplevelWindow::CreateToplevelWindow(params);
34 EXPECT_EQ("400,0 500x453", widget->GetWindowBoundsInScreen().ToString());
37 TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) {
38 if (!SupportsMultipleDisplays())
39 return;
40 #if defined(OS_WIN)
41 ash::WindowPositioner::SetMaximizeFirstWindow(true);
42 #endif
43 UpdateDisplay("400x400,1400x900");
44 aura::Window* second_root_window = Shell::GetAllRootWindows()[1];
45 Shell::GetInstance()->set_target_root_window(
46 second_root_window);
47 shell::ToplevelWindow::CreateParams params;
48 params.can_resize = true;
49 params.can_maximize = true;
50 views::Widget* widget =
51 shell::ToplevelWindow::CreateToplevelWindow(params);
52 gfx::Rect bounds = widget->GetWindowBoundsInScreen();
53 #if defined(OS_WIN)
54 EXPECT_TRUE(widget->IsMaximized());
55 #else
56 // The window should be in the 2nd display with the default size.
57 EXPECT_EQ("300x300", bounds.size().ToString());
58 #endif
59 EXPECT_TRUE(Shell::GetScreen()->GetDisplayNearestWindow(
60 second_root_window).bounds().Contains(bounds));
63 // Tests that second window inherits first window's maximized state as well as
64 // its restore bounds.
65 TEST_F(WindowPositionerTest, SecondMaximizedWindowHasProperRestoreSize) {
66 #if defined(OS_WIN)
67 ash::WindowPositioner::SetMaximizeFirstWindow(true);
68 #endif
69 UpdateDisplay("1400x900");
70 shell::ToplevelWindow::CreateParams params;
71 params.can_resize = true;
72 params.can_maximize = true;
73 views::Widget* widget1 =
74 shell::ToplevelWindow::CreateToplevelWindow(params);
75 gfx::Rect bounds = widget1->GetWindowBoundsInScreen();
77 #if !defined(OS_WIN)
78 // The window should have default size.
79 EXPECT_FALSE(widget1->IsMaximized());
80 EXPECT_EQ("300x300", bounds.size().ToString());
81 widget1->Maximize();
82 #endif
83 // The window should be maximized.
84 bounds = widget1->GetWindowBoundsInScreen();
85 EXPECT_TRUE(widget1->IsMaximized());
86 EXPECT_EQ("0,0 1400x853", bounds.ToString());
88 // Create another window
89 views::Widget* widget2 =
90 shell::ToplevelWindow::CreateToplevelWindow(params);
92 // The second window should be maximized.
93 bounds = widget2->GetWindowBoundsInScreen();
94 EXPECT_TRUE(widget2->IsMaximized());
95 EXPECT_EQ("0,0 1400x853", bounds.ToString());
97 widget2->Restore();
98 // Second window's restored size should be set to default size.
99 bounds = widget2->GetWindowBoundsInScreen();
100 EXPECT_EQ("300x300", bounds.size().ToString());
103 namespace {
105 // A WidgetDelegate that returns the out of display saved bounds.
106 class OutOfDisplayDelegate : public views::WidgetDelegate {
107 public:
108 explicit OutOfDisplayDelegate(views::Widget* widget) : widget_(widget) {}
109 ~OutOfDisplayDelegate() override {}
111 // Overridden from WidgetDelegate:
112 void DeleteDelegate() override { delete this; }
113 views::Widget* GetWidget() override { return widget_; }
114 const views::Widget* GetWidget() const override { return widget_; }
115 bool GetSavedWindowPlacement(const views::Widget* widget,
116 gfx::Rect* bounds,
117 ui::WindowShowState* show_state) const override {
118 bounds->SetRect(450, 10, 100, 100);
119 *show_state = ui::SHOW_STATE_NORMAL;
120 return true;
123 private:
124 views::Widget* widget_;
126 DISALLOW_COPY_AND_ASSIGN(OutOfDisplayDelegate);
129 } // namespace
131 TEST_F(WindowPositionerTest, EnsureMinimumVisibility) {
132 if (!SupportsHostWindowResize())
133 return;
135 UpdateDisplay("400x400");
136 views::Widget* widget = new views::Widget();
137 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
138 params.delegate = new OutOfDisplayDelegate(widget);
139 params.context = Shell::GetPrimaryRootWindow();
140 widget->Init(params);
141 widget->SetBounds(gfx::Rect(450,10, 100, 100));
142 wm::GetWindowState(widget->GetNativeView())->set_minimum_visibility(true);
143 widget->Show();
144 // Make sure the bounds is adjusted to be inside the work area.
145 EXPECT_EQ("390,10 100x100", widget->GetWindowBoundsInScreen().ToString());
146 widget->CloseNow();
149 } // namespace