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

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

Issue 101773004: Refactor PhantomWindowController so that the PhantomWindowController owns the phantom window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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_constants.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/display/display_manager.h" 9 #include "ash/display/display_manager.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
(...skipping 12 matching lines...) Expand all
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "ui/aura/client/aura_constants.h" 24 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
26 #include "ui/aura/test/event_generator.h" 26 #include "ui/aura/test/event_generator.h"
27 #include "ui/aura/test/test_window_delegate.h" 27 #include "ui/aura/test/test_window_delegate.h"
28 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
29 #include "ui/gfx/insets.h" 29 #include "ui/gfx/insets.h"
30 #include "ui/gfx/screen.h" 30 #include "ui/gfx/screen.h"
31 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
32 32
33 namespace gfx {
34
35 // Class to provide access to SlideAnimation internals for testing.
36 // TODO: this should be next to SlideAnimation, not here.
37 class SlideAnimation::TestApi {
38 public:
39 explicit TestApi(SlideAnimation* animation) : animation_(animation) {}
40
41 void SetStartTime(base::TimeTicks ticks) {
42 animation_->SetStartTime(ticks);
43 }
44
45 void Step(base::TimeTicks ticks) {
46 animation_->Step(ticks);
47 }
48
49 void RunTillComplete() {
50 SetStartTime(base::TimeTicks());
51 Step(base::TimeTicks() +
52 base::TimeDelta::FromMilliseconds(animation_->GetSlideDuration()));
53 EXPECT_EQ(1.0, animation_->GetCurrentValue());
54 }
55
56 private:
57 SlideAnimation* animation_;
58
59 DISALLOW_COPY_AND_ASSIGN(TestApi);
60 };
61
62 }
63
64 namespace ash { 33 namespace ash {
65 namespace internal { 34 namespace internal {
66 namespace { 35 namespace {
67 36
68 const int kRootHeight = 600; 37 const int kRootHeight = 600;
69 38
70 // A simple window delegate that returns the specified min size. 39 // A simple window delegate that returns the specified min size.
71 class TestWindowDelegate : public aura::test::TestWindowDelegate { 40 class TestWindowDelegate : public aura::test::TestWindowDelegate {
72 public: 41 public:
73 TestWindowDelegate() { 42 TestWindowDelegate() {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 gfx::Insets mouse_outer_insets(-ash::kResizeOutsideBoundsSize, 181 gfx::Insets mouse_outer_insets(-ash::kResizeOutsideBoundsSize,
213 -ash::kResizeOutsideBoundsSize, 182 -ash::kResizeOutsideBoundsSize,
214 -ash::kResizeOutsideBoundsSize, 183 -ash::kResizeOutsideBoundsSize,
215 -ash::kResizeOutsideBoundsSize); 184 -ash::kResizeOutsideBoundsSize);
216 gfx::Insets touch_outer_insets = mouse_outer_insets.Scale( 185 gfx::Insets touch_outer_insets = mouse_outer_insets.Scale(
217 ash::kResizeOutsideBoundsScaleForTouch); 186 ash::kResizeOutsideBoundsScaleForTouch);
218 touch_resize_window_->SetHitTestBoundsOverrideOuter(mouse_outer_insets, 187 touch_resize_window_->SetHitTestBoundsOverrideOuter(mouse_outer_insets,
219 touch_outer_insets); 188 touch_outer_insets);
220 } 189 }
221 190
222 // Simulate running the animation.
223 void RunAnimationTillComplete(gfx::SlideAnimation* animation) {
224 gfx::SlideAnimation::TestApi test_api(animation);
225 test_api.RunTillComplete();
226 }
227
228 TestWindowDelegate delegate_; 191 TestWindowDelegate delegate_;
229 TestWindowDelegate delegate2_; 192 TestWindowDelegate delegate2_;
230 TestWindowDelegate delegate3_; 193 TestWindowDelegate delegate3_;
231 TestWindowDelegate delegate4_; 194 TestWindowDelegate delegate4_;
232 scoped_ptr<aura::Window> window_; 195 scoped_ptr<aura::Window> window_;
233 scoped_ptr<aura::Window> window2_; 196 scoped_ptr<aura::Window> window2_;
234 scoped_ptr<aura::Window> window3_; 197 scoped_ptr<aura::Window> window3_;
235 scoped_ptr<aura::Window> window4_; 198 scoped_ptr<aura::Window> window4_;
236 199
237 TestWindowDelegate touch_resize_delegate_; 200 TestWindowDelegate touch_resize_delegate_;
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 touch_resize_window_->bounds().ToString()); 1861 touch_resize_window_->bounds().ToString());
1899 // Drag even more to snap to the edge. 1862 // Drag even more to snap to the edge.
1900 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), 1863 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1901 gfx::Point(400, kRootHeight - 25), 1864 gfx::Point(400, kRootHeight - 25),
1902 base::TimeDelta::FromMilliseconds(10), 1865 base::TimeDelta::FromMilliseconds(10),
1903 5); 1866 5);
1904 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), 1867 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1905 touch_resize_window_->bounds().ToString()); 1868 touch_resize_window_->bounds().ToString());
1906 } 1869 }
1907 1870
1908 TEST_F(WorkspaceWindowResizerTest, PhantomWindowShow) {
1909 if (!SupportsMultipleDisplays())
1910 return;
1911
1912 UpdateDisplay("500x400,500x400");
1913 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
1914 Shell::GetScreen()->GetPrimaryDisplay());
1915 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1916 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
1917
1918 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1919 window_.get(), gfx::Point(), HTCAPTION));
1920 ASSERT_TRUE(resizer.get());
1921 EXPECT_FALSE(snap_phantom_window_controller());
1922
1923 // The pointer is on the edge but not shared. The snap phantom window
1924 // controller should be non-NULL.
1925 resizer->Drag(CalculateDragPoint(*resizer, -1, 0), 0);
1926 EXPECT_TRUE(snap_phantom_window_controller());
1927 PhantomWindowController* phantom_controller(snap_phantom_window_controller());
1928
1929 // phantom widget only in the left screen.
1930 phantom_controller->Show(gfx::Rect(100, 100, 50, 60));
1931 EXPECT_TRUE(phantom_controller->phantom_widget_);
1932 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1933 EXPECT_EQ(
1934 root_windows[0],
1935 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1936
1937 // Move phantom widget into the right screen. Test that 2 widgets got created.
1938 phantom_controller->Show(gfx::Rect(600, 100, 50, 60));
1939 EXPECT_TRUE(phantom_controller->phantom_widget_);
1940 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1941 EXPECT_EQ(
1942 root_windows[1],
1943 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1944 EXPECT_EQ(
1945 root_windows[0],
1946 phantom_controller->phantom_widget_start_->GetNativeWindow()->
1947 GetRootWindow());
1948 RunAnimationTillComplete(phantom_controller->animation_.get());
1949
1950 // Move phantom widget only in the right screen. Start widget should close.
1951 phantom_controller->Show(gfx::Rect(700, 100, 50, 60));
1952 EXPECT_TRUE(phantom_controller->phantom_widget_);
1953 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1954 EXPECT_EQ(
1955 root_windows[1],
1956 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1957 RunAnimationTillComplete(phantom_controller->animation_.get());
1958
1959 // Move phantom widget into the left screen. Start widget should open.
1960 phantom_controller->Show(gfx::Rect(100, 100, 50, 60));
1961 EXPECT_TRUE(phantom_controller->phantom_widget_);
1962 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1963 EXPECT_EQ(
1964 root_windows[0],
1965 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1966 EXPECT_EQ(
1967 root_windows[1],
1968 phantom_controller->phantom_widget_start_->GetNativeWindow()->
1969 GetRootWindow());
1970 RunAnimationTillComplete(phantom_controller->animation_.get());
1971
1972 // Move phantom widget while in the left screen. Start widget should close.
1973 phantom_controller->Show(gfx::Rect(200, 100, 50, 60));
1974 EXPECT_TRUE(phantom_controller->phantom_widget_);
1975 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1976 EXPECT_EQ(
1977 root_windows[0],
1978 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1979 RunAnimationTillComplete(phantom_controller->animation_.get());
1980
1981 // Move phantom widget spanning both screens with most of the window in the
1982 // right screen. Two widgets are created.
1983 phantom_controller->Show(gfx::Rect(495, 100, 50, 60));
1984 EXPECT_TRUE(phantom_controller->phantom_widget_);
1985 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1986 EXPECT_EQ(
1987 root_windows[1],
1988 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1989 EXPECT_EQ(
1990 root_windows[0],
1991 phantom_controller->phantom_widget_start_->GetNativeWindow()->
1992 GetRootWindow());
1993 RunAnimationTillComplete(phantom_controller->animation_.get());
1994
1995 // Move phantom widget back into the left screen. Phantom widgets should swap.
1996 phantom_controller->Show(gfx::Rect(200, 100, 50, 60));
1997 EXPECT_TRUE(phantom_controller->phantom_widget_);
1998 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1999 EXPECT_EQ(
2000 root_windows[0],
2001 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
2002 EXPECT_EQ(
2003 root_windows[1],
2004 phantom_controller->phantom_widget_start_->GetNativeWindow()->
2005 GetRootWindow());
2006 RunAnimationTillComplete(phantom_controller->animation_.get());
2007
2008 // Hide phantom controller. Both widgets should close.
2009 phantom_controller->Hide();
2010 EXPECT_FALSE(phantom_controller->phantom_widget_);
2011 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
2012 }
2013
2014 } // namespace internal 1871 } // namespace internal
2015 } // namespace ash 1872 } // 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