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

Side by Side Diff: athena/util/drag_handle_unittest.cc

Issue 545393002: Adding split view divider widget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code format Created 6 years, 3 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
(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"
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 : can_scroll_(true),
19 begin_delta_(0),
20 got_scroll_end_(false),
21 update_delta_(0) {}
22
23 virtual ~DragHandleDelegateTest() {}
24
25 void Reset() {
26 can_scroll_ = true;
27 begin_delta_ = 0;
28 got_scroll_end_ = false;
29 update_delta_ = 0;
30 }
31
32 float begin_delta() { return begin_delta_; }
33 bool got_scroll_end() { return got_scroll_end_; }
34 float update_delta() { return update_delta_; }
35
36 void set_can_scroll(bool can_scroll) { can_scroll_ = can_scroll; }
37
38 private:
39 // DragHandleScrollDelegate:
40 virtual void HandleScrollBegin(float delta) OVERRIDE {
41 begin_delta_ = delta;
42 }
43
44 virtual void HandleScrollEnd() OVERRIDE {
45 got_scroll_end_ = true;
46 }
47
48 virtual void HandleScrollUpdate(float delta) OVERRIDE {
49 update_delta_ = delta;
50 }
51
52 virtual bool HandleCanScroll() OVERRIDE {
53 return can_scroll_;
54 }
55
56 bool can_scroll_;
57 float begin_delta_;
58 bool got_scroll_end_;
59 float update_delta_;
60
61 DISALLOW_COPY_AND_ASSIGN(DragHandleDelegateTest);
62 };
63
64 typedef aura::test::AuraTestBase DragHandleTest;
65
66 const int kDragHandleWidth = 10;
67 const int kDragHandleHeight = 100;
68
69 ui::GestureEvent CreateGestureEvent(ui::EventType type,
70 float x,
71 float delta_x) {
72 ui::GestureEvent event(
73 x,
74 1,
75 0,
76 base::TimeDelta::FromInternalValue(base::Time::Now().ToInternalValue()),
77 ui::GestureEventDetails(type, delta_x, 0));
78 event.set_root_location(gfx::PointF(x, 1));
79 return event;
80 }
81
82 TEST_F(DragHandleTest, ScrollTest) {
83 DragHandleDelegateTest delegate;
84 scoped_ptr<views::View> drag_handle(
85 CreateDragHandleView(DragHandleScrollDirection::DRAG_HANDLE_HORIZONTAL,
86 &delegate,
87 kDragHandleWidth,
88 kDragHandleHeight));
89
90 views::Widget widget;
91 views::Widget::InitParams params(
92 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
93 params.parent = root_window();
94 params.accept_events = true;
95 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
96 widget.Init(params);
97 widget.SetContentsView(drag_handle.get());
98 const gfx::Size& size = gfx::Size(kDragHandleWidth, kDragHandleHeight);
99 widget.SetSize(size);
100 widget.SetBounds(gfx::Rect(0, 0, size.width(), size.height()));
101
102 const float begin_x = 4.0;
103 const float begin_delta = 10.0;
104 const float update_delta = 15.0;
105
106 ui::GestureEvent scroll_begin_model =
107 CreateGestureEvent(ui::ET_GESTURE_SCROLL_BEGIN, begin_x, begin_delta);
108 ui::GestureEvent scroll_update_model =
109 CreateGestureEvent(ui::ET_GESTURE_SCROLL_UPDATE,
110 begin_x + update_delta,
111 update_delta - begin_delta);
112 ui::GestureEvent scroll_end_model =
113 CreateGestureEvent(ui::ET_GESTURE_SCROLL_END, begin_x + update_delta, 0);
114 ui::GestureEvent fling_start_model =
115 CreateGestureEvent(ui::ET_SCROLL_FLING_START, begin_x + update_delta, 0);
116
117 // Normal scroll
118 ui::GestureEvent e(scroll_begin_model);
119 widget.OnGestureEvent(&e);
120 EXPECT_EQ(begin_delta, delegate.begin_delta());
121 EXPECT_EQ(0, delegate.update_delta());
122 EXPECT_FALSE(delegate.got_scroll_end());
123 e = ui::GestureEvent(scroll_update_model);
124 widget.OnGestureEvent(&e);
125 EXPECT_EQ(update_delta, delegate.update_delta());
126 EXPECT_FALSE(delegate.got_scroll_end());
127 e = ui::GestureEvent(scroll_end_model);
128 widget.OnGestureEvent(&e);
129 EXPECT_EQ(update_delta, delegate.update_delta());
130 EXPECT_TRUE(delegate.got_scroll_end());
131
132 delegate.Reset();
133
134 // Scroll ending with a fling
135 e = ui::GestureEvent(scroll_begin_model);
136 widget.OnGestureEvent(&e);
137 e = ui::GestureEvent(scroll_update_model);
138 widget.OnGestureEvent(&e);
139 e = ui::GestureEvent(fling_start_model);
140 widget.OnGestureEvent(&e);
141 EXPECT_TRUE(delegate.got_scroll_end());
142
143 delegate.Reset();
144
145 // Changing CanScroll mid-scroll should't prevent events for the current
146 // scroll from coming through.
147 e = ui::GestureEvent(scroll_begin_model);
148 widget.OnGestureEvent(&e);
149 EXPECT_EQ(begin_delta, delegate.begin_delta());
150 delegate.set_can_scroll(false);
151 e = ui::GestureEvent(scroll_update_model);
152 widget.OnGestureEvent(&e);
153 EXPECT_EQ(update_delta, delegate.update_delta());
154 e = ui::GestureEvent(scroll_end_model);
155 widget.OnGestureEvent(&e);
156 EXPECT_TRUE(delegate.got_scroll_end());
157
158 delegate.Reset();
159
160 // When CanScroll is false, new scroll events should be ignored
161 delegate.set_can_scroll(false);
162 e = ui::GestureEvent(scroll_begin_model);
163 widget.OnGestureEvent(&e);
164 EXPECT_EQ(0, delegate.begin_delta());
165 e = ui::GestureEvent(scroll_update_model);
166 widget.OnGestureEvent(&e);
167 EXPECT_EQ(0, delegate.update_delta());
168 e = ui::GestureEvent(scroll_end_model);
169 widget.OnGestureEvent(&e);
170
171 drag_handle.reset();
172 }
173
174 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698