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