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

Side by Side Diff: ash/wm/dock/docked_window_layout_manager_unittest.cc

Issue 13896026: Stick windows to sides of workspaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dock with zero width (comments) Created 7 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/dock/docked_window_layout_manager.h"
6
7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher.h"
9 #include "ash/launcher/launcher_button.h"
10 #include "ash/launcher/launcher_model.h"
11 #include "ash/launcher/launcher_view.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/screen_ash.h"
14 #include "ash/shelf/shelf_layout_manager.h"
15 #include "ash/shelf/shelf_types.h"
16 #include "ash/shelf/shelf_widget.h"
17 #include "ash/shell.h"
18 #include "ash/shell_window_ids.h"
19 #include "ash/test/ash_test_base.h"
20 #include "ash/test/launcher_view_test_api.h"
21 #include "ash/test/shell_test_api.h"
22 #include "ash/test/test_launcher_delegate.h"
23 #include "ash/wm/drag_window_resizer.h"
24 #include "ash/wm/panels/panel_layout_manager.h"
25 #include "ash/wm/window_properties.h"
26 #include "ash/wm/window_util.h"
27 #include "base/basictypes.h"
28 #include "base/command_line.h"
29 #include "base/compiler_specific.h"
30 #include "base/run_loop.h"
31 #include "ui/aura/client/aura_constants.h"
32 #include "ui/aura/root_window.h"
33 #include "ui/aura/test/event_generator.h"
34 #include "ui/aura/test/test_windows.h"
35 #include "ui/aura/window.h"
36 #include "ui/base/hit_test.h"
37 #include "ui/views/corewm/corewm_switches.h"
38 #include "ui/views/widget/widget.h"
39
40 namespace ash {
41 namespace internal {
42
43 using aura::test::WindowIsAbove;
44
45 class DockLayoutManagerTest
46 : public test::AshTestBase,
47 public testing::WithParamInterface<bool> {
48 public:
49 DockLayoutManagerTest() : test_panels_(GetParam()) {}
50 virtual ~DockLayoutManagerTest() {}
51
52 virtual void SetUp() OVERRIDE {
53 CommandLine::ForCurrentProcess()->AppendSwitch(
54 ash::switches::kAshEnableStickyEdges);
55 CommandLine::ForCurrentProcess()->AppendSwitch(
56 ash::switches::kAshEnableDockedWindows);
57 AshTestBase::SetUp();
58 UpdateDisplay("600x400");
59 ASSERT_TRUE(test::TestLauncherDelegate::instance());
60
61 launcher_view_test_.reset(new test::LauncherViewTestAPI(
62 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest()));
63 launcher_view_test_->SetAnimationDuration(1);
64 }
65
66 protected:
67 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
68 return (test_panels_) ?
69 CreatePanel(bounds) : CreateTestWindowInShellWithBounds(bounds);
70 }
71
72 aura::Window* CreatePanel(const gfx::Rect& bounds) {
73 aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
74 NULL,
75 aura::client::WINDOW_TYPE_PANEL,
76 0,
77 bounds);
78 test::TestLauncherDelegate* launcher_delegate =
79 test::TestLauncherDelegate::instance();
80 launcher_delegate->AddLauncherItem(window);
81 PanelLayoutManager* manager =
82 static_cast<PanelLayoutManager*>(GetPanelContainer(window)->
83 layout_manager());
84 manager->Relayout();
85 return window;
86 }
87
88 aura::Window* GetPanelContainer(aura::Window* panel) {
89 return Shell::GetContainer(panel->GetRootWindow(),
90 internal::kShellWindowId_PanelContainer);
91 }
92
93 static WindowResizer* CreateSomeWindowResizer(
94 aura::Window* window,
95 const gfx::Point& point_in_parent,
96 int window_component) {
97 return static_cast<WindowResizer*>(CreateWindowResizer(
98 window, point_in_parent, window_component).release());
99 }
100
101 void DragStart(aura::Window* window) {
102 initial_location_in_parent_ = window->bounds().origin();
103 resizer_.reset(CreateSomeWindowResizer(window,
104 initial_location_in_parent_,
105 HTCAPTION));
106 ASSERT_TRUE(resizer_.get());
107 }
108
109 void DragStartAtOffsetFromwindowOrigin(aura::Window* window,
110 int dx,
111 int dy) {
112 initial_location_in_parent_ =
113 window->bounds().origin() + gfx::Vector2d(dx, dy);
114 resizer_.reset(CreateSomeWindowResizer(window,
115 initial_location_in_parent_,
116 HTCAPTION));
117 ASSERT_TRUE(resizer_.get());
118 }
119
120 void DragMove(int dx, int dy) {
121 resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0);
122 }
123
124 void DragEnd() {
125 resizer_->CompleteDrag(0);
126 resizer_.reset();
127 }
128
129 void DragRevert() {
130 resizer_->RevertDrag();
131 resizer_.reset();
132 }
133
134 int CorrectContainerIdDuringDrag() {
135 return test_panels_ ?
136 internal::kShellWindowId_PanelContainer :
137 internal::kShellWindowId_WorkspaceContainer;
138 }
139
140 // Test dragging the window vertically (to detach if it is a panel) and then
141 // horizontally to the edge with an added offset from the edge of |dx|.
142 void DragRelativeToEdge(DockedEdge edge,
143 aura::Window* window,
144 int dx) {
145 DragVerticallyAndRelativeToEdge(edge, window, dx, test_panels_ ? -100 : 20);
146 }
147
148 // Test dragging the panel slightly, then detaching, and then
149 // dragging it vertically by |dy| and horizontally to the edge with an added
150 // offset from the edge of |dx|.
151 void DragVerticallyAndRelativeToEdge(DockedEdge edge,
152 aura::Window* window,
153 int dx,
154 int dy) {
155 aura::RootWindow* root_window = window->GetRootWindow();
156 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
flackr 2013/06/11 17:59:31 Shouldn't the window be in the correct container d
varkha 2013/06/12 04:52:13 Done.
157 DragStart(window);
158 gfx::Rect initial_bounds = window->GetBoundsInScreen();
159
160 if (test_panels_) {
161 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey));
162 // Drag the panel slightly. The window should still be snapped to the
163 // launcher.
164 DragMove(0, 5);
165 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
166 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y());
167
168 // Drag further out and the window should now move to the cursor.
169 DragMove(0, dy);
170 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
171 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
172
173 // The panel should be detached when the drag completes.
174 DragEnd();
175
176 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
177 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer,
178 window->parent()->id());
179 EXPECT_EQ(root_window, window->GetRootWindow());
180 }
flackr 2013/06/11 17:59:31 The snapping behavior is already tested in panel_w
varkha 2013/06/12 04:52:13 Done.
181
182 // avoid snap by clicking away from the border
183 DragStartAtOffsetFromwindowOrigin(window, 5, 5);
184
185 // Drag the panel left or right to the edge (or almost to it).
186 if (edge == DOCKED_EDGE_LEFT)
187 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x();
188 else if (edge == DOCKED_EDGE_RIGHT)
189 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right();
190 DragMove(dx, test_panels_ ? 0 : dy);
191 // Release the mouse and the panel should be attached to the dock.
flackr 2013/06/11 17:59:31 Add Expect that the window's parent is the dock co
varkha 2013/06/12 04:52:13 Whether docking succeeds actually depends on the d
192 DragEnd();
193
194 // x-coordinate can get adjusted by snapping or sticking.
195 // y-coordinate should not change by possible docking.
196 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
197 }
198
199 void WindowInScreen(aura::Window* window) {
flackr 2013/06/11 17:59:31 This doesn't seem to be used.
varkha 2013/06/12 04:52:13 Done.
200 gfx::Rect bounds = window->GetBoundsInRootWindow();
201 gfx::Point root_point = gfx::Point(bounds.x(), bounds.y());
202 gfx::Display display = ScreenAsh::FindDisplayContainingPoint(root_point);
203
204 gfx::Rect bounds_in_screen = window->GetBoundsInScreen();
205 gfx::Point screen_bottom_right = gfx::Point(
206 bounds_in_screen.right(),
207 bounds_in_screen.bottom());
208 gfx::Rect display_bounds = display.bounds();
209 EXPECT_TRUE(screen_bottom_right.x() < display_bounds.width() &&
210 screen_bottom_right.y() < display_bounds.height());
211 }
212
213 test::LauncherViewTestAPI* launcher_view_test() {
214 return launcher_view_test_.get();
215 }
216
217 private:
218 scoped_ptr<WindowResizer> resizer_;
219 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_;
220 bool test_panels_;
221
222 // Location at start of the drag in |window->parent()|'s coordinates.
223 gfx::Point initial_location_in_parent_;
224
225 DISALLOW_COPY_AND_ASSIGN(DockLayoutManagerTest);
226 };
227
228 // Tests that a created window is successfully added to the dock
229 // layout manager.
230 TEST_P(DockLayoutManagerTest, AddOneWindow) {
231 gfx::Rect bounds(0, 0, 201, 201);
232 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
233 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
234 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
235
236 // The window should be attached and snapped to the right dock.
237 EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT);
238 EXPECT_EQ(window->GetRootWindow()->bounds().right(),
239 window->GetBoundsInScreen().right());
240 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id());
241 }
242
243 //TODO(varkha): Add more tests for fanning windows in the dock.
244 // See http://crbug.com/233334.
245
246 // Tests run twice - on both panels and normal windows
247 INSTANTIATE_TEST_CASE_P(PanelsOrNormal, DockLayoutManagerTest, testing::Bool());
flackr 2013/06/11 17:59:31 Rather than adding a bool parameter can you pass t
varkha 2013/06/12 04:52:13 Done.
248
249 } // namespace internal
250 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698