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