OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 #include "ash/display/display_manager.h" | 6 #include "ash/display/display_manager.h" |
7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 views::Widget* widget = new views::Widget; | 150 views::Widget* widget = new views::Widget; |
151 widget->Init(params); | 151 widget->Init(params); |
152 widget->Show(); | 152 widget->Show(); |
153 return widget; | 153 return widget; |
154 } | 154 } |
155 }; | 155 }; |
156 | 156 |
157 // Test conditions that root windows in extended desktop mode | 157 // Test conditions that root windows in extended desktop mode |
158 // must satisfy. | 158 // must satisfy. |
159 TEST_F(ExtendedDesktopTest, Basic) { | 159 TEST_F(ExtendedDesktopTest, Basic) { |
| 160 if (!SupportsMultipleDisplays()) |
| 161 return; |
| 162 |
160 UpdateDisplay("1000x600,600x400"); | 163 UpdateDisplay("1000x600,600x400"); |
161 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 164 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
162 | 165 |
163 // All root windows must have the root window controller. | 166 // All root windows must have the root window controller. |
164 ASSERT_EQ(2U, root_windows.size()); | 167 ASSERT_EQ(2U, root_windows.size()); |
165 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); | 168 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
166 iter != root_windows.end(); ++iter) { | 169 iter != root_windows.end(); ++iter) { |
167 EXPECT_TRUE(GetRootWindowController(*iter) != NULL); | 170 EXPECT_TRUE(GetRootWindowController(*iter) != NULL); |
168 } | 171 } |
169 // Make sure root windows share the same controllers. | 172 // Make sure root windows share the same controllers. |
170 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]), | 173 EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]), |
171 aura::client::GetFocusClient(root_windows[1])); | 174 aura::client::GetFocusClient(root_windows[1])); |
172 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), | 175 EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]), |
173 aura::client::GetActivationClient(root_windows[1])); | 176 aura::client::GetActivationClient(root_windows[1])); |
174 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), | 177 EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]), |
175 aura::client::GetCaptureClient(root_windows[1])); | 178 aura::client::GetCaptureClient(root_windows[1])); |
176 } | 179 } |
177 | 180 |
178 TEST_F(ExtendedDesktopTest, Activation) { | 181 TEST_F(ExtendedDesktopTest, Activation) { |
| 182 if (!SupportsMultipleDisplays()) |
| 183 return; |
| 184 |
179 UpdateDisplay("1000x600,600x400"); | 185 UpdateDisplay("1000x600,600x400"); |
180 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 186 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
181 | 187 |
182 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 188 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
183 views::Widget* widget_on_2nd = | 189 views::Widget* widget_on_2nd = |
184 CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); | 190 CreateTestWidget(gfx::Rect(1200, 10, 100, 100)); |
185 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); | 191 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
186 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); | 192 EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow()); |
187 | 193 |
188 EXPECT_EQ(widget_on_2nd->GetNativeView(), | 194 EXPECT_EQ(widget_on_2nd->GetNativeView(), |
(...skipping 11 matching lines...) Expand all Loading... |
200 | 206 |
201 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); | 207 event_generator.MoveMouseToCenterOf(widget_on_2nd->GetNativeView()); |
202 event_generator.ClickLeftButton(); | 208 event_generator.ClickLeftButton(); |
203 | 209 |
204 EXPECT_EQ(widget_on_2nd->GetNativeView(), | 210 EXPECT_EQ(widget_on_2nd->GetNativeView(), |
205 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); | 211 aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow()); |
206 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); | 212 EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView())); |
207 } | 213 } |
208 | 214 |
209 TEST_F(ExtendedDesktopTest, SystemModal) { | 215 TEST_F(ExtendedDesktopTest, SystemModal) { |
| 216 if (!SupportsMultipleDisplays()) |
| 217 return; |
| 218 |
210 UpdateDisplay("1000x600,600x400"); | 219 UpdateDisplay("1000x600,600x400"); |
211 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 220 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
212 | 221 |
213 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 222 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
214 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); | 223 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
215 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); | 224 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
216 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); | 225 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
217 | 226 |
218 // Open system modal. Make sure it's on 2nd root window and active. | 227 // Open system modal. Make sure it's on 2nd root window and active. |
219 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( | 228 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( |
(...skipping 15 matching lines...) Expand all Loading... |
235 | 244 |
236 // Close system modal and so clicking a widget should work now. | 245 // Close system modal and so clicking a widget should work now. |
237 modal_widget->Close(); | 246 modal_widget->Close(); |
238 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); | 247 event_generator.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
239 event_generator.ClickLeftButton(); | 248 event_generator.ClickLeftButton(); |
240 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); | 249 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
241 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); | 250 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
242 } | 251 } |
243 | 252 |
244 TEST_F(ExtendedDesktopTest, TestCursor) { | 253 TEST_F(ExtendedDesktopTest, TestCursor) { |
| 254 if (!SupportsMultipleDisplays()) |
| 255 return; |
| 256 |
245 UpdateDisplay("1000x600,600x400"); | 257 UpdateDisplay("1000x600,600x400"); |
246 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 258 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
247 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); | 259 EXPECT_EQ(ui::kCursorPointer, root_windows[0]->last_cursor().native_type()); |
248 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); | 260 EXPECT_EQ(ui::kCursorPointer, root_windows[1]->last_cursor().native_type()); |
249 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy); | 261 Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorCopy); |
250 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); | 262 EXPECT_EQ(ui::kCursorCopy, root_windows[0]->last_cursor().native_type()); |
251 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); | 263 EXPECT_EQ(ui::kCursorCopy, root_windows[1]->last_cursor().native_type()); |
252 } | 264 } |
253 | 265 |
254 TEST_F(ExtendedDesktopTest, TestCursorLocation) { | 266 TEST_F(ExtendedDesktopTest, TestCursorLocation) { |
| 267 if (!SupportsMultipleDisplays()) |
| 268 return; |
| 269 |
255 UpdateDisplay("1000x600,600x400"); | 270 UpdateDisplay("1000x600,600x400"); |
256 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 271 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
257 aura::test::WindowTestApi root_window0_test_api(root_windows[0]); | 272 aura::test::WindowTestApi root_window0_test_api(root_windows[0]); |
258 aura::test::WindowTestApi root_window1_test_api(root_windows[1]); | 273 aura::test::WindowTestApi root_window1_test_api(root_windows[1]); |
259 | 274 |
260 root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); | 275 root_windows[0]->MoveCursorTo(gfx::Point(10, 10)); |
261 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); | 276 EXPECT_EQ("10,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
262 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); | 277 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
263 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); | 278 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
264 root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); | 279 root_windows[1]->MoveCursorTo(gfx::Point(10, 20)); |
265 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString()); | 280 EXPECT_EQ("1010,20", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
266 EXPECT_FALSE(root_window0_test_api.ContainsMouse()); | 281 EXPECT_FALSE(root_window0_test_api.ContainsMouse()); |
267 EXPECT_TRUE(root_window1_test_api.ContainsMouse()); | 282 EXPECT_TRUE(root_window1_test_api.ContainsMouse()); |
268 root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); | 283 root_windows[0]->MoveCursorTo(gfx::Point(20, 10)); |
269 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); | 284 EXPECT_EQ("20,10", Shell::GetScreen()->GetCursorScreenPoint().ToString()); |
270 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); | 285 EXPECT_TRUE(root_window0_test_api.ContainsMouse()); |
271 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); | 286 EXPECT_FALSE(root_window1_test_api.ContainsMouse()); |
272 } | 287 } |
273 | 288 |
274 TEST_F(ExtendedDesktopTest, CycleWindows) { | 289 TEST_F(ExtendedDesktopTest, CycleWindows) { |
| 290 if (!SupportsMultipleDisplays()) |
| 291 return; |
| 292 |
275 UpdateDisplay("700x500,500x500"); | 293 UpdateDisplay("700x500,500x500"); |
276 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 294 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
277 | 295 |
278 WindowCycleController* controller = | 296 WindowCycleController* controller = |
279 Shell::GetInstance()->window_cycle_controller(); | 297 Shell::GetInstance()->window_cycle_controller(); |
280 | 298 |
281 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 299 views::Widget* d1_w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
282 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); | 300 EXPECT_EQ(root_windows[0], d1_w1->GetNativeView()->GetRootWindow()); |
283 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); | 301 views::Widget* d2_w1 = CreateTestWidget(gfx::Rect(800, 10, 100, 100)); |
284 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); | 302 EXPECT_EQ(root_windows[1], d2_w1->GetNativeView()->GetRootWindow()); |
(...skipping 28 matching lines...) Expand all Loading... |
313 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); | 331 EXPECT_TRUE(wm::IsActiveWindow(d1_w1->GetNativeView())); |
314 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); | 332 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
315 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); | 333 EXPECT_TRUE(wm::IsActiveWindow(d2_w1->GetNativeView())); |
316 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); | 334 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
317 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); | 335 EXPECT_TRUE(wm::IsActiveWindow(d1_w2->GetNativeView())); |
318 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); | 336 controller->HandleCycleWindow(WindowCycleController::BACKWARD, true); |
319 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); | 337 EXPECT_TRUE(wm::IsActiveWindow(d2_w2->GetNativeView())); |
320 } | 338 } |
321 | 339 |
322 TEST_F(ExtendedDesktopTest, GetRootWindowAt) { | 340 TEST_F(ExtendedDesktopTest, GetRootWindowAt) { |
| 341 if (!SupportsMultipleDisplays()) |
| 342 return; |
| 343 |
323 UpdateDisplay("700x500,500x500"); | 344 UpdateDisplay("700x500,500x500"); |
324 SetSecondaryDisplayLayout(DisplayLayout::LEFT); | 345 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
325 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 346 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
326 | 347 |
327 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); | 348 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100))); |
328 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); | 349 EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100))); |
329 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); | 350 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300))); |
330 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300))); | 351 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700,300))); |
331 | 352 |
332 // Zero origin. | 353 // Zero origin. |
333 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); | 354 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0))); |
334 | 355 |
335 // Out of range point should return the primary root window | 356 // Out of range point should return the primary root window |
336 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0))); | 357 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0))); |
337 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); | 358 EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100))); |
338 } | 359 } |
339 | 360 |
340 TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { | 361 TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { |
| 362 if (!SupportsMultipleDisplays()) |
| 363 return; |
| 364 |
341 UpdateDisplay("700x500,500x500"); | 365 UpdateDisplay("700x500,500x500"); |
342 SetSecondaryDisplayLayout(DisplayLayout::LEFT); | 366 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
343 | 367 |
344 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 368 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
345 | 369 |
346 // Containing rect. | 370 // Containing rect. |
347 EXPECT_EQ(root_windows[1], | 371 EXPECT_EQ(root_windows[1], |
348 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); | 372 wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50))); |
349 EXPECT_EQ(root_windows[0], | 373 EXPECT_EQ(root_windows[0], |
350 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); | 374 wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50))); |
(...skipping 17 matching lines...) Expand all Loading... |
368 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); | 392 wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0))); |
369 | 393 |
370 // Out of range rect should return the primary root window. | 394 // Out of range rect should return the primary root window. |
371 EXPECT_EQ(root_windows[0], | 395 EXPECT_EQ(root_windows[0], |
372 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))); | 396 wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50))); |
373 EXPECT_EQ(root_windows[0], | 397 EXPECT_EQ(root_windows[0], |
374 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))); | 398 wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50))); |
375 } | 399 } |
376 | 400 |
377 TEST_F(ExtendedDesktopTest, Capture) { | 401 TEST_F(ExtendedDesktopTest, Capture) { |
| 402 if (!SupportsMultipleDisplays()) |
| 403 return; |
| 404 |
378 UpdateDisplay("1000x600,600x400"); | 405 UpdateDisplay("1000x600,600x400"); |
379 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 406 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
380 | 407 |
381 aura::test::EventCountDelegate r1_d1; | 408 aura::test::EventCountDelegate r1_d1; |
382 aura::test::EventCountDelegate r1_d2; | 409 aura::test::EventCountDelegate r1_d2; |
383 aura::test::EventCountDelegate r2_d1; | 410 aura::test::EventCountDelegate r2_d1; |
384 | 411 |
385 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( | 412 scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate( |
386 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); | 413 &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
387 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( | 414 scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 generator2.MoveMouseTo(15, 15); | 451 generator2.MoveMouseTo(15, 15); |
425 generator2.ClickLeftButton(); | 452 generator2.ClickLeftButton(); |
426 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); | 453 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
427 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); | 454 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
428 // Make sure the mouse_moved_handler_ is properly reset. | 455 // Make sure the mouse_moved_handler_ is properly reset. |
429 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); | 456 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
430 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); | 457 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
431 } | 458 } |
432 | 459 |
433 TEST_F(ExtendedDesktopTest, MoveWindow) { | 460 TEST_F(ExtendedDesktopTest, MoveWindow) { |
| 461 if (!SupportsMultipleDisplays()) |
| 462 return; |
| 463 |
434 UpdateDisplay("1000x600,600x400"); | 464 UpdateDisplay("1000x600,600x400"); |
435 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 465 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
436 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 466 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
437 | 467 |
438 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); | 468 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
439 | 469 |
440 d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); | 470 d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
441 EXPECT_EQ("1010,10 100x100", | 471 EXPECT_EQ("1010,10 100x100", |
442 d1->GetWindowBoundsInScreen().ToString()); | 472 d1->GetWindowBoundsInScreen().ToString()); |
443 | 473 |
(...skipping 14 matching lines...) Expand all Loading... |
458 | 488 |
459 // Setting outside of root windows will be moved to primary root window. | 489 // Setting outside of root windows will be moved to primary root window. |
460 // TODO(oshima): This one probably should pick the closest root window. | 490 // TODO(oshima): This one probably should pick the closest root window. |
461 d1->SetBounds(gfx::Rect(200, 10, 100, 100)); | 491 d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
462 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); | 492 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
463 } | 493 } |
464 | 494 |
465 // Verifies if the mouse event arrives to the window even when the window | 495 // Verifies if the mouse event arrives to the window even when the window |
466 // moves to another root in a pre-target handler. See: crbug.com/157583 | 496 // moves to another root in a pre-target handler. See: crbug.com/157583 |
467 TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { | 497 TEST_F(ExtendedDesktopTest, MoveWindowByMouseClick) { |
| 498 if (!SupportsMultipleDisplays()) |
| 499 return; |
| 500 |
468 UpdateDisplay("1000x600,600x400"); | 501 UpdateDisplay("1000x600,600x400"); |
469 | 502 |
470 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 503 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
471 aura::test::EventCountDelegate delegate; | 504 aura::test::EventCountDelegate delegate; |
472 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 505 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
473 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); | 506 &delegate, 0, gfx::Rect(10, 10, 100, 100), root_windows[0])); |
474 MoveWindowByClickEventHandler event_handler(window.get()); | 507 MoveWindowByClickEventHandler event_handler(window.get()); |
475 window->AddPreTargetHandler(&event_handler); | 508 window->AddPreTargetHandler(&event_handler); |
476 | 509 |
477 aura::test::EventGenerator& event_generator(GetEventGenerator()); | 510 aura::test::EventGenerator& event_generator(GetEventGenerator()); |
478 | 511 |
479 event_generator.MoveMouseToCenterOf(window.get()); | 512 event_generator.MoveMouseToCenterOf(window.get()); |
480 event_generator.ClickLeftButton(); | 513 event_generator.ClickLeftButton(); |
481 // Both mouse pressed and released arrive at the window and its delegate. | 514 // Both mouse pressed and released arrive at the window and its delegate. |
482 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); | 515 EXPECT_EQ("1 1", delegate.GetMouseButtonCountsAndReset()); |
483 // Also event_handler moves the window to another root at mouse release. | 516 // Also event_handler moves the window to another root at mouse release. |
484 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 517 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
485 } | 518 } |
486 | 519 |
487 TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) { | 520 TEST_F(ExtendedDesktopTest, MoveWindowToDisplay) { |
| 521 if (!SupportsMultipleDisplays()) |
| 522 return; |
| 523 |
488 UpdateDisplay("1000x1000,1000x1000"); | 524 UpdateDisplay("1000x1000,1000x1000"); |
489 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 525 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
490 | 526 |
491 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching( | 527 gfx::Display display0 = Shell::GetScreen()->GetDisplayMatching( |
492 root_windows[0]->GetBoundsInScreen()); | 528 root_windows[0]->GetBoundsInScreen()); |
493 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching( | 529 gfx::Display display1 = Shell::GetScreen()->GetDisplayMatching( |
494 root_windows[1]->GetBoundsInScreen()); | 530 root_windows[1]->GetBoundsInScreen()); |
495 EXPECT_NE(display0.id(), display1.id()); | 531 EXPECT_NE(display0.id(), display1.id()); |
496 | 532 |
497 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100)); | 533 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 1000, 100)); |
498 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); | 534 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
499 | 535 |
500 // Move the window where the window spans both root windows. Since the second | 536 // Move the window where the window spans both root windows. Since the second |
501 // parameter is |display1|, the window should be shown on the secondary root. | 537 // parameter is |display1|, the window should be shown on the secondary root. |
502 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), | 538 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
503 display1); | 539 display1); |
504 EXPECT_EQ("500,10 1000x100", | 540 EXPECT_EQ("500,10 1000x100", |
505 d1->GetWindowBoundsInScreen().ToString()); | 541 d1->GetWindowBoundsInScreen().ToString()); |
506 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); | 542 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
507 | 543 |
508 // Move to the primary root. | 544 // Move to the primary root. |
509 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), | 545 d1->GetNativeWindow()->SetBoundsInScreen(gfx::Rect(500, 10, 1000, 100), |
510 display0); | 546 display0); |
511 EXPECT_EQ("500,10 1000x100", | 547 EXPECT_EQ("500,10 1000x100", |
512 d1->GetWindowBoundsInScreen().ToString()); | 548 d1->GetWindowBoundsInScreen().ToString()); |
513 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); | 549 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
514 } | 550 } |
515 | 551 |
516 TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { | 552 TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
| 553 if (!SupportsMultipleDisplays()) |
| 554 return; |
| 555 |
517 UpdateDisplay("1000x600,600x400"); | 556 UpdateDisplay("1000x600,600x400"); |
518 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 557 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
519 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 558 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
520 views::Widget* w1_t1 = CreateTestWidgetWithParent( | 559 views::Widget* w1_t1 = CreateTestWidgetWithParent( |
521 w1, gfx::Rect(50, 50, 50, 50), false /* transient */); | 560 w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
522 // Transient child of the transient child. | 561 // Transient child of the transient child. |
523 views::Widget* w1_t11 = CreateTestWidgetWithParent( | 562 views::Widget* w1_t11 = CreateTestWidgetWithParent( |
524 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); | 563 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); |
525 | 564 |
526 views::Widget* w11 = CreateTestWidgetWithParent( | 565 views::Widget* w11 = CreateTestWidgetWithParent( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); | 604 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
566 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); | 605 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
567 EXPECT_EQ("10,50 50x50", | 606 EXPECT_EQ("10,50 50x50", |
568 w1_t1->GetWindowBoundsInScreen().ToString()); | 607 w1_t1->GetWindowBoundsInScreen().ToString()); |
569 } | 608 } |
570 | 609 |
571 namespace internal { | 610 namespace internal { |
572 // Test if the Window::ConvertPointToTarget works across root windows. | 611 // Test if the Window::ConvertPointToTarget works across root windows. |
573 // TODO(oshima): Move multiple display suport and this test to aura. | 612 // TODO(oshima): Move multiple display suport and this test to aura. |
574 TEST_F(ExtendedDesktopTest, ConvertPoint) { | 613 TEST_F(ExtendedDesktopTest, ConvertPoint) { |
| 614 if (!SupportsMultipleDisplays()) |
| 615 return; |
| 616 |
575 UpdateDisplay("1000x600,600x400"); | 617 UpdateDisplay("1000x600,600x400"); |
576 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 618 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
577 gfx::Display& display_1 = | 619 gfx::Display& display_1 = |
578 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]); | 620 GetDisplayManager()->FindDisplayForRootWindow(root_windows[0]); |
579 EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); | 621 EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
580 gfx::Display& display_2 = | 622 gfx::Display& display_2 = |
581 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); | 623 GetDisplayManager()->FindDisplayForRootWindow(root_windows[1]); |
582 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); | 624 EXPECT_EQ("1000,0", display_2.bounds().origin().ToString()); |
583 | 625 |
584 aura::Window* d1 = | 626 aura::Window* d1 = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 // Convert point in Root1's window to Root2's window Coord. | 663 // Convert point in Root1's window to Root2's window Coord. |
622 p.SetPoint(0, 0); | 664 p.SetPoint(0, 0); |
623 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); | 665 aura::Window::ConvertPointToTarget(root_windows[0], root_windows[1], &p); |
624 EXPECT_EQ("0,-600", p.ToString()); | 666 EXPECT_EQ("0,-600", p.ToString()); |
625 p.SetPoint(0, 0); | 667 p.SetPoint(0, 0); |
626 aura::Window::ConvertPointToTarget(d1, d2, &p); | 668 aura::Window::ConvertPointToTarget(d1, d2, &p); |
627 EXPECT_EQ("-10,-610", p.ToString()); | 669 EXPECT_EQ("-10,-610", p.ToString()); |
628 } | 670 } |
629 | 671 |
630 TEST_F(ExtendedDesktopTest, OpenSystemTray) { | 672 TEST_F(ExtendedDesktopTest, OpenSystemTray) { |
| 673 if (!SupportsMultipleDisplays()) |
| 674 return; |
| 675 |
631 UpdateDisplay("500x600,600x400"); | 676 UpdateDisplay("500x600,600x400"); |
632 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); | 677 SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
633 ASSERT_FALSE(tray->HasSystemBubble()); | 678 ASSERT_FALSE(tray->HasSystemBubble()); |
634 | 679 |
635 aura::test::EventGenerator& event_generator(GetEventGenerator()); | 680 aura::test::EventGenerator& event_generator(GetEventGenerator()); |
636 | 681 |
637 // Opens the tray by a dummy click event and makes sure that adding/removing | 682 // Opens the tray by a dummy click event and makes sure that adding/removing |
638 // displays doesn't break anything. | 683 // displays doesn't break anything. |
639 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow()); | 684 event_generator.MoveMouseToCenterOf(tray->GetWidget()->GetNativeWindow()); |
640 event_generator.ClickLeftButton(); | 685 event_generator.ClickLeftButton(); |
(...skipping 11 matching lines...) Expand all Loading... |
652 | 697 |
653 EXPECT_FALSE(tray->HasSystemBubble()); | 698 EXPECT_FALSE(tray->HasSystemBubble()); |
654 | 699 |
655 UpdateDisplay("500x600"); | 700 UpdateDisplay("500x600"); |
656 EXPECT_FALSE(tray->HasSystemBubble()); | 701 EXPECT_FALSE(tray->HasSystemBubble()); |
657 UpdateDisplay("500x600,600x400"); | 702 UpdateDisplay("500x600,600x400"); |
658 EXPECT_FALSE(tray->HasSystemBubble()); | 703 EXPECT_FALSE(tray->HasSystemBubble()); |
659 } | 704 } |
660 | 705 |
661 TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { | 706 TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { |
| 707 if (!SupportsMultipleDisplays()) |
| 708 return; |
| 709 |
662 UpdateDisplay("100x100,200x200"); | 710 UpdateDisplay("100x100,200x200"); |
663 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 711 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
664 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50)); | 712 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50)); |
665 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); | 713 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
666 w1->SetBounds(gfx::Rect(150, 10, 50, 50)); | 714 w1->SetBounds(gfx::Rect(150, 10, 50, 50)); |
667 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 715 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
668 | 716 |
669 // The widget stays in the same root if kStayInSameRootWindowKey is set to | 717 // The widget stays in the same root if kStayInSameRootWindowKey is set to |
670 // true. | 718 // true. |
671 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); | 719 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
672 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); | 720 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
673 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 721 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
674 | 722 |
675 // The widget should now move to the 1st root window without the property. | 723 // The widget should now move to the 1st root window without the property. |
676 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); | 724 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); |
677 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); | 725 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
678 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); | 726 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
679 } | 727 } |
680 | 728 |
681 TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { | 729 TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { |
| 730 if (!SupportsMultipleDisplays()) |
| 731 return; |
| 732 |
682 UpdateDisplay("100x100,200x200"); | 733 UpdateDisplay("100x100,200x200"); |
683 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 734 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
684 | 735 |
685 // Create normal windows on both displays. | 736 // Create normal windows on both displays. |
686 views::Widget* widget1 = CreateTestWidget( | 737 views::Widget* widget1 = CreateTestWidget( |
687 Shell::GetScreen()->GetPrimaryDisplay().bounds()); | 738 Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
688 widget1->Show(); | 739 widget1->Show(); |
689 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); | 740 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); |
690 views::Widget* widget2 = CreateTestWidget( | 741 views::Widget* widget2 = CreateTestWidget( |
691 ScreenAsh::GetSecondaryDisplay().bounds()); | 742 ScreenAsh::GetSecondaryDisplay().bounds()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); | 793 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); |
743 | 794 |
744 event_generator.set_current_root_window(root_windows[1]); | 795 event_generator.set_current_root_window(root_windows[1]); |
745 event_generator.PressKey(ui::VKEY_E, 0); | 796 event_generator.PressKey(ui::VKEY_E, 0); |
746 event_generator.ReleaseKey(ui::VKEY_E, 0); | 797 event_generator.ReleaseKey(ui::VKEY_E, 0); |
747 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); | 798 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
748 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); | 799 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); |
749 } | 800 } |
750 | 801 |
751 TEST_F(ExtendedDesktopTest, PassiveGrab) { | 802 TEST_F(ExtendedDesktopTest, PassiveGrab) { |
| 803 if (!SupportsMultipleDisplays()) |
| 804 return; |
| 805 |
752 EventLocationRecordingEventHandler event_handler; | 806 EventLocationRecordingEventHandler event_handler; |
753 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 807 ash::Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
754 | 808 |
755 UpdateDisplay("300x300,200x200"); | 809 UpdateDisplay("300x300,200x200"); |
756 | 810 |
757 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200)); | 811 views::Widget* widget = CreateTestWidget(gfx::Rect(50, 50, 200, 200)); |
758 widget->Show(); | 812 widget->Show(); |
759 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString()); | 813 ASSERT_EQ("50,50 200x200", widget->GetWindowBoundsInScreen().ToString()); |
760 | 814 |
761 aura::test::EventGenerator& generator(GetEventGenerator()); | 815 aura::test::EventGenerator& generator(GetEventGenerator()); |
762 generator.MoveMouseTo(150, 150); | 816 generator.MoveMouseTo(150, 150); |
763 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset()); | 817 EXPECT_EQ("100,100 150,150", event_handler.GetLocationsAndReset()); |
764 | 818 |
765 generator.PressLeftButton(); | 819 generator.PressLeftButton(); |
766 generator.MoveMouseTo(400, 150); | 820 generator.MoveMouseTo(400, 150); |
767 | 821 |
768 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset()); | 822 EXPECT_EQ("350,100 400,150", event_handler.GetLocationsAndReset()); |
769 | 823 |
770 generator.ReleaseLeftButton(); | 824 generator.ReleaseLeftButton(); |
771 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); | 825 EXPECT_EQ("-999,-999 -999,-999", event_handler.GetLocationsAndReset()); |
772 | 826 |
773 generator.MoveMouseTo(400, 150); | 827 generator.MoveMouseTo(400, 150); |
774 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); | 828 EXPECT_EQ("100,150 100,150", event_handler.GetLocationsAndReset()); |
775 | 829 |
776 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 830 ash::Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
777 } | 831 } |
778 | 832 |
779 } // namespace internal | 833 } // namespace internal |
780 } // namespace ash | 834 } // namespace ash |
OLD | NEW |