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