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

Unified Diff: ash/wm/dock/dock_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 (no logs) 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 side-by-side diff with in-line comments
Download patch
Index: ash/wm/dock/dock_layout_manager_unittest.cc
diff --git a/ash/wm/dock/dock_layout_manager_unittest.cc b/ash/wm/dock/dock_layout_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6dbb160a831c002a6b665c0cf0e0badf9a7e0f36
--- /dev/null
+++ b/ash/wm/dock/dock_layout_manager_unittest.cc
@@ -0,0 +1,251 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/wm/dock/dock_layout_manager.h"
+
+#include "ash/ash_switches.h"
+#include "ash/launcher/launcher.h"
+#include "ash/launcher/launcher_button.h"
+#include "ash/launcher/launcher_model.h"
+#include "ash/launcher/launcher_view.h"
+#include "ash/root_window_controller.h"
+#include "ash/screen_ash.h"
+#include "ash/shelf/shelf_layout_manager.h"
+#include "ash/shelf/shelf_types.h"
+#include "ash/shelf/shelf_widget.h"
+#include "ash/shell.h"
+#include "ash/shell_window_ids.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/test/launcher_view_test_api.h"
+#include "ash/test/shell_test_api.h"
+#include "ash/test/test_launcher_delegate.h"
+#include "ash/wm/dock/dock_layout_manager.h"
+#include "ash/wm/drag_window_resizer.h"
+#include "ash/wm/panels/panel_layout_manager.h"
+#include "ash/wm/window_properties.h"
+#include "ash/wm/window_util.h"
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/compiler_specific.h"
+#include "base/run_loop.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/test/event_generator.h"
+#include "ui/aura/test/test_windows.h"
+#include "ui/aura/window.h"
+#include "ui/base/hit_test.h"
+#include "ui/views/corewm/corewm_switches.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+namespace internal {
+
+using aura::test::WindowIsAbove;
+
+class DockLayoutManagerTest
+ : public test::AshTestBase,
+ public testing::WithParamInterface<bool> {
+ public:
+ DockLayoutManagerTest() : test_panels_(GetParam()) {}
+ virtual ~DockLayoutManagerTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ ash::switches::kAshEnableStickyEdges);
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ ash::switches::kAshEnableDockedWindows);
+ AshTestBase::SetUp();
+ UpdateDisplay("600x400");
+ ASSERT_TRUE(test::TestLauncherDelegate::instance());
+
+ launcher_view_test_.reset(new test::LauncherViewTestAPI(
+ Launcher::ForPrimaryDisplay()->GetLauncherViewForTest()));
+ launcher_view_test_->SetAnimationDuration(1);
+ }
+
+ protected:
+ aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
+ return (test_panels_) ?
+ CreatePanel(bounds) : CreateTestWindowInShellWithBounds(bounds);
+ }
+
+ aura::Window* CreatePanel(const gfx::Rect& bounds) {
+ aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
+ NULL,
+ aura::client::WINDOW_TYPE_PANEL,
+ 0,
+ bounds);
+ test::TestLauncherDelegate* launcher_delegate =
+ test::TestLauncherDelegate::instance();
+ launcher_delegate->AddLauncherItem(window);
+ PanelLayoutManager* manager =
+ static_cast<PanelLayoutManager*>(GetPanelContainer(window)->
+ layout_manager());
+ manager->Relayout();
+ return window;
+ }
+
+ aura::Window* GetPanelContainer(aura::Window* panel) {
+ return Shell::GetContainer(panel->GetRootWindow(),
+ internal::kShellWindowId_PanelContainer);
+ }
+
+ static WindowResizer* CreateSomeWindowResizer(
+ aura::Window* window,
+ const gfx::Point& point_in_parent,
+ int window_component) {
+ return static_cast<WindowResizer*>(CreateWindowResizer(
+ window, point_in_parent, window_component).release());
+ }
+
+ void DragStart(aura::Window* window) {
+ initial_location_in_parent_ = window->bounds().origin();
+ resizer_.reset(CreateSomeWindowResizer(window,
+ initial_location_in_parent_,
+ HTCAPTION));
+ ASSERT_TRUE(resizer_.get());
+ }
+
+ void DragStartAtOffsetFromwindowOrigin(aura::Window* window,
+ int dx,
+ int dy) {
+ initial_location_in_parent_ =
+ window->bounds().origin() + gfx::Vector2d(dx, dy);
+ resizer_.reset(CreateSomeWindowResizer(window,
+ initial_location_in_parent_,
+ HTCAPTION));
+ ASSERT_TRUE(resizer_.get());
+ }
+
+ void DragMove(int dx, int dy) {
+ resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0);
+ }
+
+ void DragEnd() {
+ resizer_->CompleteDrag(0);
+ resizer_.reset();
+ }
+
+ void DragRevert() {
+ resizer_->RevertDrag();
+ resizer_.reset();
+ }
+
+ int CorrectContainerIdDuringDrag() {
+ return test_panels_ ?
+ internal::kShellWindowId_PanelContainer :
+ internal::kShellWindowId_WorkspaceContainer;
+ }
+
+ // Test dragging the window vertically (to detach if it is a panel) and then
+ // horizontally to the edge with an added offset from the edge of |dx|.
+ void DragRelativeToEdge(DockEdge edge,
+ aura::Window* window,
+ int dx) {
+ DragVerticallyAndRelativeToEdge(edge, window, dx, test_panels_ ? -100 : 20);
+ }
+
+ // Test dragging the panel slightly, then detaching, and then
+ // dragging it vertically by |dy| and horizontally to the edge with an added
+ // offset from the edge of |dx|.
+ void DragVerticallyAndRelativeToEdge(DockEdge edge,
+ aura::Window* window,
+ int dx,
+ int dy) {
+ aura::RootWindow* root_window = window->GetRootWindow();
+ EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
+ DragStart(window);
+ gfx::Rect initial_bounds = window->GetBoundsInScreen();
+
+ if (test_panels_) {
+ EXPECT_TRUE(window->GetProperty(kPanelAttachedKey));
+ // Drag the panel slightly. The window should still be snapped to the
+ // launcher.
+ DragMove(0, 5);
+ EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
+ EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y());
+
+ // Drag further out and the window should now move to the cursor.
+ DragMove(0, dy);
+ EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
+ EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
+
+ // The panel should be detached when the drag completes.
+ DragEnd();
+
+ EXPECT_FALSE(window->GetProperty(kPanelAttachedKey));
+ EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer,
+ window->parent()->id());
+ EXPECT_EQ(root_window, window->GetRootWindow());
+ }
+
+ // avoid snap by clicking away from the border
+ DragStartAtOffsetFromwindowOrigin(window, 5, 5);
+
+ // Drag the panel left or right to the edge (or almost to it).
+ if (edge == DOCK_EDGE_LEFT)
+ dx += window->GetRootWindow()->bounds().x() - initial_bounds.x();
+ else if (edge == DOCK_EDGE_RIGHT)
+ dx += window->GetRootWindow()->bounds().right() - initial_bounds.right();
+ DragMove(dx, test_panels_ ? 0 : dy);
+ // Release the mouse and the panel should be attached to the dock.
+ DragEnd();
+
+ // x-coordinate can get adjusted by snapping or sticking.
+ // y-coordinate should not change by possible docking.
+ EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
+ }
+
+ void WindowInScreen(aura::Window* window) {
+ gfx::Rect bounds = window->GetBoundsInRootWindow();
+ gfx::Point root_point = gfx::Point(bounds.x(), bounds.y());
+ gfx::Display display = ScreenAsh::FindDisplayContainingPoint(root_point);
+
+ gfx::Rect bounds_in_screen = window->GetBoundsInScreen();
+ gfx::Point screen_bottom_right = gfx::Point(
+ bounds_in_screen.right(),
+ bounds_in_screen.bottom());
+ gfx::Rect display_bounds = display.bounds();
+ EXPECT_TRUE(screen_bottom_right.x() < display_bounds.width() &&
+ screen_bottom_right.y() < display_bounds.height());
+ }
+
+ test::LauncherViewTestAPI* launcher_view_test() {
+ return launcher_view_test_.get();
+ }
+
+ private:
+ scoped_ptr<WindowResizer> resizer_;
+ scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_;
+ bool test_panels_;
+
+ // Location at start of the drag in |window->parent()|'s coordinates.
+ gfx::Point initial_location_in_parent_;
+
+ DISALLOW_COPY_AND_ASSIGN(DockLayoutManagerTest);
+};
+
+// Tests that a created panel window is successfully added to the panel
+// layout manager.
+TEST_P(DockLayoutManagerTest, AddOneWindow) {
+ gfx::Rect bounds(0, 0, 201, 201);
+ scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
+ EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
+ DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0);
+
+ // The window should be attached and snapped to the right dock.
+ EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT);
+ EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ window->GetBoundsInScreen().right());
+ EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id());
+}
+
+//TODO(varkha): Add more tests for fanning windows in the dock.
+// See http://crbug.com/233334.
+
+// Tests run twice - on both panels and normal windows
+INSTANTIATE_TEST_CASE_P(PanelsOrNormal, DockLayoutManagerTest, testing::Bool());
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698