Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ash/wm/workspace/workspace_layout_manager_unittest.cc

Issue 1608053002: Remove now-unnecessary wrappers around gfx::Screen::GetScreen() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-5
Patch Set: cros Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/wm/workspace/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/display/display_layout.h" 10 #include "ash/display/display_layout.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { 382 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) {
383 scoped_ptr<aura::Window> window( 383 scoped_ptr<aura::Window> window(
384 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0), 384 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0),
385 NULL)); 385 NULL));
386 wm::GetWindowState(window.get())->Maximize(); 386 wm::GetWindowState(window.get())->Maximize();
387 aura::Window* default_container = Shell::GetContainer( 387 aura::Window* default_container = Shell::GetContainer(
388 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); 388 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
389 default_container->AddChild(window.get()); 389 default_container->AddChild(window.get());
390 window->Show(); 390 window->Show();
391 gfx::Rect work_area( 391 gfx::Rect work_area(
392 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 392 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
393 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); 393 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString());
394 } 394 }
395 395
396 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { 396 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) {
397 // Normal window bounds shouldn't be changed. 397 // Normal window bounds shouldn't be changed.
398 gfx::Rect window_bounds(100, 100, 200, 200); 398 gfx::Rect window_bounds(100, 100, 200, 200);
399 scoped_ptr<aura::Window> window( 399 scoped_ptr<aura::Window> window(
400 CreateTestWindowInShellWithBounds(window_bounds)); 400 CreateTestWindowInShellWithBounds(window_bounds));
401 EXPECT_EQ(window_bounds, window->bounds()); 401 EXPECT_EQ(window_bounds, window->bounds());
402 402
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 bounds = window_bigger_than_display->bounds(); 457 bounds = window_bigger_than_display->bounds();
458 bounds.Intersect(root_window_bounds); 458 bounds.Intersect(root_window_bounds);
459 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); 459 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
460 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); 460 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
461 } 461 }
462 462
463 // Verifies the size of a window is enforced to be smaller than the work area. 463 // Verifies the size of a window is enforced to be smaller than the work area.
464 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { 464 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) {
465 // Normal window bounds shouldn't be changed. 465 // Normal window bounds shouldn't be changed.
466 gfx::Size work_area( 466 gfx::Size work_area(
467 Shell::GetScreen()->GetPrimaryDisplay().work_area().size()); 467 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area().size());
468 const gfx::Rect window_bounds( 468 const gfx::Rect window_bounds(
469 100, 101, work_area.width() + 1, work_area.height() + 2); 469 100, 101, work_area.width() + 1, work_area.height() + 2);
470 scoped_ptr<aura::Window> window( 470 scoped_ptr<aura::Window> window(
471 CreateTestWindowInShellWithBounds(window_bounds)); 471 CreateTestWindowInShellWithBounds(window_bounds));
472 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), 472 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
473 window->bounds().ToString()); 473 window->bounds().ToString());
474 474
475 // Directly setting the bounds triggers a slightly different code path. Verify 475 // Directly setting the bounds triggers a slightly different code path. Verify
476 // that too. 476 // that too.
477 window->SetBounds(window_bounds); 477 window->SetBounds(window_bounds);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 initial_work_area_bounds.ToString(), 629 initial_work_area_bounds.ToString(),
630 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString()); 630 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString());
631 } 631 }
632 632
633 // Tests normal->fullscreen->normal. 633 // Tests normal->fullscreen->normal.
634 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { 634 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) {
635 gfx::Rect bounds(100, 100, 200, 200); 635 gfx::Rect bounds(100, 100, 200, 200);
636 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 636 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
637 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 637 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
638 // Fullscreen window fills the whole display. 638 // Fullscreen window fills the whole display.
639 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow( 639 EXPECT_EQ(gfx::Screen::GetScreen()
640 window.get()).bounds().ToString(), 640 ->GetDisplayNearestWindow(window.get())
641 .bounds()
642 .ToString(),
641 window->bounds().ToString()); 643 window->bounds().ToString());
642 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 644 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
643 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 645 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
644 } 646 }
645 647
646 // Tests that fullscreen window causes always_on_top windows to stack below. 648 // Tests that fullscreen window causes always_on_top windows to stack below.
647 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { 649 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) {
648 gfx::Rect bounds(100, 100, 200, 200); 650 gfx::Rect bounds(100, 100, 200, 200);
649 scoped_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds)); 651 scoped_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds));
650 scoped_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds)); 652 scoped_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds));
(...skipping 19 matching lines...) Expand all
670 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow()) 672 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow())
671 ->GetWindowForFullscreenMode()); 673 ->GetWindowForFullscreenMode());
672 } 674 }
673 675
674 // Tests fullscreen window size during root window resize. 676 // Tests fullscreen window size during root window resize.
675 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { 677 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) {
676 gfx::Rect bounds(100, 100, 200, 200); 678 gfx::Rect bounds(100, 100, 200, 200);
677 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 679 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
678 // Fullscreen window fills the whole display. 680 // Fullscreen window fills the whole display.
679 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 681 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
680 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow( 682 EXPECT_EQ(gfx::Screen::GetScreen()
681 window.get()).bounds().ToString(), 683 ->GetDisplayNearestWindow(window.get())
684 .bounds()
685 .ToString(),
682 window->bounds().ToString()); 686 window->bounds().ToString());
683 // Enlarge the root window. We should still match the display size. 687 // Enlarge the root window. We should still match the display size.
684 UpdateDisplay("800x600"); 688 UpdateDisplay("800x600");
685 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow( 689 EXPECT_EQ(gfx::Screen::GetScreen()
686 window.get()).bounds().ToString(), 690 ->GetDisplayNearestWindow(window.get())
691 .bounds()
692 .ToString(),
687 window->bounds().ToString()); 693 window->bounds().ToString());
688 } 694 }
689 695
690 // Tests that when the screen gets smaller the windows aren't bigger than 696 // Tests that when the screen gets smaller the windows aren't bigger than
691 // the screen. 697 // the screen.
692 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { 698 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) {
693 scoped_ptr<aura::Window> window( 699 scoped_ptr<aura::Window> window(
694 CreateTestWindow(gfx::Rect(10, 20, 500, 400))); 700 CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
695 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( 701 gfx::Rect work_area = gfx::Screen::GetScreen()
696 window.get()).work_area(); 702 ->GetDisplayNearestWindow(window.get())
703 .work_area();
697 // Invariant: Window is smaller than work area. 704 // Invariant: Window is smaller than work area.
698 EXPECT_LE(window->bounds().width(), work_area.width()); 705 EXPECT_LE(window->bounds().width(), work_area.width());
699 EXPECT_LE(window->bounds().height(), work_area.height()); 706 EXPECT_LE(window->bounds().height(), work_area.height());
700 707
701 // Make the root window narrower than our window. 708 // Make the root window narrower than our window.
702 UpdateDisplay("300x400"); 709 UpdateDisplay("300x400");
703 work_area = Shell::GetScreen()->GetDisplayNearestWindow( 710 work_area = gfx::Screen::GetScreen()
704 window.get()).work_area(); 711 ->GetDisplayNearestWindow(window.get())
712 .work_area();
705 EXPECT_LE(window->bounds().width(), work_area.width()); 713 EXPECT_LE(window->bounds().width(), work_area.width());
706 EXPECT_LE(window->bounds().height(), work_area.height()); 714 EXPECT_LE(window->bounds().height(), work_area.height());
707 715
708 // Make the root window shorter than our window. 716 // Make the root window shorter than our window.
709 UpdateDisplay("300x200"); 717 UpdateDisplay("300x200");
710 work_area = Shell::GetScreen()->GetDisplayNearestWindow( 718 work_area = gfx::Screen::GetScreen()
711 window.get()).work_area(); 719 ->GetDisplayNearestWindow(window.get())
720 .work_area();
712 EXPECT_LE(window->bounds().width(), work_area.width()); 721 EXPECT_LE(window->bounds().width(), work_area.width());
713 EXPECT_LE(window->bounds().height(), work_area.height()); 722 EXPECT_LE(window->bounds().height(), work_area.height());
714 723
715 // Enlarging the root window does not change the window bounds. 724 // Enlarging the root window does not change the window bounds.
716 gfx::Rect old_bounds = window->bounds(); 725 gfx::Rect old_bounds = window->bounds();
717 UpdateDisplay("800x600"); 726 UpdateDisplay("800x600");
718 EXPECT_EQ(old_bounds.width(), window->bounds().width()); 727 EXPECT_EQ(old_bounds.width(), window->bounds().width());
719 EXPECT_EQ(old_bounds.height(), window->bounds().height()); 728 EXPECT_EQ(old_bounds.height(), window->bounds().height());
720 } 729 }
721 730
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 layout_manager_ = static_cast<WorkspaceLayoutManager*>( 1021 layout_manager_ = static_cast<WorkspaceLayoutManager*>(
1013 default_container->layout_manager()); 1022 default_container->layout_manager());
1014 } 1023 }
1015 1024
1016 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { 1025 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
1017 return CreateTestWindowInShellWithBounds(bounds); 1026 return CreateTestWindowInShellWithBounds(bounds);
1018 } 1027 }
1019 1028
1020 void ShowKeyboard() { 1029 void ShowKeyboard() {
1021 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); 1030 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_);
1022 restore_work_area_insets_ = Shell::GetScreen()->GetPrimaryDisplay(). 1031 restore_work_area_insets_ =
1023 GetWorkAreaInsets(); 1032 gfx::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets();
1024 Shell::GetInstance()->SetDisplayWorkAreaInsets( 1033 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1025 Shell::GetPrimaryRootWindow(), 1034 Shell::GetPrimaryRootWindow(),
1026 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); 1035 gfx::Insets(0, 0, keyboard_bounds_.height(), 0));
1027 } 1036 }
1028 1037
1029 void HideKeyboard() { 1038 void HideKeyboard() {
1030 Shell::GetInstance()->SetDisplayWorkAreaInsets( 1039 Shell::GetInstance()->SetDisplayWorkAreaInsets(
1031 Shell::GetPrimaryRootWindow(), 1040 Shell::GetPrimaryRootWindow(),
1032 restore_work_area_insets_); 1041 restore_work_area_insets_);
1033 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); 1042 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect());
1034 } 1043 }
1035 1044
1036 void SetKeyboardBounds(const gfx::Rect& bounds) { 1045 void SetKeyboardBounds(const gfx::Rect& bounds) {
1037 keyboard_bounds_ = bounds; 1046 keyboard_bounds_ = bounds;
1038 } 1047 }
1039 1048
1040 private: 1049 private:
1041 gfx::Insets restore_work_area_insets_; 1050 gfx::Insets restore_work_area_insets_;
1042 gfx::Rect keyboard_bounds_; 1051 gfx::Rect keyboard_bounds_;
1043 WorkspaceLayoutManager* layout_manager_; 1052 WorkspaceLayoutManager* layout_manager_;
1044 1053
1045 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); 1054 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest);
1046 }; 1055 };
1047 1056
1048 // Tests that when a child window gains focus the top level window containing it 1057 // Tests that when a child window gains focus the top level window containing it
1049 // is resized to fit the remaining workspace area. 1058 // is resized to fit the remaining workspace area.
1050 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { 1059 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) {
1051 gfx::Rect work_area( 1060 gfx::Rect work_area(
1052 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1061 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
1053 gfx::Rect keyboard_bounds(work_area.x(), 1062 gfx::Rect keyboard_bounds(work_area.x(),
1054 work_area.y() + work_area.height() / 2, 1063 work_area.y() + work_area.height() / 2,
1055 work_area.width(), 1064 work_area.width(),
1056 work_area.height() / 2); 1065 work_area.height() / 2);
1057 1066
1058 SetKeyboardBounds(keyboard_bounds); 1067 SetKeyboardBounds(keyboard_bounds);
1059 1068
1060 aura::test::TestWindowDelegate delegate1; 1069 aura::test::TestWindowDelegate delegate1;
1061 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate( 1070 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate(
1062 &delegate1, -1, work_area)); 1071 &delegate1, -1, work_area));
1063 aura::test::TestWindowDelegate delegate2; 1072 aura::test::TestWindowDelegate delegate2;
1064 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1073 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1065 &delegate2, -1, work_area)); 1074 &delegate2, -1, work_area));
1066 parent_window->AddChild(window.get()); 1075 parent_window->AddChild(window.get());
1067 1076
1068 wm::ActivateWindow(window.get()); 1077 wm::ActivateWindow(window.get());
1069 1078
1070 int available_height = 1079 int available_height =
1071 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1080 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
1072 keyboard_bounds.height(); 1081 keyboard_bounds.height();
1073 1082
1074 gfx::Rect initial_window_bounds(50, 50, 100, 500); 1083 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1075 parent_window->SetBounds(initial_window_bounds); 1084 parent_window->SetBounds(initial_window_bounds);
1076 EXPECT_EQ(initial_window_bounds.ToString(), 1085 EXPECT_EQ(initial_window_bounds.ToString(),
1077 parent_window->bounds().ToString()); 1086 parent_window->bounds().ToString());
1078 ShowKeyboard(); 1087 ShowKeyboard();
1079 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(), 1088 EXPECT_EQ(gfx::Rect(50, 0, 100, available_height).ToString(),
1080 parent_window->bounds().ToString()); 1089 parent_window->bounds().ToString());
1081 HideKeyboard(); 1090 HideKeyboard();
1082 EXPECT_EQ(initial_window_bounds.ToString(), 1091 EXPECT_EQ(initial_window_bounds.ToString(),
1083 parent_window->bounds().ToString()); 1092 parent_window->bounds().ToString());
1084 } 1093 }
1085 1094
1086 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { 1095 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) {
1087 gfx::Rect work_area( 1096 gfx::Rect work_area(
1088 Shell::GetScreen()->GetPrimaryDisplay().work_area()); 1097 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
1089 gfx::Rect keyboard_bounds(work_area.x(), 1098 gfx::Rect keyboard_bounds(work_area.x(),
1090 work_area.y() + work_area.height() / 2, 1099 work_area.y() + work_area.height() / 2,
1091 work_area.width(), 1100 work_area.width(),
1092 work_area.height() / 2); 1101 work_area.height() / 2);
1093 1102
1094 SetKeyboardBounds(keyboard_bounds); 1103 SetKeyboardBounds(keyboard_bounds);
1095 1104
1096 aura::test::TestWindowDelegate delegate; 1105 aura::test::TestWindowDelegate delegate;
1097 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1106 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
1098 &delegate, -1, work_area)); 1107 &delegate, -1, work_area));
1099 1108
1100 int available_height = 1109 int available_height =
1101 Shell::GetScreen()->GetPrimaryDisplay().bounds().height() - 1110 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
1102 keyboard_bounds.height(); 1111 keyboard_bounds.height();
1103 1112
1104 wm::ActivateWindow(window.get()); 1113 wm::ActivateWindow(window.get());
1105 1114
1106 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1115 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1107 ShowKeyboard(); 1116 ShowKeyboard();
1108 EXPECT_EQ(gfx::Rect(work_area.origin(), 1117 EXPECT_EQ(gfx::Rect(work_area.origin(),
1109 gfx::Size(work_area.width(), available_height)).ToString(), 1118 gfx::Size(work_area.width(), available_height)).ToString(),
1110 window->bounds().ToString()); 1119 window->bounds().ToString());
1111 HideKeyboard(); 1120 HideKeyboard();
(...skipping 18 matching lines...) Expand all
1130 EXPECT_EQ(gfx::Rect(50, 1139 EXPECT_EQ(gfx::Rect(50,
1131 keyboard_bounds.y() - keyboard_bounds.height()/2, 1140 keyboard_bounds.y() - keyboard_bounds.height()/2,
1132 occluded_window_bounds.width(), 1141 occluded_window_bounds.width(),
1133 occluded_window_bounds.height()).ToString(), 1142 occluded_window_bounds.height()).ToString(),
1134 window->bounds().ToString()); 1143 window->bounds().ToString());
1135 HideKeyboard(); 1144 HideKeyboard();
1136 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); 1145 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1137 } 1146 }
1138 1147
1139 } // namespace ash 1148 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | ash/wm/workspace/workspace_window_resizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698