[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" |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame^] | 6 | #include "ash/display/display_manager.h" |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 7 | #include "ash/screen_ash.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 8 | #include "ash/shell.h" |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 9 | #include "ash/shell_window_ids.h" |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 10 | #include "ash/system/tray/system_tray.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 11 | #include "ash/test/ash_test_base.h" |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 12 | #include "ash/wm/coordinate_conversion.h" |
[email protected] | 7ae52500 | 2012-07-26 23:55:10 | [diff] [blame] | 13 | #include "ash/wm/property_util.h" |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 14 | #include "ash/wm/window_cycle_controller.h" |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 15 | #include "ash/wm/window_properties.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 16 | #include "ash/wm/window_util.h" |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 17 | #include "base/string_util.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 18 | #include "ui/aura/client/activation_client.h" |
| 19 | #include "ui/aura/client/capture_client.h" |
| 20 | #include "ui/aura/focus_manager.h" |
| 21 | #include "ui/aura/root_window.h" |
| 22 | #include "ui/aura/test/event_generator.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 23 | #include "ui/aura/test/test_windows.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 24 | #include "ui/aura/window.h" |
| 25 | #include "ui/base/cursor/cursor.h" |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 26 | #include "ui/base/events/event_handler.h" |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 27 | #include "ui/gfx/display.h" |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 28 | #include "ui/gfx/screen.h" |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 29 | #include "ui/views/controls/textfield/textfield.h" |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 30 | #include "ui/views/widget/widget.h" |
| 31 | #include "ui/views/widget/widget_delegate.h" |
| 32 | |
| 33 | namespace ash { |
| 34 | namespace { |
| 35 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 36 | views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
| 37 | const gfx::Rect& bounds, |
| 38 | bool child) { |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 39 | views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 40 | params.parent_widget = parent; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 41 | params.bounds = bounds; |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 42 | params.child = child; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 43 | views::Widget* widget = new views::Widget; |
| 44 | widget->Init(params); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 45 | widget->Show(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 46 | return widget; |
| 47 | } |
| 48 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 49 | views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 50 | return CreateTestWidgetWithParent(NULL, bounds, false); |
| 51 | } |
| 52 | |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 53 | void SetSecondaryDisplayLayout(DisplayLayout::Position position) { |
| 54 | DisplayController* display_controller = |
| 55 | Shell::GetInstance()->display_controller(); |
| 56 | DisplayLayout layout = display_controller->default_display_layout(); |
| 57 | layout.position = position; |
| 58 | display_controller->SetDefaultDisplayLayout(layout); |
| 59 | } |
| 60 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 61 | class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 62 | public: |
| 63 | ModalWidgetDelegate() {} |
| 64 | virtual ~ModalWidgetDelegate() {} |
| 65 | |
| 66 | // Overridden from views::WidgetDelegate: |
| 67 | virtual views::View* GetContentsView() OVERRIDE { |
| 68 | return this; |
| 69 | } |
| 70 | virtual ui::ModalType GetModalType() const OVERRIDE { |
| 71 | return ui::MODAL_TYPE_SYSTEM; |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | DISALLOW_COPY_AND_ASSIGN(ModalWidgetDelegate); |
| 76 | }; |
| 77 | |
[email protected] | 6bdf795 | 2012-11-14 10:10:58 | [diff] [blame^] | 78 | internal::DisplayManager* GetDisplayManager() { |
| 79 | return Shell::GetInstance()->display_manager(); |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 82 | // An event filter which moves the target window to the secondary root window |
| 83 | // at pre-handle phase of a mouse release event. |
| 84 | class MoveWindowByClickEventFilter : public ui::EventHandler { |
| 85 | public: |
| 86 | explicit MoveWindowByClickEventFilter(aura::Window* target) |
| 87 | : target_(target) {} |
| 88 | virtual ~MoveWindowByClickEventFilter() {} |
| 89 | |
| 90 | private: |
| 91 | // ui::EventHandler overrides: |
| 92 | virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE { |
| 93 | return ui::ER_UNHANDLED; |
| 94 | } |
| 95 | |
| 96 | virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 97 | if (event->type() == ui::ET_MOUSE_RELEASED) { |
| 98 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 99 | DCHECK_LT(1u, root_windows.size()); |
| 100 | root_windows[1]->AddChild(target_); |
| 101 | } |
| 102 | return ui::ER_UNHANDLED; |
| 103 | } |
| 104 | |
| 105 | virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { |
| 106 | return ui::ER_UNHANDLED; |
| 107 | } |
| 108 | |
| 109 | virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
| 110 | return ui::ER_UNHANDLED; |
| 111 | } |
| 112 | |
| 113 | virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
| 114 | return ui::ER_UNHANDLED; |
| 115 | } |
| 116 | |
| 117 | aura::Window* target_; |
| 118 | DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventFilter); |
| 119 | }; |
| 120 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 121 | } // namespace |
| 122 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 123 | typedef test::AshTestBase ExtendedDesktopTest; |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 124 | |
| 125 | // Test conditions that root windows in extended desktop mode |
| 126 | // must satisfy. |
| 127 | TEST_F(ExtendedDesktopTest, Basic) { |
[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(); |
| 130 | |
| 131 | // All root windows must have the root window controller. |
| 132 | ASSERT_EQ(2U, root_windows.size()); |
| 133 | for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| 134 | iter != root_windows.end(); ++iter) { |
[email protected] | 7ae52500 | 2012-07-26 23:55:10 | [diff] [blame] | 135 | EXPECT_TRUE(GetRootWindowController(*iter) != NULL); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 136 | } |
| 137 | // Make sure root windows share the same controllers. |
| 138 | EXPECT_EQ(root_windows[0]->GetFocusManager(), |
| 139 | root_windows[1]->GetFocusManager()); |
| 140 | EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), |
| 141 | aura::client::GetActivationClient(root_windows[1])); |
| 142 | EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
| 143 | aura::client::GetCaptureClient(root_windows[1])); |
| 144 | } |
| 145 | |
| 146 | TEST_F(ExtendedDesktopTest, Activation) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 147 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 148 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 149 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 150 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 151 | views::Widget* widget_on_2nd = |
| 152 | CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 153 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 154 | EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 155 | |
| 156 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
| 157 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 158 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
| 159 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 160 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 161 | aura::test::EventGenerator generator_2nd(root_windows[1]); |
| 162 | |
| 163 | // Clicking a window changes the active window and active root window. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 164 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 165 | generator_1st.ClickLeftButton(); |
| 166 | |
| 167 | EXPECT_EQ(widget_on_1st->GetNativeView(), |
| 168 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 169 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 170 | |
| 171 | generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
| 172 | generator_2nd.ClickLeftButton(); |
| 173 | |
| 174 | EXPECT_EQ(widget_on_2nd->GetNativeView(), |
| 175 | root_windows[0]->GetFocusManager()->GetFocusedWindow()); |
| 176 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | TEST_F(ExtendedDesktopTest, SystemModal) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 180 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 181 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 182 | |
| 183 | views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 184 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
[email protected] | 492533b3 | 2012-09-21 19:06:14 | [diff] [blame] | 185 | EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 186 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 187 | |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 188 | // Open system modal. Make sure it's on 2nd root window and active. |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 189 | views::Widget* modal_widget = views::Widget::CreateWindowWithBounds( |
| 190 | new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100)); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 191 | modal_widget->Show(); |
| 192 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 193 | EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
| 194 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 195 | |
[email protected] | 2e236a5 | 2012-06-27 22:21:47 | [diff] [blame] | 196 | // Clicking a widget on widget_on_1st display should not change activation. |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 197 | aura::test::EventGenerator generator_1st(root_windows[0]); |
| 198 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 199 | generator_1st.ClickLeftButton(); |
| 200 | EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 201 | EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 202 | |
| 203 | // Close system modal and so clicking a widget should work now. |
| 204 | modal_widget->Close(); |
| 205 | generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 206 | generator_1st.ClickLeftButton(); |
| 207 | EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 208 | EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 209 | } |
| 210 | |
| 211 | TEST_F(ExtendedDesktopTest, TestCursor) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 212 | UpdateDisplay("1000x600,600x400"); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 213 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 214 | EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); |
| 215 | EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); |
[email protected] | 151ffdff | 2012-09-11 20:18:35 | [diff] [blame] | 216 | Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy); |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 217 | EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); |
| 218 | EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); |
| 219 | } |
| 220 | |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 221 | TEST_F(ExtendedDesktopTest, TestCursorLocation) { |
| 222 | UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 223 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 224 | aura::Window::TestApi root_window0_test_api(root_windows[0]); |
| 225 | aura::Window::TestApi root_window1_test_api(root_windows[1]); |
| 226 | |
| 227 | root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 228 | EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 229 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 230 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 231 | root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 232 | EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 233 | EXPECT_FALSE(root_window0_test_api.ContainsMouse()); |
| 234 | EXPECT_TRUE(root_window1_test_api.ContainsMouse()); |
| 235 | root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 236 | EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
[email protected] | 718b26c | 2012-07-24 20:53:23 | [diff] [blame] | 237 | EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
| 238 | EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
| 239 | } |
| 240 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 241 | TEST_F(ExtendedDesktopTest, CycleWindows) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 242 | UpdateDisplay("700x500,500x500"); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 243 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 244 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 245 | WindowCycleController* controller = |
| 246 | Shell::GetInstance()->window_cycle_controller(); |
| 247 | |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 248 | views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 249 | EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 250 | views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 251 | EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); |
| 252 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 253 | |
| 254 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 255 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 256 | controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
| 257 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 258 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 259 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 260 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, false); |
| 261 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 262 | |
| 263 | // Cycle through all windows across root windows. |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 264 | views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 265 | EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow()); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 266 | views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100)); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 267 | EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow()); |
| 268 | |
| 269 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 270 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 271 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 272 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 273 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 274 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 275 | controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 276 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
| 277 | |
| 278 | // Backwards |
| 279 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
| 280 | EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
| 281 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 282 | EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
| 283 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 8fef743 | 2012-08-06 15:34:25 | [diff] [blame] | 284 | EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
| 285 | controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 286 | EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 290 | UpdateDisplay("700x500,500x500"); |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 291 | SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 292 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 293 | |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 294 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
| 295 | EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
| 296 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
| 297 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 298 | |
| 299 | // Zero origin. |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 300 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 301 | |
| 302 | // Out of range point should return the primary root window |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 303 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
| 304 | EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 308 | UpdateDisplay("700x500,500x500"); |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 309 | SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 310 | |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 311 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 312 | |
| 313 | // Containing rect. |
| 314 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 315 | wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 316 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 317 | wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 318 | |
| 319 | // Intersecting rect. |
| 320 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 321 | wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 322 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 323 | wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 324 | |
| 325 | // Zero origin. |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 326 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 327 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0))); |
[email protected] | 66b05eac | 2012-06-27 23:53:10 | [diff] [blame] | 328 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 329 | wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 330 | |
| 331 | // Empty rect. |
| 332 | EXPECT_EQ(root_windows[1], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 333 | wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 334 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 335 | wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 336 | |
| 337 | // Out of range rect should return the primary root window. |
| 338 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 339 | wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))); |
[email protected] | 20c5976 | 2012-06-23 01:10:24 | [diff] [blame] | 340 | EXPECT_EQ(root_windows[0], |
[email protected] | 7203a5e | 2012-08-06 18:27:46 | [diff] [blame] | 341 | wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))); |
[email protected] | 0f81f44 | 2012-06-22 06:20:27 | [diff] [blame] | 342 | } |
| 343 | |
[email protected] | 7f502eb | 2012-09-20 09:17:12 | [diff] [blame] | 344 | #if defined(OS_WIN) |
| 345 | // TODO(mazda): Re-enable this (http://crbug.com/150986). |
| 346 | #define MAYBE_Capture DISABLED_Capture |
| 347 | #else |
| 348 | #define MAYBE_Capture Capture |
| 349 | #endif |
| 350 | |
| 351 | TEST_F(ExtendedDesktopTest, MAYBE_Capture) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 352 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 353 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 354 | |
| 355 | aura::test::EventCountDelegate r1_d1; |
| 356 | aura::test::EventCountDelegate r1_d2; |
| 357 | aura::test::EventCountDelegate r2_d1; |
| 358 | |
| 359 | scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
| 360 | &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
| 361 | scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
| 362 | &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0])); |
| 363 | scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate( |
| 364 | &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1])); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 365 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 366 | r1_w1->SetCapture(); |
| 367 | |
| 368 | EXPECT_EQ(r1_w1.get(), |
| 369 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
| 370 | aura::test::EventGenerator generator2(root_windows[1]); |
| 371 | generator2.MoveMouseToCenterOf(r2_w1.get()); |
| 372 | generator2.ClickLeftButton(); |
| 373 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 374 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
[email protected] | b19ba4adf | 2012-09-07 16:13:29 | [diff] [blame] | 375 | // The mouse is outside. On chromeos, the mouse is warped to the |
| 376 | // dest root window, but it's not implemented on Win yet, so |
| 377 | // no mouse move event on Win. |
| 378 | #if defined(OS_WIN) |
| 379 | EXPECT_EQ("1 0 0", r1_d1.GetMouseMotionCountsAndReset()); |
| 380 | #else |
[email protected] | 7495e503 | 2012-09-07 15:31:45 | [diff] [blame] | 381 | EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | b19ba4adf | 2012-09-07 16:13:29 | [diff] [blame] | 382 | #endif |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 383 | EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset()); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 384 | // (15,15) on 1st display is (-985,15) on 2nd display. |
| 385 | generator2.MoveMouseTo(-985, 15); |
| 386 | EXPECT_EQ("0 1 0", r1_d1.GetMouseMotionCountsAndReset()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 387 | |
| 388 | r1_w2->SetCapture(); |
| 389 | EXPECT_EQ(r1_w2.get(), |
| 390 | aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
| 391 | generator2.MoveMouseBy(10, 10); |
| 392 | generator2.ClickLeftButton(); |
| 393 | EXPECT_EQ("0 0 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 394 | EXPECT_EQ("0 0", r2_d1.GetMouseButtonCountsAndReset()); |
| 395 | // mouse is already entered. |
| 396 | EXPECT_EQ("0 1 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 397 | EXPECT_EQ("1 1", r1_d2.GetMouseButtonCountsAndReset()); |
| 398 | |
| 399 | r1_w2->ReleaseCapture(); |
[email protected] | 36f56653 | 2012-09-19 04:07:24 | [diff] [blame] | 400 | EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 401 | generator2.MoveMouseTo(15, 15); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 402 | generator2.ClickLeftButton(); |
| 403 | EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
| 404 | EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
| 405 | // Make sure the mouse_moved_handler_ is properly reset. |
| 406 | EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
| 407 | EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
| 408 | } |
| 409 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 410 | TEST_F(ExtendedDesktopTest, MoveWindow) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 411 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 412 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 413 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 414 | |
| 415 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 416 | |
| 417 | d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
| 418 | EXPECT_EQ("1010,10 100x100", |
| 419 | d1->GetWindowBoundsInScreen().ToString()); |
| 420 | |
| 421 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 422 | |
| 423 | d1->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 424 | EXPECT_EQ("10,10 100x100", |
| 425 | d1->GetWindowBoundsInScreen().ToString()); |
| 426 | |
| 427 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 428 | |
| 429 | // Make sure the bounds which doesn't fit to the root window |
| 430 | // works correctly. |
| 431 | d1->SetBounds(gfx::Rect(1560, 30, 100, 100)); |
| 432 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 433 | EXPECT_EQ("1560,30 100x100", |
| 434 | d1->GetWindowBoundsInScreen().ToString()); |
| 435 | |
| 436 | // Setting outside of root windows will be moved to primary root window. |
| 437 | // TODO(oshima): This one probably should pick the closest root window. |
| 438 | d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
| 439 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | 2e98aaf7 | 2012-11-08 06:30:59 | [diff] [blame] | 442 | // Verifies if the mouse event arrives to the window even when the window |
| 443 | // moves to another root in a pre-target handler. See: crbug.com/157583 |
| 444 | TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { |
| 445 | UpdateDisplay("1000x600,600x400"); |
| 446 | |
| 447 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 448 | aura::test::EventCountDelegate delegate; |
| 449 | scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 450 | &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
| 451 | MoveWindowByClickEventFilter event_filter(window.get()); |
| 452 | window->AddPreTargetHandler(&event_filter); |
| 453 | aura::test::EventGenerator generator(root_windows[0], window.get()); |
| 454 | generator.ClickLeftButton(); |
| 455 | // Both mouse pressed and released arrive at the window and its delegate. |
| 456 | EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
| 457 | // Also event_filter moves the window to another root at mouse release. |
| 458 | EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 459 | } |
| 460 | |
[email protected] | 608f02f | 2012-10-25 05:53:33 | [diff] [blame] | 461 | // This test fails on the "Win Aura" bot: <http://crbug.com/157817>. |
| 462 | #if defined(OS_WIN) |
| 463 | #define MAYBE_MoveWindowToDisplay DISABLED_MoveWindowToDisplay |
| 464 | #else |
| 465 | #define MAYBE_MoveWindowToDisplay MoveWindowToDisplay |
| 466 | #endif |
| 467 | TEST_F(ExtendedDesktopTest, MAYBE_MoveWindowToDisplay) { |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 468 | UpdateDisplay("1000x1000,1000x1000"); |
| 469 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 470 | |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 471 | gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching( |
| 472 | root_windows[0]->GetBoundsInScreen()); |
| 473 | gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching( |
| 474 | root_windows[1]->GetBoundsInScreen()); |
[email protected] | e79f26e | 2012-08-09 07:12:48 | [diff] [blame] | 475 | EXPECT_NE(display0.id(), display1.id()); |
| 476 | |
| 477 | views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100)); |
| 478 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 479 | |
| 480 | // Move the window where the window spans both root windows. Since the second |
| 481 | // parameter is |display1|, the window should be shown on the secondary root. |
| 482 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 483 | display1); |
| 484 | EXPECT_EQ("500,10 1000x100", |
| 485 | d1->GetWindowBoundsInScreen().ToString()); |
| 486 | EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 487 | |
| 488 | // Move to the primary root. |
| 489 | d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
| 490 | display0); |
| 491 | EXPECT_EQ("500,10 1000x100", |
| 492 | d1->GetWindowBoundsInScreen().ToString()); |
| 493 | EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 494 | } |
| 495 | |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 496 | TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 497 | UpdateDisplay("1000x600,600x400"); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 498 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 499 | views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 500 | views::Widget* w1_t1 = CreateTestWidgetWithParent( |
| 501 | w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
| 502 | // Transient child of the transient child. |
| 503 | views::Widget* w1_t11 = CreateTestWidgetWithParent( |
| 504 | w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); |
| 505 | |
| 506 | views::Widget* w11 = CreateTestWidgetWithParent( |
| 507 | w1, gfx::Rect(10, 10, 40, 40), true /* child */); |
| 508 | views::Widget* w11_t1 = CreateTestWidgetWithParent( |
| 509 | w1, gfx::Rect(1300, 100, 80, 80), false /* transient */); |
| 510 | |
| 511 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 512 | EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow()); |
| 513 | EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow()); |
| 514 | EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow()); |
| 515 | EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow()); |
| 516 | EXPECT_EQ("50,50 50x50", |
| 517 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 518 | EXPECT_EQ("1200,70 30x30", |
| 519 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 520 | EXPECT_EQ("20,20 40x40", |
| 521 | w11->GetWindowBoundsInScreen().ToString()); |
| 522 | EXPECT_EQ("1300,100 80x80", |
| 523 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 524 | |
| 525 | w1->SetBounds(gfx::Rect(1100,10,100,100)); |
| 526 | |
| 527 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 528 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 529 | EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow()); |
| 530 | EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow()); |
| 531 | EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow()); |
| 532 | |
| 533 | EXPECT_EQ("1110,20 40x40", |
| 534 | w11->GetWindowBoundsInScreen().ToString()); |
| 535 | // Transient window's screen bounds stays the same. |
| 536 | EXPECT_EQ("50,50 50x50", |
| 537 | w1_t1->GetWindowBoundsInScreen().ToString()); |
| 538 | EXPECT_EQ("1200,70 30x30", |
| 539 | w1_t11->GetWindowBoundsInScreen().ToString()); |
| 540 | EXPECT_EQ("1300,100 80x80", |
| 541 | w11_t1->GetWindowBoundsInScreen().ToString()); |
| 542 | |
| 543 | // Transient window doesn't move between root window unless |
| 544 | // its transient parent moves. |
| 545 | w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
| 546 | EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 547 | EXPECT_EQ("10,50 50x50", |
| 548 | w1_t1->GetWindowBoundsInScreen().ToString()); |
[email protected] | f059c694 | 2012-07-21 14:27:57 | [diff] [blame] | 549 | } |
| 550 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 551 | namespace internal { |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 552 | // Test if the Window::ConvertPointToTarget works across root windows. |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 553 | // TODO(oshima): Move multiple display suport and this test to aura. |
| 554 | TEST_F(ExtendedDesktopTest, ConvertPoint) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 555 | UpdateDisplay("1000x600,600x400"); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 556 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 557 | gfx::Display& display_1 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 558 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 559 | EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
| 560 | gfx::Display& display_2 = |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 561 | GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 562 | EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); |
| 563 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 564 | aura::Window* d1 = |
| 565 | CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView(); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 566 | aura::Window* d2 = |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 567 | CreateTestWidget(gfx::Rect(1020, 20, 100, 100))->GetNativeView(); |
| 568 | EXPECT_EQ(root_windows[0], d1->GetRootWindow()); |
| 569 | EXPECT_EQ(root_windows[1], d2->GetRootWindow()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 570 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 571 | // Convert point in the Root2's window to the Root1's window Coord. |
| 572 | gfx::Point p(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 573 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 574 | EXPECT_EQ("1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 575 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 576 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 577 | EXPECT_EQ("1010,10", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 578 | |
| 579 | // Convert point in the Root1's window to the Root2's window Coord. |
| 580 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 581 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 582 | EXPECT_EQ("-1000,0", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 583 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 584 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 585 | EXPECT_EQ("-1010,-10", p.ToString()); |
| 586 | |
| 587 | // Move the 2nd display to the bottom and test again. |
[email protected] | edbfb8d | 2012-09-03 08:33:43 | [diff] [blame] | 588 | SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 589 | |
[email protected] | 3e4351b | 2012-08-09 04:04:16 | [diff] [blame] | 590 | display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 591 | EXPECT_EQ("0,600", display_2.bounds().origin().ToString()); |
| 592 | |
| 593 | // Convert point in Root2's window to Root1's window Coord. |
| 594 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 595 | aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 596 | EXPECT_EQ("0,600", p.ToString()); |
| 597 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 598 | aura::Window::ConvertPointToTarget(d2, d1, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 599 | EXPECT_EQ("10,610", p.ToString()); |
| 600 | |
| 601 | // Convert point in Root1's window to Root2's window Coord. |
| 602 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 603 | aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 604 | EXPECT_EQ("0,-600", p.ToString()); |
| 605 | p.SetPoint(0, 0); |
[email protected] | ca706098 | 2012-08-08 18:05:25 | [diff] [blame] | 606 | aura::Window::ConvertPointToTarget(d1, d2, &p); |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 607 | EXPECT_EQ("-10,-610", p.ToString()); |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 608 | } |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 609 | |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 610 | TEST_F(ExtendedDesktopTest, OpenSystemTray) { |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 611 | UpdateDisplay("500x600,600x400"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 612 | SystemTray* tray = ash::Shell::GetInstance()->system_tray(); |
| 613 | ASSERT_FALSE(tray->HasSystemBubble()); |
| 614 | |
| 615 | // Opens the tray by a dummy click event and makes sure that adding/removing |
| 616 | // displays doesn't break anything. |
| 617 | aura::test::EventGenerator event_generator( |
| 618 | ash::Shell::GetInstance()->GetPrimaryRootWindow(), |
| 619 | tray->GetWidget()->GetNativeWindow()); |
| 620 | event_generator.ClickLeftButton(); |
| 621 | EXPECT_TRUE(tray->HasSystemBubble()); |
| 622 | |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 623 | UpdateDisplay("500x600"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 624 | EXPECT_TRUE(tray->HasSystemBubble()); |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 625 | UpdateDisplay("500x600,600x400"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 626 | EXPECT_TRUE(tray->HasSystemBubble()); |
| 627 | |
| 628 | // Closes the tray and again makes sure that adding/removing displays doesn't |
| 629 | // break anything. |
| 630 | event_generator.ClickLeftButton(); |
| 631 | RunAllPendingInMessageLoop(); |
| 632 | |
| 633 | EXPECT_FALSE(tray->HasSystemBubble()); |
| 634 | |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 635 | UpdateDisplay("500x600"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 636 | EXPECT_FALSE(tray->HasSystemBubble()); |
[email protected] | 596c61c | 2012-10-29 17:29:43 | [diff] [blame] | 637 | UpdateDisplay("500x600,600x400"); |
[email protected] | 263898a | 2012-09-17 17:20:07 | [diff] [blame] | 638 | EXPECT_FALSE(tray->HasSystemBubble()); |
| 639 | } |
| 640 | |
[email protected] | 57804851 | 2012-09-19 20:01:24 | [diff] [blame] | 641 | TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { |
| 642 | UpdateDisplay("100x100,200x200"); |
| 643 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 644 | views::Widget* w1 = CreateTestWidgetWithParent( |
| 645 | NULL, gfx::Rect(10, 10, 50, 50), false); |
| 646 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 647 | w1->SetBounds(gfx::Rect(150, 10, 50, 50)); |
| 648 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 649 | |
| 650 | // The widget stays in the same root if kStayInSameRootWindowKey is set to |
| 651 | // true. |
| 652 | w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
| 653 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 654 | EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 655 | |
| 656 | // The widget should now move to the 1st root window without the property. |
| 657 | w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); |
| 658 | w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 659 | EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 660 | } |
| 661 | |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 662 | TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { |
| 663 | UpdateDisplay("100x100,200x200"); |
| 664 | Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 665 | |
| 666 | // Create normal windows on both displays. |
| 667 | views::Widget* widget1 = CreateTestWidget( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 668 | Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 669 | widget1->Show(); |
| 670 | EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); |
| 671 | views::Widget* widget2 = CreateTestWidget( |
| 672 | ScreenAsh::GetSecondaryDisplay().bounds()); |
| 673 | widget2->Show(); |
| 674 | EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow()); |
| 675 | |
| 676 | // Create a LockScreen window. |
| 677 | views::Widget* lock_widget = CreateTestWidget( |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 678 | Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
[email protected] | e67291f1 | 2012-10-10 05:52:38 | [diff] [blame] | 679 | views::Textfield* textfield = new views::Textfield; |
| 680 | lock_widget->SetContentsView(textfield); |
| 681 | |
| 682 | ash::Shell::GetContainer( |
| 683 | Shell::GetPrimaryRootWindow(), |
| 684 | ash::internal::kShellWindowId_LockScreenContainer)-> |
| 685 | AddChild(lock_widget->GetNativeView()); |
| 686 | lock_widget->Show(); |
| 687 | textfield->RequestFocus(); |
| 688 | |
| 689 | aura::FocusManager* focus_manager = root_windows[0]->GetFocusManager(); |
| 690 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 691 | |
| 692 | // The lock window should get events on both root windows. |
| 693 | aura::test::EventGenerator generator1(root_windows[0]); |
| 694 | generator1.PressKey(ui::VKEY_A, 0); |
| 695 | generator1.ReleaseKey(ui::VKEY_A, 0); |
| 696 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 697 | EXPECT_EQ("a", UTF16ToASCII(textfield->text())); |
| 698 | |
| 699 | aura::test::EventGenerator generator2(root_windows[1]); |
| 700 | generator2.PressKey(ui::VKEY_B, 0); |
| 701 | generator2.ReleaseKey(ui::VKEY_B, 0); |
| 702 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 703 | EXPECT_EQ("ab", UTF16ToASCII(textfield->text())); |
| 704 | |
| 705 | // Deleting 2nd display. The lock window still should get the events. |
| 706 | UpdateDisplay("100x100"); |
| 707 | generator2.PressKey(ui::VKEY_C, 0); |
| 708 | generator2.ReleaseKey(ui::VKEY_C, 0); |
| 709 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 710 | EXPECT_EQ("abc", UTF16ToASCII(textfield->text())); |
| 711 | |
| 712 | // Creating 2nd display again, and lock window still should get events |
| 713 | // on both root windows. |
| 714 | UpdateDisplay("100x100,200x200"); |
| 715 | root_windows = Shell::GetAllRootWindows(); |
| 716 | generator1.PressKey(ui::VKEY_D, 0); |
| 717 | generator1.ReleaseKey(ui::VKEY_D, 0); |
| 718 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 719 | EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); |
| 720 | |
| 721 | aura::test::EventGenerator generator22(root_windows[1]); |
| 722 | generator22.PressKey(ui::VKEY_E, 0); |
| 723 | generator22.ReleaseKey(ui::VKEY_E, 0); |
| 724 | EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); |
| 725 | EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); |
| 726 | } |
| 727 | |
[email protected] | a5e71c9 | 2012-06-22 22:09:08 | [diff] [blame] | 728 | } // namespace internal |
[email protected] | c39be8f | 2012-06-15 22:58:36 | [diff] [blame] | 729 | } // namespace ash |