[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" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 12 | #include "ui/aura/focus_manager.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 13 | #include "ui/aura/root_window.h" |
| 14 | #include "ui/aura/test/event_generator.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 15 | #include "ui/aura/test/test_window_delegate.h" |
| 16 | #include "ui/aura/test/test_windows.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 17 | #include "ui/aura/window.h" |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 18 | #include "ui/aura/window_tracker.h" |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 19 | #include "ui/views/controls/menu/menu_controller.h" |
| 20 | #include "ui/views/widget/widget.h" |
| 21 | #include "ui/views/widget/widget_delegate.h" |
| 22 | |
| 23 | namespace ash { |
| 24 | namespace { |
| 25 | |
| 26 | class TestDelegate : public views::WidgetDelegateView { |
| 27 | public: |
| 28 | explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {} |
| 29 | virtual ~TestDelegate() {} |
| 30 | |
| 31 | // Overridden from views::WidgetDelegate: |
| 32 | virtual views::View* GetContentsView() OVERRIDE { |
| 33 | return this; |
| 34 | } |
| 35 | |
| 36 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 37 | return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE; |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | bool system_modal_; |
| 42 | DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 43 | }; |
| 44 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 45 | class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate { |
| 46 | public: |
| 47 | DeleteOnBlurDelegate() : window_(NULL) {} |
| 48 | virtual ~DeleteOnBlurDelegate() {} |
| 49 | |
| 50 | void set_window(aura::Window* window) { window_ = window; } |
| 51 | |
| 52 | // aura::test::TestWindowDelegate overrides: |
| 53 | virtual bool CanFocus() OVERRIDE { |
| 54 | return true; |
| 55 | } |
| 56 | virtual void OnBlur() OVERRIDE { |
| 57 | delete window_; |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | aura::Window* window_; |
| 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 64 | }; |
| 65 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 66 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 67 | views::Widget* widget = |
| 68 | views::Widget::CreateWindowWithBounds(NULL, bounds); |
| 69 | widget->Show(); |
| 70 | return widget; |
| 71 | } |
| 72 | |
| 73 | views::Widget* CreateModalWidget(const gfx::Rect& bounds) { |
| 74 | views::Widget* widget = |
| 75 | views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds); |
| 76 | widget->Show(); |
| 77 | return widget; |
| 78 | } |
| 79 | |
| 80 | aura::Window* GetModalContainer(aura::RootWindow* root_window) { |
| 81 | return Shell::GetContainer( |
| 82 | root_window, |
| 83 | ash::internal::kShellWindowId_SystemModalContainer); |
| 84 | } |
| 85 | |
| 86 | } // namespace |
| 87 | |
| 88 | namespace test { |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 89 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 90 | typedef test::AshTestBase RootWindowControllerTest; |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 91 | |
| 92 | TEST_F(RootWindowControllerTest, MoveWindows_Basic) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 93 | UpdateDisplay("600x600,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 94 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame^] | 95 | ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
| 96 | ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 97 | |
| 98 | views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100)); |
| 99 | EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 100 | EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 101 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 102 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 103 | |
| 104 | views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100)); |
| 105 | maximized->Maximize(); |
| 106 | EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow()); |
| 107 | #if !defined(OS_WIN) |
| 108 | // TODO(oshima): Window reports smaller screen size. Investigate why. |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 109 | EXPECT_EQ("600,0 500x500", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 110 | EXPECT_EQ("0,0 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 111 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
| 115 | minimized->Minimize(); |
| 116 | EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 117 | EXPECT_EQ("800,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 118 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 119 | |
| 120 | views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100)); |
| 121 | fullscreen->SetFullscreen(true); |
| 122 | EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow()); |
| 123 | #if !defined(OS_WIN) |
| 124 | // TODO(oshima): Window reports smaller screen size. Investigate why. |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 125 | EXPECT_EQ("600,0 500x500", |
[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 500x500", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 128 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 129 | #endif |
| 130 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 131 | // Make sure a window that will delete itself when losing focus |
| 132 | // will not crash. |
| 133 | aura::WindowTracker tracker; |
| 134 | DeleteOnBlurDelegate delete_on_blur_delegate; |
| 135 | aura::Window* d2 = aura::test::CreateTestWindowWithDelegate( |
| 136 | &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100), NULL); |
| 137 | delete_on_blur_delegate.set_window(d2); |
| 138 | root_windows[0]->GetFocusManager()->SetFocusedWindow( |
| 139 | d2, NULL); |
| 140 | tracker.Add(d2); |
| 141 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 142 | UpdateDisplay("600x600"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 143 | |
[email protected] | dbf835d8 | 2012-09-11 18:23:09 | [diff] [blame] | 144 | // d2 must have been deleted. |
| 145 | EXPECT_FALSE(tracker.Contains(d2)); |
| 146 | |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 147 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 148 | EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 149 | EXPECT_EQ("50,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 150 | normal->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 151 | |
[email protected] | eefd51b2 | 2012-09-25 20:26:24 | [diff] [blame^] | 152 | // Maximized area on primary display has 3px (given as |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 153 | // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom. |
| 154 | EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 155 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 156 | maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 7b675df61 | 2012-09-16 18:33:20 | [diff] [blame] | 157 | EXPECT_EQ("0,0 600x597", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 158 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 159 | |
| 160 | EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 161 | EXPECT_EQ("200,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 162 | minimized->GetWindowBoundsInScreen().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 163 | |
| 164 | EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow()); |
| 165 | EXPECT_TRUE(fullscreen->IsFullscreen()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 166 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 167 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 168 | EXPECT_EQ("0,0 600x600", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 169 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 170 | |
| 171 | // Test if the restore bounds are correctly updated. |
| 172 | wm::RestoreWindow(maximized->GetNativeView()); |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 173 | EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 174 | EXPECT_EQ("100,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 175 | maximized->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 176 | |
| 177 | fullscreen->SetFullscreen(false); |
| 178 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 179 | fullscreen->GetWindowBoundsInScreen().ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 180 | EXPECT_EQ("300,10 100x100", |
[email protected] | e2f64d10 | 2012-07-19 19:17:04 | [diff] [blame] | 181 | fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString()); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | TEST_F(RootWindowControllerTest, MoveWindows_Modal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 185 | UpdateDisplay("500x500,500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 186 | |
| 187 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 188 | // Emulate virtual screen coordinate system. |
| 189 | root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 190 | root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500)); |
| 191 | |
| 192 | views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100)); |
| 193 | EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow()); |
| 194 | EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView())); |
| 195 | |
| 196 | views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100)); |
| 197 | EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow()); |
| 198 | EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains( |
| 199 | modal->GetNativeView())); |
| 200 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 201 | |
| 202 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 203 | generator_1st.ClickLeftButton(); |
| 204 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 205 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 206 | UpdateDisplay("500x500"); |
[email protected] | f185312 | 2012-06-27 16:21:26 | [diff] [blame] | 207 | EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow()); |
| 208 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 209 | generator_1st.ClickLeftButton(); |
| 210 | EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView())); |
| 211 | } |
| 212 | |
| 213 | } // namespace test |
| 214 | } // namespace ash |