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