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

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

Issue 15008002: Make touch-resizing windows to screen edge possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied some reviews 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 | Annotate | Revision Log
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_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/ash_constants.h"
7 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
8 #include "ash/display/display_controller.h" 9 #include "ash/display/display_controller.h"
9 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 11 #include "ash/screen_ash.h"
11 #include "ash/shelf/shelf_layout_manager.h" 12 #include "ash/shelf/shelf_layout_manager.h"
12 #include "ash/shell.h" 13 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
14 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
15 #include "ash/wm/property_util.h" 16 #include "ash/wm/property_util.h"
16 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
17 #include "ash/wm/workspace/phantom_window_controller.h" 18 #include "ash/wm/workspace/phantom_window_controller.h"
18 #include "ash/wm/workspace/snap_sizer.h" 19 #include "ash/wm/workspace/snap_sizer.h"
19 #include "ash/wm/workspace_controller.h" 20 #include "ash/wm/workspace_controller.h"
20 #include "base/command_line.h" 21 #include "base/command_line.h"
21 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
26 #include "ui/aura/test/event_generator.h"
25 #include "ui/aura/test/test_window_delegate.h" 27 #include "ui/aura/test/test_window_delegate.h"
26 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
27 #include "ui/gfx/insets.h" 29 #include "ui/gfx/insets.h"
28 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
29 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
30 32
31 namespace ash { 33 namespace ash {
32 namespace internal { 34 namespace internal {
33 namespace { 35 namespace {
34 36
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 window4_->Init(ui::LAYER_NOT_DRAWN); 108 window4_->Init(ui::LAYER_NOT_DRAWN);
107 SetDefaultParentByPrimaryRootWindow(window4_.get()); 109 SetDefaultParentByPrimaryRootWindow(window4_.get());
108 window4_->set_id(4); 110 window4_->set_id(4);
109 } 111 }
110 112
111 virtual void TearDown() OVERRIDE { 113 virtual void TearDown() OVERRIDE {
112 window_.reset(); 114 window_.reset();
113 window2_.reset(); 115 window2_.reset();
114 window3_.reset(); 116 window3_.reset();
115 window4_.reset(); 117 window4_.reset();
118 touch_resize_window_.reset();
116 AshTestBase::TearDown(); 119 AshTestBase::TearDown();
117 } 120 }
118 121
119 // Returns a string identifying the z-order of each of the known child windows 122 // Returns a string identifying the z-order of each of the known child windows
120 // of |parent|. The returned string constains the id of the known windows and 123 // of |parent|. The returned string constains the id of the known windows and
121 // is ordered from topmost to bottomost windows. 124 // is ordered from topmost to bottomost windows.
122 std::string WindowOrderAsString(aura::Window* parent) const { 125 std::string WindowOrderAsString(aura::Window* parent) const {
123 std::string result; 126 std::string result;
124 const aura::Window::Windows& windows = parent->children(); 127 const aura::Window::Windows& windows = parent->children();
125 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); 128 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin();
(...skipping 18 matching lines...) Expand all
144 } 147 }
145 148
146 std::vector<aura::Window*> empty_windows() const { 149 std::vector<aura::Window*> empty_windows() const {
147 return std::vector<aura::Window*>(); 150 return std::vector<aura::Window*>();
148 } 151 }
149 152
150 internal::ShelfLayoutManager* shelf_layout_manager() { 153 internal::ShelfLayoutManager* shelf_layout_manager() {
151 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 154 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
152 } 155 }
153 156
157 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) {
158 touch_resize_delegate_.set_window_component(window_component);
159 touch_resize_window_.reset(
160 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0,
161 bounds));
162 gfx::Insets mouse_insets = gfx::Insets(-ash::kResizeOutsideBoundsSize,
163 -ash::kResizeOutsideBoundsSize,
164 -ash::kResizeOutsideBoundsSize,
165 -ash::kResizeOutsideBoundsSize);
166 gfx::Insets touch_insets = mouse_insets.Scale(
167 ash::kResizeOutsideBoundsScaleForTouch);
168 touch_resize_window_->SetHitTestBoundsOverrideOuter(mouse_insets,
169 touch_insets);
170 touch_resize_window_->set_hit_test_bounds_override_inner(mouse_insets);
171 }
172
154 TestWindowDelegate delegate_; 173 TestWindowDelegate delegate_;
155 TestWindowDelegate delegate2_; 174 TestWindowDelegate delegate2_;
156 TestWindowDelegate delegate3_; 175 TestWindowDelegate delegate3_;
157 TestWindowDelegate delegate4_; 176 TestWindowDelegate delegate4_;
158 scoped_ptr<aura::Window> window_; 177 scoped_ptr<aura::Window> window_;
159 scoped_ptr<aura::Window> window2_; 178 scoped_ptr<aura::Window> window2_;
160 scoped_ptr<aura::Window> window3_; 179 scoped_ptr<aura::Window> window3_;
161 scoped_ptr<aura::Window> window4_; 180 scoped_ptr<aura::Window> window4_;
162 181
182 TestWindowDelegate touch_resize_delegate_;
183 scoped_ptr<aura::Window> touch_resize_window_;
184
163 private: 185 private:
164 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 186 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
165 }; 187 };
166 188
167 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest { 189 class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest {
168 public: 190 public:
169 WorkspaceWindowResizerTestSticky() {} 191 WorkspaceWindowResizerTestSticky() {}
170 virtual ~WorkspaceWindowResizerTestSticky() {} 192 virtual ~WorkspaceWindowResizerTestSticky() {}
171 193
172 virtual void SetUp() OVERRIDE { 194 virtual void SetUp() OVERRIDE {
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1620 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1599 window_.get(), gfx::Point(), HTRIGHT, windows)); 1621 window_.get(), gfx::Point(), HTRIGHT, windows));
1600 ASSERT_TRUE(resizer.get()); 1622 ASSERT_TRUE(resizer.get());
1601 // Move it 50 to the left, which should contract w1 and expand w2-3. 1623 // Move it 50 to the left, which should contract w1 and expand w2-3.
1602 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); 1624 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1603 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); 1625 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1604 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); 1626 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1605 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); 1627 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1606 } 1628 }
1607 1629
1630 // The following variants test that windows are resized correctly to the edges
1631 // of the screen using touch, when touch point is off of the window border.
1632 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
1633 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1634
1635 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
1636 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1637 touch_resize_window_->bounds().ToString());
1638
1639 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1640 touch_resize_window_.get());
1641
1642 // Drag out of the right border and resize leftward.
1643 generator.GestureScrollSequence(gfx::Point(720, kRootHeight / 2),
1644 gfx::Point(670, kRootHeight / 2),
1645 base::TimeDelta::FromMilliseconds(100),
1646 1);
1647 EXPECT_EQ(gfx::Rect(100, 100, 550, kRootHeight - 200).ToString(),
1648 touch_resize_window_->bounds().ToString());
1649 // Drag out of the right border and resize rightward.
1650 generator.GestureScrollSequence(gfx::Point(670, kRootHeight / 2),
1651 gfx::Point(770, kRootHeight / 2),
1652 base::TimeDelta::FromMilliseconds(100),
1653 1);
1654 EXPECT_EQ(gfx::Rect(100, 100, 666, kRootHeight - 200).ToString(),
1655 touch_resize_window_->bounds().ToString());
1656 // Drag the right border and resize rightward to snap.
1657 generator.GestureScrollSequence(gfx::Point(766, kRootHeight / 2),
1658 gfx::Point(785, kRootHeight / 2),
1659 base::TimeDelta::FromMilliseconds(100),
1660 1);
1661 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
1662 touch_resize_window_->bounds().ToString());
1663 }
1664
1665 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1666 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1667
1668 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1669 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1670 touch_resize_window_->bounds().ToString());
1671
1672 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1673 touch_resize_window_.get());
1674
1675 // Drag out of the left border and resize rightward.
1676 generator.GestureScrollSequence(gfx::Point(80, kRootHeight / 2),
1677 gfx::Point(130, kRootHeight / 2),
1678 base::TimeDelta::FromMilliseconds(100),
1679 1);
1680 EXPECT_EQ(gfx::Rect(150, 100, 550, kRootHeight - 200).ToString(),
1681 touch_resize_window_->bounds().ToString());
1682 // Drag out of the left border and resize leftward.
1683 generator.GestureScrollSequence(gfx::Point(130, kRootHeight / 2),
1684 gfx::Point(30, kRootHeight / 2),
1685 base::TimeDelta::FromMilliseconds(100),
1686 1);
1687 EXPECT_EQ(gfx::Rect(34, 100, 666, kRootHeight - 200).ToString(),
1688 touch_resize_window_->bounds().ToString());
1689 // Drag the left border and resize leftward to snap.
1690 generator.GestureScrollSequence(gfx::Point(34, kRootHeight / 2),
1691 gfx::Point(15, kRootHeight / 2),
1692 base::TimeDelta::FromMilliseconds(100),
1693 1);
1694 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
1695 touch_resize_window_->bounds().ToString());
1696 }
1697
1698 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1699 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1700
1701 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1702 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1703 touch_resize_window_->bounds().ToString());
1704
1705 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1706 touch_resize_window_.get());
1707
1708 // Drag out of the top border and resize downward.
1709 generator.GestureScrollSequence(gfx::Point(400, 80),
1710 gfx::Point(400, 130),
1711 base::TimeDelta::FromMilliseconds(100),
1712 1);
1713 EXPECT_EQ(gfx::Rect(100, 150, 600, kRootHeight - 250).ToString(),
1714 touch_resize_window_->bounds().ToString());
1715 // Drag out of the top border and resize upward.
1716 generator.GestureScrollSequence(gfx::Point(400, 130),
1717 gfx::Point(400, 30),
1718 base::TimeDelta::FromMilliseconds(100),
1719 1);
1720 EXPECT_EQ(gfx::Rect(100, 34, 600, kRootHeight - 134).ToString(),
1721 touch_resize_window_->bounds().ToString());
1722 // Drag the top border and resize upward to snap.
1723 generator.GestureScrollSequence(gfx::Point(400, 34),
1724 gfx::Point(400, 15),
1725 base::TimeDelta::FromMilliseconds(100),
1726 1);
1727 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
1728 touch_resize_window_->bounds().ToString());
1729 }
1730
1731 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1732 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1733
1734 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1735 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1736 touch_resize_window_->bounds().ToString());
1737
1738 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1739 touch_resize_window_.get());
1740
1741 // Drag out of the bottom border and resize upward.
1742 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 80),
1743 gfx::Point(400, kRootHeight - 130),
1744 base::TimeDelta::FromMilliseconds(100),
1745 1);
1746 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 250).ToString(),
1747 touch_resize_window_->bounds().ToString());
1748 // Drag out of the bottom border and resize downward.
1749 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 130),
1750 gfx::Point(400, kRootHeight - 30),
1751 base::TimeDelta::FromMilliseconds(100),
1752 1);
1753 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 134).ToString(),
1754 touch_resize_window_->bounds().ToString());
1755 // Drag the bottom border and resize downward to snap.
1756 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 34),
1757 gfx::Point(400, kRootHeight - 15),
1758 base::TimeDelta::FromMilliseconds(100),
1759 1);
1760 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1761 touch_resize_window_->bounds().ToString());
1762 }
1608 } // namespace internal 1763 } // namespace internal
1609 } // namespace ash 1764 } // namespace ash
OLDNEW
« ash/wm/window_resizer.cc ('K') | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698