blob: 12b27e82b419d272393630c50dc5d7b4eb02bb0c [file] [log] [blame]
[email protected]f1853122012-06-27 16:21:261// Copyright (c) 2012 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.
4
[email protected]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
6#include "ash/display/multi_display_manager.h"
[email protected]f1853122012-06-27 16:21:267#include "ash/shell.h"
8#include "ash/shell_window_ids.h"
9#include "ash/test/ash_test_base.h"
10#include "ash/wm/window_util.h"
11#include "ui/aura/env.h"
12#include "ui/aura/root_window.h"
13#include "ui/aura/test/event_generator.h"
14#include "ui/aura/window.h"
15#include "ui/views/controls/menu/menu_controller.h"
16#include "ui/views/widget/widget.h"
17#include "ui/views/widget/widget_delegate.h"
18
19namespace ash {
20namespace {
21
22class TestDelegate : public views::WidgetDelegateView {
23 public:
24 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
25 virtual ~TestDelegate() {}
26
27 // Overridden from views::WidgetDelegate:
28 virtual views::View* GetContentsView() OVERRIDE {
29 return this;
30 }
31
32 virtual ui::ModalType GetModalType() const OVERRIDE {
33 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
34 }
35
36 private:
37 bool system_modal_;
38 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
39};
40
41views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
42 views::Widget* widget =
43 views::Widget::CreateWindowWithBounds(NULL, bounds);
44 widget->Show();
45 return widget;
46}
47
48views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
49 views::Widget* widget =
50 views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds);
51 widget->Show();
52 return widget;
53}
54
55aura::Window* GetModalContainer(aura::RootWindow* root_window) {
56 return Shell::GetContainer(
57 root_window,
58 ash::internal::kShellWindowId_SystemModalContainer);
59}
60
61} // namespace
62
63namespace test {
[email protected]f1853122012-06-27 16:21:2664
[email protected]3e4351b2012-08-09 04:04:1665typedef test::AshTestBase RootWindowControllerTest;
[email protected]f1853122012-06-27 16:21:2666
67TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
[email protected]f634dd32012-07-23 22:49:0768 UpdateDisplay("600x600,500x500");
[email protected]f1853122012-06-27 16:21:2669 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:2670
71 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
72 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:0473 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:0674 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:0475 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:2676
77 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
78 maximized->Maximize();
79 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
80#if !defined(OS_WIN)
81 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]e2f64d102012-07-19 19:17:0482 EXPECT_EQ("600,0 500x500", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:0683 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:0484 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:2685#endif
86
87 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
88 minimized->Minimize();
89 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:0690 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:0491 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:2692
93 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
94 fullscreen->SetFullscreen(true);
95 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
96#if !defined(OS_WIN)
97 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]8d625fb2012-07-18 16:40:0698 EXPECT_EQ("600,0 500x500",
[email protected]e2f64d102012-07-19 19:17:0499 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06100 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04101 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26102#endif
103
[email protected]f634dd32012-07-23 22:49:07104 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26105
106 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04107 EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06108 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04109 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26110
[email protected]2e236a52012-06-27 22:21:47111 // Maximized area on primary display has 2px (given as
[email protected]f1853122012-06-27 16:21:26112 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
113 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06114 EXPECT_EQ("0,0 600x598",
[email protected]e2f64d102012-07-19 19:17:04115 maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06116 EXPECT_EQ("0,0 600x598",
[email protected]e2f64d102012-07-19 19:17:04117 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26118
119 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06120 EXPECT_EQ("200,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04121 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26122
123 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
124 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06125 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04126 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06127 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04128 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06129
130 // Test if the restore bounds are correctly updated.
131 wm::RestoreWindow(maximized->GetNativeView());
[email protected]e2f64d102012-07-19 19:17:04132 EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06133 EXPECT_EQ("100,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04134 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06135
136 fullscreen->SetFullscreen(false);
137 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04138 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06139 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04140 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26141}
142
143TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
[email protected]f634dd32012-07-23 22:49:07144 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26145
146 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
147 // Emulate virtual screen coordinate system.
148 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
149 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
150
151 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
152 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
153 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
154
155 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
156 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
157 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
158 modal->GetNativeView()));
159 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
160
161 aura::test::EventGenerator generator_1st(root_windows[0]);
162 generator_1st.ClickLeftButton();
163 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
164
[email protected]f634dd32012-07-23 22:49:07165 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26166 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
167 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
168 generator_1st.ClickLeftButton();
169 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
170}
171
172} // namespace test
173} // namespace ash