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