Implement blink::Platform::yieldCurrentThread()
[chromium-blink-merge.git] / athena / util / drag_handle_unittest.cc
blobc86e2a032e11fe9a1a5ebe3c0211bb94c1e09305
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"
12 namespace athena {
14 class DragHandleDelegateTest : public DragHandleScrollDelegate {
15 public:
16 explicit DragHandleDelegateTest()
17 : begin_delta_(0),
18 got_scroll_end_(false),
19 update_delta_(0) {}
21 virtual ~DragHandleDelegateTest() {}
23 void Reset() {
24 begin_delta_ = 0;
25 got_scroll_end_ = false;
26 update_delta_ = 0;
29 float begin_delta() { return begin_delta_; }
30 bool got_scroll_end() { return got_scroll_end_; }
31 float update_delta() { return update_delta_; }
33 private:
34 // DragHandleScrollDelegate:
35 virtual void HandleScrollBegin(float delta) OVERRIDE {
36 begin_delta_ = delta;
39 virtual void HandleScrollEnd() OVERRIDE {
40 got_scroll_end_ = true;
43 virtual void HandleScrollUpdate(float delta) OVERRIDE {
44 update_delta_ = delta;
47 float begin_delta_;
48 bool got_scroll_end_;
49 float update_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,
60 float x,
61 float delta_x) {
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));
69 return event;
72 TEST_F(DragHandleTest, ScrollTest) {
73 DragHandleDelegateTest delegate;
74 scoped_ptr<views::View> drag_handle(
75 CreateDragHandleView(DragHandleScrollDirection::DRAG_HANDLE_HORIZONTAL,
76 &delegate,
77 kDragHandleWidth,
78 kDragHandleHeight));
80 views::Widget widget;
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;
86 widget.Init(params);
87 widget.SetContentsView(drag_handle.get());
88 const gfx::Size& size = gfx::Size(kDragHandleWidth, kDragHandleHeight);
89 widget.SetSize(size);
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);
107 // Normal scroll
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());
122 delegate.Reset();
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());
133 delegate.Reset();
135 drag_handle.reset();
138 } // namespace athena