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

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 7 years 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_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 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 touch_resize_window_->bounds().ToString()); 1873 touch_resize_window_->bounds().ToString());
1911 // Drag even more to snap to the edge. 1874 // Drag even more to snap to the edge.
1912 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), 1875 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
1913 gfx::Point(400, kRootHeight - 25), 1876 gfx::Point(400, kRootHeight - 25),
1914 base::TimeDelta::FromMilliseconds(10), 1877 base::TimeDelta::FromMilliseconds(10),
1915 5); 1878 5);
1916 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), 1879 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
1917 touch_resize_window_->bounds().ToString()); 1880 touch_resize_window_->bounds().ToString());
1918 } 1881 }
1919 1882
1920 TEST_F(WorkspaceWindowResizerTest, PhantomWindowShow) {
1921 if (!SupportsMultipleDisplays())
1922 return;
1923
1924 UpdateDisplay("500x400,500x400");
1925 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
1926 Shell::GetScreen()->GetPrimaryDisplay());
1927 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1928 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
1929
1930 scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
1931 window_.get(), gfx::Point(), HTCAPTION));
1932 ASSERT_TRUE(resizer.get());
1933 EXPECT_FALSE(snap_phantom_window_controller());
1934
1935 // The pointer is on the edge but not shared. The snap phantom window
1936 // controller should be non-NULL.
1937 resizer->Drag(CalculateDragPoint(*resizer, -1, 0), 0);
1938 EXPECT_TRUE(snap_phantom_window_controller());
1939 PhantomWindowController* phantom_controller(snap_phantom_window_controller());
1940
1941 // phantom widget only in the left screen.
1942 phantom_controller->Show(gfx::Rect(100, 100, 50, 60));
1943 EXPECT_TRUE(phantom_controller->phantom_widget_);
1944 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1945 EXPECT_EQ(
1946 root_windows[0],
1947 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1948
1949 // Move phantom widget into the right screen. Test that 2 widgets got created.
1950 phantom_controller->Show(gfx::Rect(600, 100, 50, 60));
1951 EXPECT_TRUE(phantom_controller->phantom_widget_);
1952 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1953 EXPECT_EQ(
1954 root_windows[1],
1955 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1956 EXPECT_EQ(
1957 root_windows[0],
1958 phantom_controller->phantom_widget_start_->GetNativeWindow()->
1959 GetRootWindow());
1960 RunAnimationTillComplete(phantom_controller->animation_.get());
1961
1962 // Move phantom widget only in the right screen. Start widget should close.
1963 phantom_controller->Show(gfx::Rect(700, 100, 50, 60));
1964 EXPECT_TRUE(phantom_controller->phantom_widget_);
1965 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1966 EXPECT_EQ(
1967 root_windows[1],
1968 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1969 RunAnimationTillComplete(phantom_controller->animation_.get());
1970
1971 // Move phantom widget into the left screen. Start widget should open.
1972 phantom_controller->Show(gfx::Rect(100, 100, 50, 60));
1973 EXPECT_TRUE(phantom_controller->phantom_widget_);
1974 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1975 EXPECT_EQ(
1976 root_windows[0],
1977 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1978 EXPECT_EQ(
1979 root_windows[1],
1980 phantom_controller->phantom_widget_start_->GetNativeWindow()->
1981 GetRootWindow());
1982 RunAnimationTillComplete(phantom_controller->animation_.get());
1983
1984 // Move phantom widget while in the left screen. Start widget should close.
1985 phantom_controller->Show(gfx::Rect(200, 100, 50, 60));
1986 EXPECT_TRUE(phantom_controller->phantom_widget_);
1987 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1988 EXPECT_EQ(
1989 root_windows[0],
1990 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1991 RunAnimationTillComplete(phantom_controller->animation_.get());
1992
1993 // Move phantom widget spanning both screens with most of the window in the
1994 // right screen. Two widgets are created.
1995 phantom_controller->Show(gfx::Rect(495, 100, 50, 60));
1996 EXPECT_TRUE(phantom_controller->phantom_widget_);
1997 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
1998 EXPECT_EQ(
1999 root_windows[1],
2000 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
2001 EXPECT_EQ(
2002 root_windows[0],
2003 phantom_controller->phantom_widget_start_->GetNativeWindow()->
2004 GetRootWindow());
2005 RunAnimationTillComplete(phantom_controller->animation_.get());
2006
2007 // Move phantom widget back into the left screen. Phantom widgets should swap.
2008 phantom_controller->Show(gfx::Rect(200, 100, 50, 60));
2009 EXPECT_TRUE(phantom_controller->phantom_widget_);
2010 EXPECT_TRUE(phantom_controller->phantom_widget_start_);
2011 EXPECT_EQ(
2012 root_windows[0],
2013 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
2014 EXPECT_EQ(
2015 root_windows[1],
2016 phantom_controller->phantom_widget_start_->GetNativeWindow()->
2017 GetRootWindow());
2018 RunAnimationTillComplete(phantom_controller->animation_.get());
2019
2020 // Hide phantom controller. Both widgets should close.
2021 phantom_controller->Hide();
2022 EXPECT_FALSE(phantom_controller->phantom_widget_);
2023 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
2024 }
2025
2026 } // namespace internal 1883 } // namespace internal
2027 } // namespace ash 1884 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698