1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "athena/util/drag_handle.h"
7 #include "ui/aura/test/aura_test_base.h"
8 #include "ui/aura/window.h"
9 #include "ui/views/view.h"
10 #include "ui/views/widget/widget.h"
14 class DragHandleDelegateTest
: public DragHandleScrollDelegate
{
16 explicit DragHandleDelegateTest()
18 got_scroll_end_(false),
21 virtual ~DragHandleDelegateTest() {}
25 got_scroll_end_
= false;
29 float begin_delta() { return begin_delta_
; }
30 bool got_scroll_end() { return got_scroll_end_
; }
31 float update_delta() { return update_delta_
; }
34 // DragHandleScrollDelegate:
35 virtual void HandleScrollBegin(float delta
) OVERRIDE
{
39 virtual void HandleScrollEnd() OVERRIDE
{
40 got_scroll_end_
= true;
43 virtual void HandleScrollUpdate(float delta
) OVERRIDE
{
44 update_delta_
= delta
;
51 DISALLOW_COPY_AND_ASSIGN(DragHandleDelegateTest
);
54 typedef aura::test::AuraTestBase DragHandleTest
;
56 const int kDragHandleWidth
= 10;
57 const int kDragHandleHeight
= 100;
59 ui::GestureEvent
CreateGestureEvent(ui::EventType type
,
62 ui::GestureEvent
event(
66 base::TimeDelta::FromInternalValue(base::Time::Now().ToInternalValue()),
67 ui::GestureEventDetails(type
, delta_x
, 0));
68 event
.set_root_location(gfx::PointF(x
, 1));
72 TEST_F(DragHandleTest
, ScrollTest
) {
73 DragHandleDelegateTest delegate
;
74 scoped_ptr
<views::View
> drag_handle(
75 CreateDragHandleView(DragHandleScrollDirection::DRAG_HANDLE_HORIZONTAL
,
81 views::Widget::InitParams
params(
82 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS
);
83 params
.parent
= root_window();
84 params
.accept_events
= true;
85 params
.ownership
= views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET
;
87 widget
.SetContentsView(drag_handle
.get());
88 const gfx::Size
& size
= gfx::Size(kDragHandleWidth
, kDragHandleHeight
);
90 widget
.SetBounds(gfx::Rect(0, 0, size
.width(), size
.height()));
92 const float begin_x
= 4.0;
93 const float begin_delta
= 10.0;
94 const float update_delta
= 15.0;
96 ui::GestureEvent scroll_begin_model
=
97 CreateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN
, begin_x
, begin_delta
);
98 ui::GestureEvent scroll_update_model
=
99 CreateGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE
,
100 begin_x
+ update_delta
,
101 update_delta
- begin_delta
);
102 ui::GestureEvent scroll_end_model
=
103 CreateGestureEvent(ui::ET_GESTURE_SCROLL_END
, begin_x
+ update_delta
, 0);
104 ui::GestureEvent fling_start_model
=
105 CreateGestureEvent(ui::ET_SCROLL_FLING_START
, begin_x
+ update_delta
, 0);
108 ui::GestureEvent
e(scroll_begin_model
);
109 widget
.OnGestureEvent(&e
);
110 EXPECT_EQ(begin_delta
, delegate
.begin_delta());
111 EXPECT_EQ(0, delegate
.update_delta());
112 EXPECT_FALSE(delegate
.got_scroll_end());
113 e
= ui::GestureEvent(scroll_update_model
);
114 widget
.OnGestureEvent(&e
);
115 EXPECT_EQ(update_delta
, delegate
.update_delta());
116 EXPECT_FALSE(delegate
.got_scroll_end());
117 e
= ui::GestureEvent(scroll_end_model
);
118 widget
.OnGestureEvent(&e
);
119 EXPECT_EQ(update_delta
, delegate
.update_delta());
120 EXPECT_TRUE(delegate
.got_scroll_end());
124 // Scroll ending with a fling
125 e
= ui::GestureEvent(scroll_begin_model
);
126 widget
.OnGestureEvent(&e
);
127 e
= ui::GestureEvent(scroll_update_model
);
128 widget
.OnGestureEvent(&e
);
129 e
= ui::GestureEvent(fling_start_model
);
130 widget
.OnGestureEvent(&e
);
131 EXPECT_TRUE(delegate
.got_scroll_end());
138 } // namespace athena