blob: 213cb8a50e4d2642b60478a26030f12ec91e1796 [file] [log] [blame]
[email protected]c39be8f2012-06-15 22:58:361// 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]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
6#include "ash/display/multi_display_manager.h"
[email protected]e67291f12012-10-10 05:52:387#include "ash/screen_ash.h"
[email protected]c39be8f2012-06-15 22:58:368#include "ash/shell.h"
[email protected]e67291f12012-10-10 05:52:389#include "ash/shell_window_ids.h"
[email protected]263898a2012-09-17 17:20:0710#include "ash/system/tray/system_tray.h"
[email protected]c39be8f2012-06-15 22:58:3611#include "ash/test/ash_test_base.h"
[email protected]7203a5e2012-08-06 18:27:4612#include "ash/wm/coordinate_conversion.h"
[email protected]7ae525002012-07-26 23:55:1013#include "ash/wm/property_util.h"
[email protected]0f81f442012-06-22 06:20:2714#include "ash/wm/window_cycle_controller.h"
[email protected]578048512012-09-19 20:01:2415#include "ash/wm/window_properties.h"
[email protected]c39be8f2012-06-15 22:58:3616#include "ash/wm/window_util.h"
[email protected]e67291f12012-10-10 05:52:3817#include "base/string_util.h"
[email protected]c39be8f2012-06-15 22:58:3618#include "ui/aura/client/activation_client.h"
19#include "ui/aura/client/capture_client.h"
[email protected]a5e71c92012-06-22 22:09:0820#include "ui/aura/env.h"
[email protected]c39be8f2012-06-15 22:58:3621#include "ui/aura/focus_manager.h"
22#include "ui/aura/root_window.h"
23#include "ui/aura/test/event_generator.h"
[email protected]a5e71c92012-06-22 22:09:0824#include "ui/aura/test/test_windows.h"
[email protected]c39be8f2012-06-15 22:58:3625#include "ui/aura/window.h"
26#include "ui/base/cursor/cursor.h"
[email protected]a5e71c92012-06-22 22:09:0827#include "ui/gfx/display.h"
[email protected]718b26c2012-07-24 20:53:2328#include "ui/gfx/screen.h"
[email protected]e67291f12012-10-10 05:52:3829#include "ui/views/controls/textfield/textfield.h"
[email protected]c39be8f2012-06-15 22:58:3630#include "ui/views/widget/widget.h"
31#include "ui/views/widget/widget_delegate.h"
32
33namespace ash {
34namespace {
35
[email protected]f059c6942012-07-21 14:27:5736views::Widget* CreateTestWidgetWithParent(views::Widget* parent,
37 const gfx::Rect& bounds,
38 bool child) {
[email protected]c39be8f2012-06-15 22:58:3639 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
[email protected]f059c6942012-07-21 14:27:5740 params.parent_widget = parent;
[email protected]c39be8f2012-06-15 22:58:3641 params.bounds = bounds;
[email protected]f059c6942012-07-21 14:27:5742 params.child = child;
[email protected]c39be8f2012-06-15 22:58:3643 views::Widget* widget = new views::Widget;
44 widget->Init(params);
[email protected]0f81f442012-06-22 06:20:2745 widget->Show();
[email protected]c39be8f2012-06-15 22:58:3646 return widget;
47}
48
[email protected]f059c6942012-07-21 14:27:5749views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
50 return CreateTestWidgetWithParent(NULL, bounds, false);
51}
52
[email protected]edbfb8d2012-09-03 08:33:4353void 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]c39be8f2012-06-15 22:58:3661class 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]3e4351b2012-08-09 04:04:1678internal::MultiDisplayManager* GetDisplayManager() {
79 return static_cast<internal::MultiDisplayManager*>(
80 aura::Env::GetInstance()->display_manager());
81}
82
[email protected]c39be8f2012-06-15 22:58:3683} // namespace
84
[email protected]3e4351b2012-08-09 04:04:1685typedef test::AshTestBase ExtendedDesktopTest;
[email protected]c39be8f2012-06-15 22:58:3686
87// Test conditions that root windows in extended desktop mode
88// must satisfy.
89TEST_F(ExtendedDesktopTest, Basic) {
[email protected]f634dd32012-07-23 22:49:0790 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:3691 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]7ae525002012-07-26 23:55:1097 EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
[email protected]c39be8f2012-06-15 22:58:3698 }
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
108TEST_F(ExtendedDesktopTest, Activation) {
[email protected]f634dd32012-07-23 22:49:07109 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36110 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
111
[email protected]c39be8f2012-06-15 22:58:36112 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]f634dd32012-07-23 22:49:07113 views::Widget* widget_on_2nd =
114 CreateTestWidget(gfx::Rect(1200, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36115 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]f634dd32012-07-23 22:49:07116 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36117
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]f634dd32012-07-23 22:49:07122 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]c39be8f2012-06-15 22:58:36126 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]f634dd32012-07-23 22:49:07132
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]c39be8f2012-06-15 22:58:36139}
140
141TEST_F(ExtendedDesktopTest, SystemModal) {
[email protected]f634dd32012-07-23 22:49:07142 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36143 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36144
145 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36146 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));
[email protected]492533b32012-09-21 19:06:14147 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow());
[email protected]c39be8f2012-06-15 22:58:36148 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow());
149
[email protected]c39be8f2012-06-15 22:58:36150 // Open system modal. Make sure it's on 2nd root window and active.
[email protected]f634dd32012-07-23 22:49:07151 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds(
152 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100));
[email protected]c39be8f2012-06-15 22:58:36153 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]2e236a52012-06-27 22:21:47158 // Clicking a widget on widget_on_1st display should not change activation.
[email protected]c39be8f2012-06-15 22:58:36159 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
173TEST_F(ExtendedDesktopTest, TestCursor) {
[email protected]f634dd32012-07-23 22:49:07174 UpdateDisplay("1000x600,600x400");
[email protected]c39be8f2012-06-15 22:58:36175 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]c39be8f2012-06-15 22:58:36176 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]151ffdff2012-09-11 20:18:35178 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy);
[email protected]c39be8f2012-06-15 22:58:36179 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]718b26c2012-07-24 20:53:23183TEST_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]ffabb1e2012-10-12 19:51:17190 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23191 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]ffabb1e2012-10-12 19:51:17194 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23195 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]ffabb1e2012-10-12 19:51:17198 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString());
[email protected]718b26c2012-07-24 20:53:23199 EXPECT_TRUE(root_window0_test_api.ContainsMouse());
200 EXPECT_FALSE(root_window1_test_api.ContainsMouse());
201}
202
[email protected]0f81f442012-06-22 06:20:27203TEST_F(ExtendedDesktopTest, CycleWindows) {
[email protected]f634dd32012-07-23 22:49:07204 UpdateDisplay("700x500,500x500");
[email protected]0f81f442012-06-22 06:20:27205 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24206
[email protected]0f81f442012-06-22 06:20:27207 WindowCycleController* controller =
208 Shell::GetInstance()->window_cycle_controller();
209
[email protected]0f81f442012-06-22 06:20:27210 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100));
211 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24212 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
[email protected]0f81f442012-06-22 06:20:27213 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]20c59762012-06-23 01:10:24226 views::Widget* d1_w2 = CreateTestWidget(gfx::Rect(10, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27227 EXPECT_EQ(root_windows[0], d1_w2->GetNativeView()->GetRootWindow());
[email protected]20c59762012-06-23 01:10:24228 views::Widget* d2_w2 = CreateTestWidget(gfx::Rect(800, 200, 100, 100));
[email protected]0f81f442012-06-22 06:20:27229 EXPECT_EQ(root_windows[1], d2_w2->GetNativeView()->GetRootWindow());
230
231 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27232 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
233 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]8fef7432012-08-06 15:34:25234 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
235 controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
[email protected]0f81f442012-06-22 06:20:27236 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]0f81f442012-06-22 06:20:27244 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView()));
245 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]8fef7432012-08-06 15:34:25246 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView()));
247 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
[email protected]0f81f442012-06-22 06:20:27248 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView()));
[email protected]20c59762012-06-23 01:10:24249}
250
251TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
[email protected]f634dd32012-07-23 22:49:07252 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43253 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]20c59762012-06-23 01:10:24254 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24255
[email protected]7203a5e2012-08-06 18:27:46256 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]20c59762012-06-23 01:10:24260
261 // Zero origin.
[email protected]7203a5e2012-08-06 18:27:46262 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
[email protected]20c59762012-06-23 01:10:24263
264 // Out of range point should return the primary root window
[email protected]7203a5e2012-08-06 18:27:46265 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]20c59762012-06-23 01:10:24267}
268
269TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
[email protected]f634dd32012-07-23 22:49:07270 UpdateDisplay("700x500,500x500");
[email protected]edbfb8d2012-09-03 08:33:43271 SetSecondaryDisplayLayout(DisplayLayout::LEFT);
[email protected]66b05eac2012-06-27 23:53:10272
[email protected]20c59762012-06-23 01:10:24273 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]20c59762012-06-23 01:10:24274
275 // Containing rect.
276 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46277 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24278 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46279 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));
[email protected]20c59762012-06-23 01:10:24280
281 // Intersecting rect.
282 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46283 wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24284 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46285 wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));
[email protected]20c59762012-06-23 01:10:24286
287 // Zero origin.
[email protected]66b05eac2012-06-27 23:53:10288 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46289 wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
[email protected]66b05eac2012-06-27 23:53:10290 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46291 wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));
[email protected]20c59762012-06-23 01:10:24292
293 // Empty rect.
294 EXPECT_EQ(root_windows[1],
[email protected]7203a5e2012-08-06 18:27:46295 wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24296 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46297 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));
[email protected]20c59762012-06-23 01:10:24298
299 // Out of range rect should return the primary root window.
300 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46301 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
[email protected]20c59762012-06-23 01:10:24302 EXPECT_EQ(root_windows[0],
[email protected]7203a5e2012-08-06 18:27:46303 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
[email protected]0f81f442012-06-22 06:20:27304}
305
[email protected]7f502eb2012-09-20 09:17:12306#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
313TEST_F(ExtendedDesktopTest, MAYBE_Capture) {
[email protected]f634dd32012-07-23 22:49:07314 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08315 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]f634dd32012-07-23 22:49:07327
[email protected]a5e71c92012-06-22 22:09:08328 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]b19ba4adf2012-09-07 16:13:29337 // 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]7495e5032012-09-07 15:31:45343 EXPECT_EQ("1 1 0", r1_d1.GetMouseMotionCountsAndReset());
[email protected]b19ba4adf2012-09-07 16:13:29344#endif
[email protected]a5e71c92012-06-22 22:09:08345 EXPECT_EQ("1 1", r1_d1.GetMouseButtonCountsAndReset());
[email protected]f634dd32012-07-23 22:49:07346 // (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]a5e71c92012-06-22 22:09:08349
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]36f566532012-09-19 04:07:24362 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(r2_w1->GetRootWindow()));
[email protected]f634dd32012-07-23 22:49:07363 generator2.MoveMouseTo(15, 15);
[email protected]a5e71c92012-06-22 22:09:08364 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]f059c6942012-07-21 14:27:57372TEST_F(ExtendedDesktopTest, MoveWindow) {
[email protected]f634dd32012-07-23 22:49:07373 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57374 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]f059c6942012-07-21 14:27:57402}
403
[email protected]608f02f2012-10-25 05:53:33404// 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
410TEST_F(ExtendedDesktopTest, MAYBE_MoveWindowToDisplay) {
[email protected]e79f26e2012-08-09 07:12:48411 UpdateDisplay("1000x1000,1000x1000");
412 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
413
[email protected]ffabb1e2012-10-12 19:51:17414 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]e79f26e2012-08-09 07:12:48418 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]f059c6942012-07-21 14:27:57439TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) {
[email protected]f634dd32012-07-23 22:49:07440 UpdateDisplay("1000x600,600x400");
[email protected]f059c6942012-07-21 14:27:57441 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]f059c6942012-07-21 14:27:57492}
493
[email protected]a5e71c92012-06-22 22:09:08494namespace internal {
[email protected]ca7060982012-08-08 18:05:25495// Test if the Window::ConvertPointToTarget works across root windows.
[email protected]a5e71c92012-06-22 22:09:08496// TODO(oshima): Move multiple display suport and this test to aura.
497TEST_F(ExtendedDesktopTest, ConvertPoint) {
[email protected]f634dd32012-07-23 22:49:07498 UpdateDisplay("1000x600,600x400");
[email protected]a5e71c92012-06-22 22:09:08499 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
500 gfx::Display& display_1 =
[email protected]3e4351b2012-08-09 04:04:16501 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]);
[email protected]a5e71c92012-06-22 22:09:08502 EXPECT_EQ("0,0", display_1.bounds().origin().ToString());
503 gfx::Display& display_2 =
[email protected]3e4351b2012-08-09 04:04:16504 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07505 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString());
506
[email protected]a5e71c92012-06-22 22:09:08507 aura::Window* d1 =
508 CreateTestWidget(gfx::Rect(10, 10, 100, 100))->GetNativeView();
[email protected]a5e71c92012-06-22 22:09:08509 aura::Window* d2 =
[email protected]f634dd32012-07-23 22:49:07510 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]a5e71c92012-06-22 22:09:08513
[email protected]a5e71c92012-06-22 22:09:08514 // Convert point in the Root2's window to the Root1's window Coord.
515 gfx::Point p(0, 0);
[email protected]ca7060982012-08-08 18:05:25516 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07517 EXPECT_EQ("1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08518 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25519 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07520 EXPECT_EQ("1010,10", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08521
522 // Convert point in the Root1's window to the Root2's window Coord.
523 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25524 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07525 EXPECT_EQ("-1000,0", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08526 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25527 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07528 EXPECT_EQ("-1010,-10", p.ToString());
529
530 // Move the 2nd display to the bottom and test again.
[email protected]edbfb8d2012-09-03 08:33:43531 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
[email protected]f634dd32012-07-23 22:49:07532
[email protected]3e4351b2012-08-09 04:04:16533 display_2 = GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]);
[email protected]f634dd32012-07-23 22:49:07534 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]ca7060982012-08-08 18:05:25538 aura::Window::ConvertPointToTarget(root_windows[1], root_windows[0], &p);
[email protected]f634dd32012-07-23 22:49:07539 EXPECT_EQ("0,600", p.ToString());
540 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25541 aura::Window::ConvertPointToTarget(d2, d1, &p);
[email protected]f634dd32012-07-23 22:49:07542 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]ca7060982012-08-08 18:05:25546 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p);
[email protected]f634dd32012-07-23 22:49:07547 EXPECT_EQ("0,-600", p.ToString());
548 p.SetPoint(0, 0);
[email protected]ca7060982012-08-08 18:05:25549 aura::Window::ConvertPointToTarget(d1, d2, &p);
[email protected]f634dd32012-07-23 22:49:07550 EXPECT_EQ("-10,-610", p.ToString());
[email protected]a5e71c92012-06-22 22:09:08551}
[email protected]f634dd32012-07-23 22:49:07552
[email protected]263898a2012-09-17 17:20:07553TEST_F(ExtendedDesktopTest, OpenSystemTray) {
[email protected]596c61c2012-10-29 17:29:43554 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07555 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]596c61c2012-10-29 17:29:43566 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07567 EXPECT_TRUE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43568 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07569 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]596c61c2012-10-29 17:29:43578 UpdateDisplay("500x600");
[email protected]263898a2012-09-17 17:20:07579 EXPECT_FALSE(tray->HasSystemBubble());
[email protected]596c61c2012-10-29 17:29:43580 UpdateDisplay("500x600,600x400");
[email protected]263898a2012-09-17 17:20:07581 EXPECT_FALSE(tray->HasSystemBubble());
582}
583
[email protected]578048512012-09-19 20:01:24584TEST_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]e67291f12012-10-10 05:52:38605TEST_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]ffabb1e2012-10-12 19:51:17611 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38612 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]ffabb1e2012-10-12 19:51:17621 Shell::GetScreen()->GetPrimaryDisplay().bounds());
[email protected]e67291f12012-10-10 05:52:38622 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]a5e71c92012-06-22 22:09:08671} // namespace internal
[email protected]c39be8f2012-06-15 22:58:36672} // namespace ash