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

Side by Side Diff: ash/wm/window_util_unittest.cc

Issue 2696073002: Merge ShelfItemDelegate::ItemSelected & LauncherItemDelegate::Activate. (Closed)
Patch Set: nit Created 3 years, 10 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
« no previous file with comments | « ash/wm/window_util.cc ('k') | chrome/browser/ui/ash/app_list/app_list_controller_ash.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/window_util.h" 5 #include "ash/wm/window_util.h"
6 6
7 #include "ash/common/wm/window_positioning_utils.h" 7 #include "ash/common/wm/window_positioning_utils.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/window_state_aura.h" 11 #include "ash/wm/window_state_aura.h"
12 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
13 #include "ui/display/manager/display_manager.h" 13 #include "ui/display/manager/display_manager.h"
14 #include "ui/display/screen.h" 14 #include "ui/display/screen.h"
15 15
16 namespace ash { 16 namespace ash {
17 namespace wm {
17 18
18 namespace { 19 namespace {
19 20
20 std::string GetAdjustedBounds(const gfx::Rect& visible, 21 std::string GetAdjustedBounds(const gfx::Rect& visible,
21 gfx::Rect to_be_adjusted) { 22 gfx::Rect to_be_adjusted) {
22 wm::AdjustBoundsToEnsureMinimumWindowVisibility(visible, &to_be_adjusted); 23 AdjustBoundsToEnsureMinimumWindowVisibility(visible, &to_be_adjusted);
23 return to_be_adjusted.ToString(); 24 return to_be_adjusted.ToString();
24 } 25 }
25 } 26
27 } // namespace
26 28
27 typedef test::AshTestBase WindowUtilTest; 29 typedef test::AshTestBase WindowUtilTest;
28 30
29 TEST_F(WindowUtilTest, CenterWindow) { 31 TEST_F(WindowUtilTest, CenterWindow) {
30 UpdateDisplay("500x400, 600x400"); 32 UpdateDisplay("500x400, 600x400");
31 std::unique_ptr<aura::Window> window( 33 std::unique_ptr<aura::Window> window(
32 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100))); 34 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100)));
33 35
34 wm::WindowState* window_state = wm::GetWindowState(window.get()); 36 WindowState* window_state = GetWindowState(window.get());
35 EXPECT_FALSE(window_state->bounds_changed_by_user()); 37 EXPECT_FALSE(window_state->bounds_changed_by_user());
36 38
37 wm::CenterWindow(WmWindow::Get(window.get())); 39 CenterWindow(WmWindow::Get(window.get()));
38 // Centring window is considered as a user's action. 40 // Centring window is considered as a user's action.
39 EXPECT_TRUE(window_state->bounds_changed_by_user()); 41 EXPECT_TRUE(window_state->bounds_changed_by_user());
40 EXPECT_EQ("200,126 100x100", window->bounds().ToString()); 42 EXPECT_EQ("200,126 100x100", window->bounds().ToString());
41 EXPECT_EQ("200,126 100x100", window->GetBoundsInScreen().ToString()); 43 EXPECT_EQ("200,126 100x100", window->GetBoundsInScreen().ToString());
42 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), 44 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
43 display_manager()->GetSecondaryDisplay()); 45 display_manager()->GetSecondaryDisplay());
44 wm::CenterWindow(WmWindow::Get(window.get())); 46 CenterWindow(WmWindow::Get(window.get()));
45 EXPECT_EQ("250,126 100x100", window->bounds().ToString()); 47 EXPECT_EQ("250,126 100x100", window->bounds().ToString());
46 EXPECT_EQ("750,126 100x100", window->GetBoundsInScreen().ToString()); 48 EXPECT_EQ("750,126 100x100", window->GetBoundsInScreen().ToString());
47 } 49 }
48 50
49 TEST_F(WindowUtilTest, AdjustBoundsToEnsureMinimumVisibility) { 51 TEST_F(WindowUtilTest, AdjustBoundsToEnsureMinimumVisibility) {
50 const gfx::Rect visible_bounds(0, 0, 100, 100); 52 const gfx::Rect visible_bounds(0, 0, 100, 100);
51 53
52 EXPECT_EQ("0,0 90x90", 54 EXPECT_EQ("0,0 90x90",
53 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 90, 90))); 55 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 90, 90)));
54 EXPECT_EQ("0,0 100x100", 56 EXPECT_EQ("0,0 100x100",
55 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 150, 150))); 57 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 0, 150, 150)));
56 EXPECT_EQ("-50,0 100x100", 58 EXPECT_EQ("-50,0 100x100",
57 GetAdjustedBounds(visible_bounds, gfx::Rect(-50, -50, 150, 150))); 59 GetAdjustedBounds(visible_bounds, gfx::Rect(-50, -50, 150, 150)));
58 EXPECT_EQ("-75,10 100x100", 60 EXPECT_EQ("-75,10 100x100",
59 GetAdjustedBounds(visible_bounds, gfx::Rect(-100, 10, 150, 150))); 61 GetAdjustedBounds(visible_bounds, gfx::Rect(-100, 10, 150, 150)));
60 EXPECT_EQ("75,75 100x100", 62 EXPECT_EQ("75,75 100x100",
61 GetAdjustedBounds(visible_bounds, gfx::Rect(100, 100, 150, 150))); 63 GetAdjustedBounds(visible_bounds, gfx::Rect(100, 100, 150, 150)));
62 64
63 // For windows that have smaller dimensions than wm::kMinimumOnScreenArea, 65 // For windows that have smaller dimensions than kMinimumOnScreenArea,
64 // we should adjust bounds accordingly, leaving no white space. 66 // we should adjust bounds accordingly, leaving no white space.
65 EXPECT_EQ("50,80 20x20", 67 EXPECT_EQ("50,80 20x20",
66 GetAdjustedBounds(visible_bounds, gfx::Rect(50, 80, 20, 20))); 68 GetAdjustedBounds(visible_bounds, gfx::Rect(50, 80, 20, 20)));
67 EXPECT_EQ("80,50 20x20", 69 EXPECT_EQ("80,50 20x20",
68 GetAdjustedBounds(visible_bounds, gfx::Rect(80, 50, 20, 20))); 70 GetAdjustedBounds(visible_bounds, gfx::Rect(80, 50, 20, 20)));
69 EXPECT_EQ("0,50 20x20", 71 EXPECT_EQ("0,50 20x20",
70 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 50, 20, 20))); 72 GetAdjustedBounds(visible_bounds, gfx::Rect(0, 50, 20, 20)));
71 EXPECT_EQ("50,0 20x20", 73 EXPECT_EQ("50,0 20x20",
72 GetAdjustedBounds(visible_bounds, gfx::Rect(50, 0, 20, 20))); 74 GetAdjustedBounds(visible_bounds, gfx::Rect(50, 0, 20, 20)));
73 EXPECT_EQ("50,80 20x20", 75 EXPECT_EQ("50,80 20x20",
(...skipping 28 matching lines...) Expand all
102 EXPECT_EQ( 104 EXPECT_EQ(
103 "-250,-40 100x100", 105 "-250,-40 100x100",
104 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-250, -40, 150, 150))); 106 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-250, -40, 150, 150)));
105 EXPECT_EQ( 107 EXPECT_EQ(
106 "-275,-50 100x100", 108 "-275,-50 100x100",
107 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-400, -60, 150, 150))); 109 GetAdjustedBounds(visible_bounds_left, gfx::Rect(-400, -60, 150, 150)));
108 EXPECT_EQ("-125,0 100x100", 110 EXPECT_EQ("-125,0 100x100",
109 GetAdjustedBounds(visible_bounds_left, gfx::Rect(0, 0, 150, 150))); 111 GetAdjustedBounds(visible_bounds_left, gfx::Rect(0, 0, 150, 150)));
110 } 112 }
111 113
114 TEST_F(WindowUtilTest, MoveWindowToDisplay) {
115 UpdateDisplay("500x400, 600x400");
116 std::unique_ptr<aura::Window> window(
117 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 100, 100)));
118 display::Screen* screen = display::Screen::GetScreen();
119 const int64_t original_display_id =
120 screen->GetDisplayNearestWindow(window.get()).id();
121 EXPECT_EQ(screen->GetPrimaryDisplay().id(), original_display_id);
122 const int original_container_id = window->parent()->id();
123 const aura::Window* original_root = window->GetRootWindow();
124
125 EXPECT_FALSE(MoveWindowToDisplay(window.get(), display::kInvalidDisplayId));
126 EXPECT_EQ(original_display_id,
127 screen->GetDisplayNearestWindow(window.get()).id());
128 EXPECT_FALSE(MoveWindowToDisplay(window.get(), original_display_id));
129 EXPECT_EQ(original_display_id,
130 screen->GetDisplayNearestWindow(window.get()).id());
131
132 ASSERT_EQ(2, screen->GetNumDisplays());
133 const int64_t secondary_display_id = screen->GetAllDisplays()[1].id();
134 EXPECT_NE(original_display_id, secondary_display_id);
135 EXPECT_TRUE(MoveWindowToDisplay(window.get(), secondary_display_id));
136 EXPECT_EQ(secondary_display_id,
137 screen->GetDisplayNearestWindow(window.get()).id());
138 EXPECT_EQ(original_container_id, window->parent()->id());
139 EXPECT_NE(original_root, window->GetRootWindow());
140
141 EXPECT_TRUE(MoveWindowToDisplay(window.get(), original_display_id));
142 EXPECT_EQ(original_display_id,
143 screen->GetDisplayNearestWindow(window.get()).id());
144 EXPECT_EQ(original_container_id, window->parent()->id());
145 EXPECT_EQ(original_root, window->GetRootWindow());
146 }
147
148 } // namespace wm
112 } // namespace ash 149 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_util.cc ('k') | chrome/browser/ui/ash/app_list/app_list_controller_ash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698