OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "athena/util/drag_handle.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
pkotwicz
2014/09/23 19:44:46
Nit: Remove this include
| |
8 #include "ui/aura/test/aura_test_base.h" | |
9 #include "ui/aura/window.h" | |
10 #include "ui/views/view.h" | |
11 #include "ui/views/widget/widget.h" | |
12 | |
13 namespace athena { | |
14 | |
15 class DragHandleDelegateTest : public DragHandleScrollDelegate { | |
16 public: | |
17 explicit DragHandleDelegateTest() | |
18 : begin_delta_(0), | |
19 got_scroll_end_(false), | |
20 update_delta_(0) {} | |
21 | |
22 virtual ~DragHandleDelegateTest() {} | |
23 | |
24 void Reset() { | |
25 begin_delta_ = 0; | |
26 got_scroll_end_ = false; | |
27 update_delta_ = 0; | |
28 } | |
29 | |
30 float begin_delta() { return begin_delta_; } | |
31 bool got_scroll_end() { return got_scroll_end_; } | |
32 float update_delta() { return update_delta_; } | |
33 | |
34 private: | |
35 // DragHandleScrollDelegate: | |
36 virtual void HandleScrollBegin(float delta) OVERRIDE { | |
37 begin_delta_ = delta; | |
38 } | |
39 | |
40 virtual void HandleScrollEnd() OVERRIDE { | |
41 got_scroll_end_ = true; | |
42 } | |
43 | |
44 virtual void HandleScrollUpdate(float delta) OVERRIDE { | |
45 update_delta_ = delta; | |
46 } | |
47 | |
48 float begin_delta_; | |
49 bool got_scroll_end_; | |
50 float update_delta_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(DragHandleDelegateTest); | |
53 }; | |
54 | |
55 typedef aura::test::AuraTestBase DragHandleTest; | |
56 | |
57 const int kDragHandleWidth = 10; | |
58 const int kDragHandleHeight = 100; | |
59 | |
60 ui::GestureEvent CreateGestureEvent(ui::EventType type, | |
61 float x, | |
62 float delta_x) { | |
63 ui::GestureEvent event( | |
64 x, | |
65 1, | |
66 0, | |
67 base::TimeDelta::FromInternalValue(base::Time::Now().ToInternalValue()), | |
68 ui::GestureEventDetails(type, delta_x, 0)); | |
69 event.set_root_location(gfx::PointF(x, 1)); | |
70 return event; | |
71 } | |
72 | |
73 TEST_F(DragHandleTest, ScrollTest) { | |
74 DragHandleDelegateTest delegate; | |
75 scoped_ptr<views::View> drag_handle( | |
76 CreateDragHandleView(DragHandleScrollDirection::DRAG_HANDLE_HORIZONTAL, | |
77 &delegate, | |
78 kDragHandleWidth, | |
79 kDragHandleHeight)); | |
80 | |
81 views::Widget widget; | |
82 views::Widget::InitParams params( | |
83 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
84 params.parent = root_window(); | |
85 params.accept_events = true; | |
86 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
87 widget.Init(params); | |
88 widget.SetContentsView(drag_handle.get()); | |
89 const gfx::Size& size = gfx::Size(kDragHandleWidth, kDragHandleHeight); | |
90 widget.SetSize(size); | |
91 widget.SetBounds(gfx::Rect(0, 0, size.width(), size.height())); | |
92 | |
93 const float begin_x = 4.0; | |
94 const float begin_delta = 10.0; | |
95 const float update_delta = 15.0; | |
96 | |
97 ui::GestureEvent scroll_begin_model = | |
98 CreateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, begin_x, begin_delta); | |
99 ui::GestureEvent scroll_update_model = | |
100 CreateGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE, | |
101 begin_x + update_delta, | |
102 update_delta - begin_delta); | |
103 ui::GestureEvent scroll_end_model = | |
104 CreateGestureEvent(ui::ET_GESTURE_SCROLL_END, begin_x + update_delta, 0); | |
105 ui::GestureEvent fling_start_model = | |
106 CreateGestureEvent(ui::ET_SCROLL_FLING_START, begin_x + update_delta, 0); | |
107 | |
108 // Normal scroll | |
109 ui::GestureEvent e(scroll_begin_model); | |
110 widget.OnGestureEvent(&e); | |
111 EXPECT_EQ(begin_delta, delegate.begin_delta()); | |
112 EXPECT_EQ(0, delegate.update_delta()); | |
113 EXPECT_FALSE(delegate.got_scroll_end()); | |
114 e = ui::GestureEvent(scroll_update_model); | |
115 widget.OnGestureEvent(&e); | |
116 EXPECT_EQ(update_delta, delegate.update_delta()); | |
117 EXPECT_FALSE(delegate.got_scroll_end()); | |
118 e = ui::GestureEvent(scroll_end_model); | |
119 widget.OnGestureEvent(&e); | |
120 EXPECT_EQ(update_delta, delegate.update_delta()); | |
121 EXPECT_TRUE(delegate.got_scroll_end()); | |
122 | |
123 delegate.Reset(); | |
124 | |
125 // Scroll ending with a fling | |
126 e = ui::GestureEvent(scroll_begin_model); | |
127 widget.OnGestureEvent(&e); | |
128 e = ui::GestureEvent(scroll_update_model); | |
129 widget.OnGestureEvent(&e); | |
130 e = ui::GestureEvent(fling_start_model); | |
131 widget.OnGestureEvent(&e); | |
132 EXPECT_TRUE(delegate.got_scroll_end()); | |
133 | |
134 delegate.Reset(); | |
135 | |
136 drag_handle.reset(); | |
137 } | |
138 | |
139 } // namespace athena | |
OLD | NEW |