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 | 6 |
| 7 #include "ash/ash_switches.h" |
7 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
8 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
9 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
10 #include "ash/launcher/launcher.h" | 11 #include "ash/launcher/launcher.h" |
11 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
12 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
15 #include "ash/test/cursor_manager_test_api.h" | 16 #include "ash/test/cursor_manager_test_api.h" |
| 17 #include "base/command_line.h" |
16 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
17 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
18 #include "ui/aura/test/event_generator.h" | 20 #include "ui/aura/test/event_generator.h" |
19 #include "ui/aura/window_tracker.h" | 21 #include "ui/aura/window_tracker.h" |
20 #include "ui/base/events/event_handler.h" | 22 #include "ui/base/events/event_handler.h" |
21 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
22 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
24 | 26 |
25 #if defined(USE_X11) | 27 #if defined(USE_X11) |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); | 474 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
473 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 475 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
474 EXPECT_FALSE(secondary_root->Contains(launcher_window)); | 476 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
475 EXPECT_EQ(primary_display.id(), | 477 EXPECT_EQ(primary_display.id(), |
476 Shell::GetScreen()->GetDisplayNearestPoint( | 478 Shell::GetScreen()->GetDisplayNearestPoint( |
477 gfx::Point(-100, -100)).id()); | 479 gfx::Point(-100, -100)).id()); |
478 EXPECT_EQ(primary_display.id(), | 480 EXPECT_EQ(primary_display.id(), |
479 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | 481 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
480 | 482 |
481 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); | 483 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); |
| 484 EXPECT_EQ("0,0 200x153", primary_display.work_area().ToString()); |
| 485 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); |
| 486 EXPECT_EQ("200,0 300x253", secondary_display.work_area().ToString()); |
| 487 EXPECT_EQ("right, 50", |
| 488 display_manager->GetCurrentDisplayLayout().ToString()); |
| 489 |
| 490 // Switch primary and secondary |
| 491 display_controller->SetPrimaryDisplay(secondary_display); |
| 492 const DisplayLayout& inverted_layout = |
| 493 display_manager->GetCurrentDisplayLayout(); |
| 494 EXPECT_EQ("left, -50", inverted_layout.ToString()); |
| 495 |
| 496 EXPECT_EQ(secondary_display.id(), |
| 497 Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 498 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); |
| 499 EXPECT_EQ(secondary_display.id(), |
| 500 Shell::GetScreen()->GetDisplayNearestPoint( |
| 501 gfx::Point(-100, -100)).id()); |
| 502 EXPECT_EQ(secondary_display.id(), |
| 503 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 504 |
| 505 EXPECT_EQ( |
| 506 primary_root, |
| 507 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
| 508 EXPECT_EQ( |
| 509 secondary_root, |
| 510 display_controller->GetRootWindowForDisplayId(primary_display.id())); |
| 511 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 512 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
| 513 |
| 514 // Test if the bounds are correctly swapped. |
| 515 gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay(); |
| 516 gfx::Display swapped_secondary = ScreenAsh::GetSecondaryDisplay(); |
| 517 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString()); |
| 518 EXPECT_EQ("0,0 300x253", swapped_primary.work_area().ToString()); |
| 519 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString()); |
| 520 |
| 521 EXPECT_EQ("-200,-50 200x153", swapped_secondary.work_area().ToString()); |
| 522 |
| 523 aura::WindowTracker tracker; |
| 524 tracker.Add(primary_root); |
| 525 tracker.Add(secondary_root); |
| 526 |
| 527 // Deleting 2nd display should move the primary to original primary display. |
| 528 UpdateDisplay("200x200"); |
| 529 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. |
| 530 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); |
| 531 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 532 EXPECT_EQ(primary_display.id(), |
| 533 Shell::GetScreen()->GetDisplayNearestPoint( |
| 534 gfx::Point(-100, -100)).id()); |
| 535 EXPECT_EQ(primary_display.id(), |
| 536 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 537 EXPECT_TRUE(tracker.Contains(primary_root)); |
| 538 EXPECT_FALSE(tracker.Contains(secondary_root)); |
| 539 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 540 } |
| 541 |
| 542 TEST_F(DisplayControllerTest, SwapPrimaryForLegacyShelfLayout) { |
| 543 if (!SupportsMultipleDisplays()) |
| 544 return; |
| 545 |
| 546 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 547 ash::switches::kAshDisableAlternateShelfLayout); |
| 548 |
| 549 DisplayController* display_controller = |
| 550 Shell::GetInstance()->display_controller(); |
| 551 internal::DisplayManager* display_manager = |
| 552 Shell::GetInstance()->display_manager(); |
| 553 |
| 554 UpdateDisplay("200x200,300x300"); |
| 555 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 556 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
| 557 |
| 558 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); |
| 559 display_controller->SetLayoutForCurrentDisplays(display_layout); |
| 560 |
| 561 EXPECT_NE(primary_display.id(), secondary_display.id()); |
| 562 aura::RootWindow* primary_root = |
| 563 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
| 564 aura::RootWindow* secondary_root = |
| 565 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
| 566 EXPECT_NE(primary_root, secondary_root); |
| 567 aura::Window* launcher_window = |
| 568 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
| 569 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
| 570 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
| 571 EXPECT_EQ(primary_display.id(), |
| 572 Shell::GetScreen()->GetDisplayNearestPoint( |
| 573 gfx::Point(-100, -100)).id()); |
| 574 EXPECT_EQ(primary_display.id(), |
| 575 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 576 |
| 577 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); |
482 EXPECT_EQ("0,0 200x152", primary_display.work_area().ToString()); | 578 EXPECT_EQ("0,0 200x152", primary_display.work_area().ToString()); |
483 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); | 579 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); |
484 EXPECT_EQ("200,0 300x252", secondary_display.work_area().ToString()); | 580 EXPECT_EQ("200,0 300x252", secondary_display.work_area().ToString()); |
485 EXPECT_EQ("right, 50", | 581 EXPECT_EQ("right, 50", |
486 display_manager->GetCurrentDisplayLayout().ToString()); | 582 display_manager->GetCurrentDisplayLayout().ToString()); |
487 | 583 |
488 // Switch primary and secondary | 584 // Switch primary and secondary |
489 display_controller->SetPrimaryDisplay(secondary_display); | 585 display_controller->SetPrimaryDisplay(secondary_display); |
490 const DisplayLayout& inverted_layout = | 586 const DisplayLayout& inverted_layout = |
491 display_manager->GetCurrentDisplayLayout(); | 587 display_manager->GetCurrentDisplayLayout(); |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); | 1123 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); |
1028 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); | 1124 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); |
1029 | 1125 |
1030 // Switching back to single display. | 1126 // Switching back to single display. |
1031 UpdateDisplay("300x400"); | 1127 UpdateDisplay("300x400"); |
1032 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); | 1128 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); |
1033 } | 1129 } |
1034 #endif | 1130 #endif |
1035 | 1131 |
1036 } // namespace ash | 1132 } // namespace ash |
OLD | NEW |