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

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

Issue 2017413002: ash: Fix variable names and setters in ShelfLayoutManager and tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shellshelf
Patch Set: review comments 3 Created 4 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
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/common/wm/workspace/workspace_window_resizer.h" 5 #include "ash/common/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/common/wm/window_positioning_utils.h" 7 #include "ash/common/wm/window_positioning_utils.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm/wm_event.h" 9 #include "ash/common/wm/wm_event.h"
10 #include "ash/common/wm/workspace/phantom_window_controller.h" 10 #include "ash/common/wm/workspace/phantom_window_controller.h"
11 #include "ash/display/display_manager.h" 11 #include "ash/display/display_manager.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/screen_util.h" 12 #include "ash/screen_util.h"
14 #include "ash/shelf/shelf_layout_manager.h" 13 #include "ash/shelf/shelf.h"
15 #include "ash/shell.h" 14 #include "ash/shell.h"
16 #include "ash/shell_window_ids.h" 15 #include "ash/shell_window_ids.h"
17 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
18 #include "ash/test/display_manager_test_api.h" 17 #include "ash/test/display_manager_test_api.h"
19 #include "ash/wm/aura/wm_window_aura.h" 18 #include "ash/wm/aura/wm_window_aura.h"
20 #include "ash/wm/window_state_aura.h" 19 #include "ash/wm/window_state_aura.h"
21 #include "ash/wm/window_util.h" 20 #include "ash/wm/window_util.h"
22 #include "ash/wm/workspace_controller.h" 21 #include "ash/wm/workspace_controller.h"
23 #include "base/command_line.h" 22 #include "base/command_line.h"
24 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
26 #include "ui/aura/client/aura_constants.h" 25 #include "ui/aura/client/aura_constants.h"
27 #include "ui/aura/test/test_window_delegate.h" 26 #include "ui/aura/test/test_window_delegate.h"
28 #include "ui/aura/window_event_dispatcher.h" 27 #include "ui/aura/window_event_dispatcher.h"
29 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
30 #include "ui/display/manager/display_layout.h" 29 #include "ui/display/manager/display_layout.h"
31 #include "ui/display/screen.h" 30 #include "ui/display/screen.h"
32 #include "ui/events/gesture_detection/gesture_configuration.h" 31 #include "ui/events/gesture_detection/gesture_configuration.h"
33 #include "ui/events/test/event_generator.h" 32 #include "ui/events/test/event_generator.h"
34 #include "ui/gfx/geometry/insets.h" 33 #include "ui/gfx/geometry/insets.h"
35 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
36 35
37 namespace ash { 36 namespace ash {
38 namespace { 37 namespace {
39 38
40 const int kRootHeight = 600; 39 const int kRootHeight = 600;
41 40
41 Shelf* GetShelf() {
42 return Shelf::ForPrimaryDisplay();
43 }
44
42 // A simple window delegate that returns the specified min size. 45 // A simple window delegate that returns the specified min size.
43 class TestWindowDelegate : public aura::test::TestWindowDelegate { 46 class TestWindowDelegate : public aura::test::TestWindowDelegate {
44 public: 47 public:
45 TestWindowDelegate() { 48 TestWindowDelegate() {
46 } 49 }
47 ~TestWindowDelegate() override {} 50 ~TestWindowDelegate() override {}
48 51
49 void set_min_size(const gfx::Size& size) { 52 void set_min_size(const gfx::Size& size) {
50 min_size_ = size; 53 min_size_ = size;
51 } 54 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 gfx::Point location = resizer.GetInitialLocation(); 178 gfx::Point location = resizer.GetInitialLocation();
176 location.set_x(location.x() + delta_x); 179 location.set_x(location.x() + delta_x);
177 location.set_y(location.y() + delta_y); 180 location.set_y(location.y() + delta_y);
178 return location; 181 return location;
179 } 182 }
180 183
181 std::vector<aura::Window*> empty_windows() const { 184 std::vector<aura::Window*> empty_windows() const {
182 return std::vector<aura::Window*>(); 185 return std::vector<aura::Window*>();
183 } 186 }
184 187
185 ShelfLayoutManager* shelf_layout_manager() {
186 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
187 }
188
189 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) { 188 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) {
190 touch_resize_delegate_.set_window_component(window_component); 189 touch_resize_delegate_.set_window_component(window_component);
191 touch_resize_window_.reset( 190 touch_resize_window_.reset(
192 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0, 191 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0,
193 bounds)); 192 bounds));
194 } 193 }
195 194
196 TestWindowDelegate delegate_; 195 TestWindowDelegate delegate_;
197 TestWindowDelegate delegate2_; 196 TestWindowDelegate delegate2_;
198 TestWindowDelegate delegate3_; 197 TestWindowDelegate delegate3_;
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 995 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
997 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 996 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
998 EXPECT_EQ(base::IntToString(window_x + window_width) + 997 EXPECT_EQ(base::IntToString(window_x + window_width) +
999 ",100 " + 998 ",100 " +
1000 base::IntToString(window_width) + 999 base::IntToString(window_width) +
1001 "x380", window_->bounds().ToString()); 1000 "x380", window_->bounds().ToString());
1002 } 1001 }
1003 1002
1004 // Verifies snapping to edges works. 1003 // Verifies snapping to edges works.
1005 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 1004 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
1006 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 1005 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1007 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1008 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1006 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1009 // Click 50px to the right so that the mouse pointer does not leave the 1007 // Click 50px to the right so that the mouse pointer does not leave the
1010 // workspace ensuring sticky behavior. 1008 // workspace ensuring sticky behavior.
1011 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest( 1009 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest(
1012 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0), 1010 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0),
1013 HTCAPTION)); 1011 HTCAPTION));
1014 ASSERT_TRUE(resizer.get()); 1012 ASSERT_TRUE(resizer.get());
1015 // Move to an x-coordinate of 15, which should not snap. 1013 // Move to an x-coordinate of 15, which should not snap.
1016 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); 1014 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1017 // An x-coordinate of 7 should snap. 1015 // An x-coordinate of 7 should snap.
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 // Move it 50 to the left, which should contract w1 and expand w2-3. 1750 // Move it 50 to the left, which should contract w1 and expand w2-3.
1753 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); 1751 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
1754 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); 1752 EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
1755 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); 1753 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
1756 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); 1754 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
1757 } 1755 }
1758 1756
1759 // The following variants test that windows are resized correctly to the edges 1757 // The following variants test that windows are resized correctly to the edges
1760 // of the screen using touch, when touch point is off of the window border. 1758 // of the screen using touch, when touch point is off of the window border.
1761 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { 1759 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
1762 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 1760 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1763 1761
1764 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); 1762 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
1765 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), 1763 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1766 touch_resize_window_->bounds().ToString()); 1764 touch_resize_window_->bounds().ToString());
1767 1765
1768 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 1766 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1769 touch_resize_window_.get()); 1767 touch_resize_window_.get());
1770 1768
1771 // Drag out of the right border a bit and check if the border is aligned with 1769 // Drag out of the right border a bit and check if the border is aligned with
1772 // the touch point. 1770 // the touch point.
(...skipping 13 matching lines...) Expand all
1786 // Drag even more to snap to the edge. 1784 // Drag even more to snap to the edge.
1787 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2), 1785 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2),
1788 gfx::Point(775, kRootHeight / 2), 1786 gfx::Point(775, kRootHeight / 2),
1789 base::TimeDelta::FromMilliseconds(10), 1787 base::TimeDelta::FromMilliseconds(10),
1790 5); 1788 5);
1791 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(), 1789 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
1792 touch_resize_window_->bounds().ToString()); 1790 touch_resize_window_->bounds().ToString());
1793 } 1791 }
1794 1792
1795 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { 1793 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
1796 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 1794 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1797 1795
1798 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); 1796 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
1799 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), 1797 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1800 touch_resize_window_->bounds().ToString()); 1798 touch_resize_window_->bounds().ToString());
1801 1799
1802 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 1800 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1803 touch_resize_window_.get()); 1801 touch_resize_window_.get());
1804 1802
1805 // Drag out of the left border a bit and check if the border is aligned with 1803 // Drag out of the left border a bit and check if the border is aligned with
1806 // the touch point. 1804 // the touch point.
(...skipping 13 matching lines...) Expand all
1820 // Drag even more to snap to the edge. 1818 // Drag even more to snap to the edge.
1821 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2), 1819 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2),
1822 gfx::Point(25, kRootHeight / 2), 1820 gfx::Point(25, kRootHeight / 2),
1823 base::TimeDelta::FromMilliseconds(10), 1821 base::TimeDelta::FromMilliseconds(10),
1824 5); 1822 5);
1825 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(), 1823 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
1826 touch_resize_window_->bounds().ToString()); 1824 touch_resize_window_->bounds().ToString());
1827 } 1825 }
1828 1826
1829 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { 1827 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
1830 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 1828 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1831 1829
1832 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); 1830 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
1833 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), 1831 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1834 touch_resize_window_->bounds().ToString()); 1832 touch_resize_window_->bounds().ToString());
1835 1833
1836 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 1834 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1837 touch_resize_window_.get()); 1835 touch_resize_window_.get());
1838 1836
1839 // Drag out of the top border a bit and check if the border is aligned with 1837 // Drag out of the top border a bit and check if the border is aligned with
1840 // the touch point. 1838 // the touch point.
(...skipping 13 matching lines...) Expand all
1854 // Drag even more to snap to the edge. 1852 // Drag even more to snap to the edge.
1855 generator.GestureScrollSequence(gfx::Point(400, 40), 1853 generator.GestureScrollSequence(gfx::Point(400, 40),
1856 gfx::Point(400, 25), 1854 gfx::Point(400, 25),
1857 base::TimeDelta::FromMilliseconds(10), 1855 base::TimeDelta::FromMilliseconds(10),
1858 5); 1856 5);
1859 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(), 1857 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
1860 touch_resize_window_->bounds().ToString()); 1858 touch_resize_window_->bounds().ToString());
1861 } 1859 }
1862 1860
1863 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { 1861 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
1864 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 1862 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
1865 1863
1866 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); 1864 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
1867 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), 1865 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
1868 touch_resize_window_->bounds().ToString()); 1866 touch_resize_window_->bounds().ToString());
1869 1867
1870 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 1868 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1871 touch_resize_window_.get()); 1869 touch_resize_window_.get());
1872 1870
1873 // Drag out of the bottom border a bit and check if the border is aligned with 1871 // Drag out of the bottom border a bit and check if the border is aligned with
1874 // the touch point. 1872 // the touch point.
(...skipping 13 matching lines...) Expand all
1888 // Drag even more to snap to the edge. 1886 // Drag even more to snap to the edge.
1889 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), 1887 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1890 gfx::Point(400, kRootHeight - 25), 1888 gfx::Point(400, kRootHeight - 25),
1891 base::TimeDelta::FromMilliseconds(10), 1889 base::TimeDelta::FromMilliseconds(10),
1892 5); 1890 5);
1893 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), 1891 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1894 touch_resize_window_->bounds().ToString()); 1892 touch_resize_window_->bounds().ToString());
1895 } 1893 }
1896 1894
1897 } // namespace ash 1895 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager_unittest.cc ('k') | ash/wm/workspace_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698