[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 1 | // 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] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 5 | #include "ash/display/display_controller.h" |
| 6 | #include "ash/display/multi_display_manager.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 7 | #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 | |
| 19 | namespace ash { |
| 20 | namespace { |
| 21 | |
| 22 | class 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 | |
| 41 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 42 | views::Widget* widget = |
| 43 | views::Widget::CreateWindowWithBounds(NULL, bounds); |
| 44 | widget->Show(); |
| 45 | return widget; |
| 46 | } |
| 47 | |
| 48 | views::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 | |
| 55 | aura::Window* GetModalContainer(aura::RootWindow* root_window) { |
| 56 | return Shell::GetContainer( |
| 57 | root_window, |
| 58 | ash::internal::kShellWindowId_SystemModalContainer); |
| 59 | } |
| 60 | |
| 61 | } // namespace |
| 62 | |
| 63 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 64 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 65 | typedef test::AshTestBase RootWindowControllerTest; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 66 | |
| 67 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 68 | UpdateDisplay("600x600,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 69 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 70 | |
| 71 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 72 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 73 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 74 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 75 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 76 | |
| 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] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 82 | EXPECT_EQ("600,0 500x500", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 83 | EXPECT_EQ("0,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 84 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 85 | #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] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 90 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 91 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 92 | |
| 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] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 98 | EXPECT_EQ("600,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 99 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 100 | EXPECT_EQ("0,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 101 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 102 | #endif |
| 103 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 104 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 105 | |
| 106 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 107 | EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 108 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 109 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 110 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 111 | // Maximized area on primary display has 2px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 112 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
| 113 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 114 | EXPECT_EQ("0,0 600x598", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 115 | maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 116 | EXPECT_EQ("0,0 600x598", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 117 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 118 | |
| 119 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 120 | EXPECT_EQ("200,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 121 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 122 | |
| 123 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 124 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 125 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 126 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 127 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 128 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 129 | |
| 130 | // Test if the restore bounds are correctly updated. |
| 131 | wm::RestoreWindow(maximized->GetNativeView()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 132 | EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 133 | EXPECT_EQ("100,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 134 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 135 | |
| 136 | fullscreen->SetFullscreen(false); |
| 137 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 138 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 139 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 140 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 144 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 145 | |
| 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] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 165 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 166 | 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 |