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