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

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: Added test coverage 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
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | no next file » | 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) 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 int expected_height = kRootHeight - 200;
1637 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
sadrul 2013/06/04 19:17:24 This is better done using gfx::Rect(100, 100, 600,
mohsen 2013/06/04 19:30:08 What about directly comparing the gfx::Rects, inst
sadrul 2013/06/04 19:42:46 Direct Rect-comparisons don't show human-readable
mohsen 2013/06/04 20:13:33 I see. Done.
1638 touch_resize_window_->bounds().ToString());
1639
1640 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1641 touch_resize_window_.get());
1642
1643 // Drag out of the right border and resize leftward.
1644 generator.GestureScrollSequence(gfx::Point(720, kRootHeight / 2),
1645 gfx::Point(670, kRootHeight / 2),
1646 base::TimeDelta::FromMilliseconds(100),
1647 1);
1648 expected_height = kRootHeight - 200;
1649 EXPECT_EQ("100,100 550x" + base::IntToString(expected_height),
1650 touch_resize_window_->bounds().ToString());
1651 // Drag out of the right border and resize rightward.
1652 generator.GestureScrollSequence(gfx::Point(670, kRootHeight / 2),
1653 gfx::Point(770, kRootHeight / 2),
1654 base::TimeDelta::FromMilliseconds(100),
1655 1);
1656 expected_height = kRootHeight - 200;
1657 EXPECT_EQ("100,100 666x" + base::IntToString(expected_height),
sadrul 2013/06/04 19:17:24 Why should the height change when dragging towards
mohsen 2013/06/04 19:30:08 The height is not changing. It just depends on kRo
sadrul 2013/06/04 19:42:46 I mean in line 1656
mohsen 2013/06/04 20:13:33 I'm talking about the same line! The height of the
1658 touch_resize_window_->bounds().ToString());
1659 // Drag the right border and resize rightward to snap.
1660 generator.GestureScrollSequence(gfx::Point(766, kRootHeight / 2),
1661 gfx::Point(785, kRootHeight / 2),
1662 base::TimeDelta::FromMilliseconds(100),
1663 1);
1664 expected_height = kRootHeight - 200;
1665 EXPECT_EQ("100,100 700x" + base::IntToString(expected_height),
1666 touch_resize_window_->bounds().ToString());
1667 }
1668
1669 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1670 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1671
1672 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1673 int expected_height = kRootHeight - 200;
1674 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1675 touch_resize_window_->bounds().ToString());
1676
1677 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1678 touch_resize_window_.get());
1679
1680 // Drag out of the left border and resize rightward.
1681 generator.GestureScrollSequence(gfx::Point(80, kRootHeight / 2),
1682 gfx::Point(130, kRootHeight / 2),
1683 base::TimeDelta::FromMilliseconds(100),
1684 1);
1685 expected_height = kRootHeight - 200;
1686 EXPECT_EQ("150,100 550x" + base::IntToString(expected_height),
1687 touch_resize_window_->bounds().ToString());
1688 // Drag out of the left border and resize leftward.
1689 generator.GestureScrollSequence(gfx::Point(130, kRootHeight / 2),
1690 gfx::Point(30, kRootHeight / 2),
1691 base::TimeDelta::FromMilliseconds(100),
1692 1);
1693 expected_height = kRootHeight - 200;
1694 EXPECT_EQ("34,100 666x" + base::IntToString(expected_height),
1695 touch_resize_window_->bounds().ToString());
1696 // Drag the left border and resize leftward to snap.
1697 generator.GestureScrollSequence(gfx::Point(34, kRootHeight / 2),
1698 gfx::Point(15, kRootHeight / 2),
1699 base::TimeDelta::FromMilliseconds(100),
1700 1);
1701 expected_height = kRootHeight - 200;
1702 EXPECT_EQ("0,100 700x" + base::IntToString(expected_height),
1703 touch_resize_window_->bounds().ToString());
1704 }
1705
1706 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1707 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1708
1709 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1710 int expected_height = kRootHeight - 200;
1711 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1712 touch_resize_window_->bounds().ToString());
1713
1714 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1715 touch_resize_window_.get());
1716
1717 // Drag out of the top border and resize downward.
1718 generator.GestureScrollSequence(gfx::Point(400, 80),
1719 gfx::Point(400, 130),
1720 base::TimeDelta::FromMilliseconds(100),
1721 1);
1722 expected_height = kRootHeight - 250;
1723 EXPECT_EQ("100,150 600x" + base::IntToString(expected_height),
1724 touch_resize_window_->bounds().ToString());
1725 // Drag out of the top border and resize upward.
1726 generator.GestureScrollSequence(gfx::Point(400, 130),
1727 gfx::Point(400, 30),
1728 base::TimeDelta::FromMilliseconds(100),
1729 1);
1730 expected_height = kRootHeight - 134;
1731 EXPECT_EQ("100,34 600x" + base::IntToString(expected_height),
1732 touch_resize_window_->bounds().ToString());
1733 // Drag the top border and resize upward to snap.
1734 generator.GestureScrollSequence(gfx::Point(400, 34),
1735 gfx::Point(400, 15),
1736 base::TimeDelta::FromMilliseconds(100),
1737 1);
1738 expected_height = kRootHeight - 100;
1739 EXPECT_EQ("100,0 600x" + base::IntToString(expected_height),
1740 touch_resize_window_->bounds().ToString());
1741 }
1742
1743 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1744 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1745
1746 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1747 int expected_height = kRootHeight - 200;
1748 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1749 touch_resize_window_->bounds().ToString());
1750
1751 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1752 touch_resize_window_.get());
1753
1754 // Drag out of the bottom border and resize upward.
1755 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 80),
1756 gfx::Point(400, kRootHeight - 130),
1757 base::TimeDelta::FromMilliseconds(100),
1758 1);
1759 expected_height = kRootHeight - 250;
1760 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1761 touch_resize_window_->bounds().ToString());
1762 // Drag out of the bottom border and resize downward.
1763 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 130),
1764 gfx::Point(400, kRootHeight - 30),
1765 base::TimeDelta::FromMilliseconds(100),
1766 1);
1767 expected_height = kRootHeight - 134;
1768 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1769 touch_resize_window_->bounds().ToString());
1770 // Drag the bottom border and resize downward to snap.
1771 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 34),
1772 gfx::Point(400, kRootHeight - 15),
1773 base::TimeDelta::FromMilliseconds(100),
1774 1);
1775 expected_height = kRootHeight - 100;
1776 EXPECT_EQ("100,100 600x" + base::IntToString(expected_height),
1777 touch_resize_window_->bounds().ToString());
1778 }
1608 } // namespace internal 1779 } // namespace internal
1609 } // namespace ash 1780 } // namespace ash
OLDNEW
« no previous file with comments | « 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