[email protected] | c39be8f | 2012-06-15 22:58:36 | [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] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 7 | #include "ash/shell.h" |
| 8 | #include "ash/test/ash_test_base.h" |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 9 | #include "ash/wm/coordinate_conversion.h" |
[email protected] | 7ae52500 | 2012-07-26 23:55:10 | [diff] [blame] | 10 | #include "ash/wm/property_util.h" |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 11 | #include "ash/wm/window_cycle_controller.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 12 | #include "ash/wm/window_util.h" |
| 13 | #include "ui/aura/client/activation_client.h" |
| 14 | #include "ui/aura/client/capture_client.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 15 | #include "ui/aura/env.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 16 | #include "ui/aura/focus_manager.h" |
| 17 | #include "ui/aura/root_window.h" |
| 18 | #include "ui/aura/test/event_generator.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 19 | #include "ui/aura/test/test_windows.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 20 | #include "ui/aura/window.h" |
| 21 | #include "ui/base/cursor/cursor.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 22 | #include "ui/gfx/display.h" |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 23 | #include "ui/gfx/screen.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 24 | #include "ui/views/widget/widget.h" |
| 25 | #include "ui/views/widget/widget_delegate.h" |
| 26 | |
| 27 | namespace ash { |
| 28 | namespace { |
| 29 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 30 | views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
| 31 | const gfx::Rect& bounds, |
| 32 | bool child) { |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 33 | views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 34 | params.parent_widget = parent; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 35 | params.bounds = bounds; |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 36 | params.child = child; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 37 | views::Widget* widget = new views::Widget; |
| 38 | widget->Init(params); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 39 | widget->Show(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 40 | return widget; |
| 41 | } |
| 42 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 43 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 44 | return CreateTestWidgetWithParent(NULL, bounds, false); |
| 45 | } |
| 46 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 47 | class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 48 | public: |
| 49 | ModalWidgetDelegate() {} |
| 50 | virtual ~ModalWidgetDelegate() {} |
| 51 | |
| 52 | // Overridden from views::WidgetDelegate: |
| 53 | virtual views::View* GetContentsView() OVERRIDE { |
| 54 | return this; |
| 55 | } |
| 56 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 57 | return ui::MODAL_TYPE_SYSTEM; |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
| 62 | }; |
| 63 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 64 | internal::MultiDisplayManager* GetDisplayManager() { |
| 65 | return static_cast<internal::MultiDisplayManager*>( |
| 66 | aura::Env::GetInstance()->display_manager()); |
| 67 | } |
| 68 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 69 | } // namespace |
| 70 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 71 | typedef test::AshTestBase ExtendedDesktopTest; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 72 | |
| 73 | // Test conditions that root windows in extended desktop mode |
| 74 | // must satisfy. |
| 75 | TEST_F(ExtendedDesktopTest, Basic) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 76 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 77 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 78 | |
| 79 | // All root windows must have the root window controller. |
| 80 | ASSERT_EQ(2U, root_windows.size()); |
| 81 | for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| 82 | iter != root_windows.end(); ++iter) { |
[email protected] | 7ae52500 | 2012-07-26 23:55:10 | [diff] [blame] | 83 | EXPECT_TRUE(GetRootWindowController(*iter) != NULL); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 84 | } |
| 85 | // Make sure root windows share the same controllers. |
| 86 | EXPECT_EQ(root_windows[0]->GetFocusManager(), |
| 87 | root_windows[1]->GetFocusManager()); |
| 88 | EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), |
| 89 | aura::client::GetActivationClient(root_windows[1])); |
| 90 | EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
| 91 | aura::client::GetCaptureClient(root_windows[1])); |
| 92 | } |
| 93 | |
| 94 | TEST_F(ExtendedDesktopTest, Activation) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 95 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 96 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 97 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 98 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 99 | views::Widget* widget_on_2nd = |
| 100 | CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 101 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 102 | EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 103 | |
| 104 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
| 105 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 106 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
| 107 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 108 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 109 | aura::test::EventGenerator generator_2nd(root_windows[1]); |
| 110 | |
| 111 | // Clicking a window changes the active window and active root window. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 112 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 113 | generator_1st.ClickLeftButton(); |
| 114 | |
| 115 | EXPECT_EQ(widget_on_1st->GetNativeView(), |
| 116 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 117 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 118 | |
| 119 | generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
| 120 | generator_2nd.ClickLeftButton(); |
| 121 | |
| 122 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
| 123 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 124 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | TEST_F(ExtendedDesktopTest, SystemModal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 128 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 129 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 130 | |
| 131 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 132 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 133 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 134 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 135 | // Open system modal. Make sure it's on 2nd root window and active. |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 136 | views::Widget* modal_widget = views::Widget::CreateWindowWithBounds( |
| 137 | new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 138 | modal_widget->Show(); |
| 139 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 140 | EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
| 141 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 142 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 143 | // Clicking a widget on widget_on_1st display should not change activation. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 144 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 145 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 146 | generator_1st.ClickLeftButton(); |
| 147 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 148 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 149 | |
| 150 | // Close system modal and so clicking a widget should work now. |
| 151 | modal_widget->Close(); |
| 152 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 153 | generator_1st.ClickLeftButton(); |
| 154 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 155 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 156 | } |
| 157 | |
| 158 | TEST_F(ExtendedDesktopTest, TestCursor) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 159 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 160 | Shell::GetInstance()->ShowCursor(false); |
| 161 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 162 | EXPECT_FALSE(root_windows[0]->cursor_shown()); |
| 163 | EXPECT_FALSE(root_windows[1]->cursor_shown()); |
| 164 | Shell::GetInstance()->ShowCursor(true); |
| 165 | EXPECT_TRUE(root_windows[0]->cursor_shown()); |
| 166 | EXPECT_TRUE(root_windows[1]->cursor_shown()); |
| 167 | |
| 168 | EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); |
| 169 | EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); |
| 170 | Shell::GetInstance()->SetCursor(ui::kCursorCopy); |
| 171 | EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); |
| 172 | EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); |
| 173 | } |
| 174 | |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 175 | TEST_F(ExtendedDesktopTest, TestCursorLocation) { |
| 176 | UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 177 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 178 | aura::Window::TestApi root_window0_test_api(root_windows[0]); |
| 179 | aura::Window::TestApi root_window1_test_api(root_windows[1]); |
| 180 | |
| 181 | root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); |
| 182 | EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString()); |
| 183 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 184 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 185 | root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); |
| 186 | EXPECT_EQ("1010,20", gfx::Screen::GetCursorScreenPoint().ToString()); |
| 187 | EXPECT_FALSE(root_window0_test_api.ContainsMouse()); |
| 188 | EXPECT_TRUE(root_window1_test_api.ContainsMouse()); |
| 189 | root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); |
| 190 | EXPECT_EQ("20,10", gfx::Screen::GetCursorScreenPoint().ToString()); |
| 191 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 192 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 193 | } |
| 194 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 195 | TEST_F(ExtendedDesktopTest, CycleWindows) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 196 | UpdateDisplay("700x500,500x500"); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 197 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 198 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 199 | WindowCycleController* controller = |
| 200 | Shell::GetInstance()->window_cycle_controller(); |
| 201 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 202 | views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 203 | EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 204 | views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 205 | EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); |
| 206 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 207 | |
| 208 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 209 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 210 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 211 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 212 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 213 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 214 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 215 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 216 | |
| 217 | // Cycle through all windows across root windows. |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 218 | views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 219 | EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 220 | views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 221 | EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow()); |
| 222 | |
| 223 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 224 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 225 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 226 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 227 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 228 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 229 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 230 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
| 231 | |
| 232 | // Backwards |
| 233 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 234 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 235 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 236 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 237 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 238 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 239 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 240 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 244 | UpdateDisplay("700x500,500x500"); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 245 | Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( |
| 246 | internal::DisplayController::LEFT); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 247 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 248 | |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 249 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
| 250 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
| 251 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
| 252 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 253 | |
| 254 | // Zero origin. |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 255 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 256 | |
| 257 | // Out of range point should return the primary root window |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 258 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
| 259 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 263 | UpdateDisplay("700x500,500x500"); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 264 | Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( |
| 265 | internal::DisplayController::LEFT); |
| 266 | |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 267 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 268 | |
| 269 | // Containing rect. |
| 270 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 271 | wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 272 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 273 | wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 274 | |
| 275 | // Intersecting rect. |
| 276 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 277 | wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 278 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 279 | wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 280 | |
| 281 | // Zero origin. |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 282 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 283 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 284 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 285 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 286 | |
| 287 | // Empty rect. |
| 288 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 289 | wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 290 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 291 | wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 292 | |
| 293 | // Out of range rect should return the primary root window. |
| 294 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 295 | wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 296 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 297 | wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 300 | TEST_F(ExtendedDesktopTest, Capture) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 301 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 302 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 303 | |
| 304 | aura::test::EventCountDelegate r1_d1; |
| 305 | aura::test::EventCountDelegate r1_d2; |
| 306 | aura::test::EventCountDelegate r2_d1; |
| 307 | |
| 308 | scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
| 309 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
| 310 | scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
| 311 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
| 312 | scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
| 313 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 314 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 315 | r1_w1->SetCapture(); |
| 316 | |
| 317 | EXPECT_EQ(r1_w1.get(), |
| 318 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
| 319 | aura::test::EventGenerator generator2(root_windows[1]); |
| 320 | generator2.MoveMouseToCenterOf(r2_w1.get()); |
| 321 | generator2.ClickLeftButton(); |
| 322 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 323 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 324 | // The mouse is outside, so no move event will be sent. |
| 325 | EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 326 | EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 327 | // (15,15) on 1st display is (-985,15) on 2nd display. |
| 328 | generator2.MoveMouseTo(-985, 15); |
| 329 | EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 330 | |
| 331 | r1_w2->SetCapture(); |
| 332 | EXPECT_EQ(r1_w2.get(), |
| 333 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
| 334 | generator2.MoveMouseBy(10, 10); |
| 335 | generator2.ClickLeftButton(); |
| 336 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 337 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
| 338 | // mouse is already entered. |
| 339 | EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 340 | EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset()); |
| 341 | |
| 342 | r1_w2->ReleaseCapture(); |
| 343 | EXPECT_EQ(NULL, |
| 344 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 345 | generator2.MoveMouseTo(15, 15); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 346 | generator2.ClickLeftButton(); |
| 347 | EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 348 | EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
| 349 | // Make sure the mouse_moved_handler_ is properly reset. |
| 350 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 351 | EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
| 352 | } |
| 353 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 354 | TEST_F(ExtendedDesktopTest, MoveWindow) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 355 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 356 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 357 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 358 | |
| 359 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 360 | |
| 361 | d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
| 362 | EXPECT_EQ("1010,10 100x100", |
| 363 | d1->GetWindowBoundsInScreen().ToString()); |
| 364 | |
| 365 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 366 | |
| 367 | d1->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 368 | EXPECT_EQ("10,10 100x100", |
| 369 | d1->GetWindowBoundsInScreen().ToString()); |
| 370 | |
| 371 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 372 | |
| 373 | // Make sure the bounds which doesn't fit to the root window |
| 374 | // works correctly. |
| 375 | d1->SetBounds(gfx::Rect(1560, 30, 100, 100)); |
| 376 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 377 | EXPECT_EQ("1560,30 100x100", |
| 378 | d1->GetWindowBoundsInScreen().ToString()); |
| 379 | |
| 380 | // Setting outside of root windows will be moved to primary root window. |
| 381 | // TODO(oshima): This one probably should pick the closest root window. |
| 382 | d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
| 383 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 387 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 388 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 389 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 390 | views::Widget* w1_t1 = CreateTestWidgetWithParent( |
| 391 | w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
| 392 | // Transient child of the transient child. |
| 393 | views::Widget* w1_t11 = CreateTestWidgetWithParent( |
| 394 | w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); |
| 395 | |
| 396 | views::Widget* w11 = CreateTestWidgetWithParent( |
| 397 | w1, gfx::Rect(10, 10, 40, 40), true /* child */); |
| 398 | views::Widget* w11_t1 = CreateTestWidgetWithParent( |
| 399 | w1, gfx::Rect(1300, 100, 80, 80), false /* transient */); |
| 400 | |
| 401 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 402 | EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow()); |
| 403 | EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow()); |
| 404 | EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow()); |
| 405 | EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow()); |
| 406 | EXPECT_EQ("50,50 50x50", |
| 407 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 408 | EXPECT_EQ("1200,70 30x30", |
| 409 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 410 | EXPECT_EQ("20,20 40x40", |
| 411 | w11->GetWindowBoundsInScreen().ToString()); |
| 412 | EXPECT_EQ("1300,100 80x80", |
| 413 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 414 | |
| 415 | w1->SetBounds(gfx::Rect(1100,10,100,100)); |
| 416 | |
| 417 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 418 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 419 | EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow()); |
| 420 | EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow()); |
| 421 | EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow()); |
| 422 | |
| 423 | EXPECT_EQ("1110,20 40x40", |
| 424 | w11->GetWindowBoundsInScreen().ToString()); |
| 425 | // Transient window's screen bounds stays the same. |
| 426 | EXPECT_EQ("50,50 50x50", |
| 427 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 428 | EXPECT_EQ("1200,70 30x30", |
| 429 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 430 | EXPECT_EQ("1300,100 80x80", |
| 431 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 432 | |
| 433 | // Transient window doesn't move between root window unless |
| 434 | // its transient parent moves. |
| 435 | w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
| 436 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 437 | EXPECT_EQ("10,50 50x50", |
| 438 | w1_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 441 | namespace internal { |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 442 | // Test if the Window::ConvertPointToTarget works across root windows. |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 443 | // TODO(oshima): Move multiple display suport and this test to aura. |
| 444 | TEST_F(ExtendedDesktopTest, ConvertPoint) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 445 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 446 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 447 | gfx::Display& display_1 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 448 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 449 | EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
| 450 | gfx::Display& display_2 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 451 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 452 | EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); |
| 453 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 454 | aura::Window* d1 = |
| 455 | CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 456 | aura::Window* d2 = |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 457 | CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView(); |
| 458 | EXPECT_EQ(root_windows[0], d1->GetRootWindow()); |
| 459 | EXPECT_EQ(root_windows[1], d2->GetRootWindow()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 460 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 461 | // Convert point in the Root2's window to the Root1's window Coord. |
| 462 | gfx::Point p(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 463 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 464 | EXPECT_EQ("1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 465 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 466 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 467 | EXPECT_EQ("1010,10", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 468 | |
| 469 | // Convert point in the Root1's window to the Root2's window Coord. |
| 470 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 471 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 472 | EXPECT_EQ("-1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 473 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 474 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 475 | EXPECT_EQ("-1010,-10", p.ToString()); |
| 476 | |
| 477 | // Move the 2nd display to the bottom and test again. |
| 478 | Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( |
| 479 | internal::DisplayController::BOTTOM); |
| 480 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame^] | 481 | display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 482 | EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); |
| 483 | |
| 484 | // Convert point in Root2's window to Root1's window Coord. |
| 485 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 486 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 487 | EXPECT_EQ("0,600", p.ToString()); |
| 488 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 489 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 490 | EXPECT_EQ("10,610", p.ToString()); |
| 491 | |
| 492 | // Convert point in Root1's window to Root2's window Coord. |
| 493 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 494 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 495 | EXPECT_EQ("0,-600", p.ToString()); |
| 496 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 497 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 498 | EXPECT_EQ("-10,-610", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 499 | } |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 500 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 501 | } // namespace internal |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 502 | } // namespace ash |