1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/top_controls_manager.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "cc/layer_impl.h"
#include "cc/layer_tree_impl.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/top_controls_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/vector2d_f.h"
namespace cc {
namespace {
static const float kTopControlsHeight = 100;
class MockTopControlsManagerClient : public TopControlsManagerClient {
public:
MockTopControlsManagerClient()
: host_impl_(&proxy_),
redraw_needed_(false),
update_draw_properties_needed_(false) {
active_tree_ = LayerTreeImpl::create(&host_impl_);
root_scroll_layer_ = LayerImpl::create(active_tree_.get(), 1);
}
virtual ~MockTopControlsManagerClient() {}
virtual void setNeedsRedraw() OVERRIDE {
redraw_needed_ = true;
}
virtual void setNeedsUpdateDrawProperties() OVERRIDE {
update_draw_properties_needed_ = true;
}
virtual bool haveRootScrollLayer() const OVERRIDE {
return true;
}
virtual float rootScrollLayerTotalScrollY() const OVERRIDE {
return root_scroll_layer_->scrollOffset().y() +
root_scroll_layer_->scrollDelta().y();
}
LayerImpl* rootScrollLayer() {
return root_scroll_layer_.get();
}
TopControlsManager* manager() {
if (!manager_)
manager_ = TopControlsManager::Create(this, kTopControlsHeight);
return manager_.get();
}
private:
FakeImplProxy proxy_;
FakeLayerTreeHostImpl host_impl_;
scoped_ptr<LayerTreeImpl> active_tree_;
scoped_ptr<LayerImpl> root_scroll_layer_;
scoped_ptr<TopControlsManager> manager_;
bool redraw_needed_;
bool update_draw_properties_needed_;
};
TEST(TopControlsManagerTest, overlayModeDetection) {
MockTopControlsManagerClient client;
TopControlsManager* manager = client.manager();
client.rootScrollLayer()->setScrollDelta(gfx::Vector2dF(0.f, 0.f));
gfx::Vector2dF remaining_scroll = manager->ScrollBy(
gfx::Vector2dF(0.f, 30.f));
EXPECT_EQ(0.f, remaining_scroll.y());
EXPECT_EQ(-30.f, manager->controls_top_offset());
EXPECT_EQ(70.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, 69.f));
EXPECT_EQ(0.f, remaining_scroll.y());
EXPECT_EQ(-99.f, manager->controls_top_offset());
EXPECT_EQ(1.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -20.f));
EXPECT_EQ(0.f, remaining_scroll.y());
EXPECT_EQ(-79.f, manager->controls_top_offset());
EXPECT_EQ(21.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
// Scroll to the toggle point
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, 21.f));
EXPECT_EQ(0.f, remaining_scroll.y());
EXPECT_EQ(-100.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, 1.f));
EXPECT_EQ(1.f, remaining_scroll.y());
EXPECT_EQ(-100.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -1.f));
EXPECT_EQ(-1.f, remaining_scroll.y());
EXPECT_EQ(-99.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -50.f));
EXPECT_EQ(-50.f, remaining_scroll.y());
EXPECT_EQ(-49.f, manager->controls_top_offset());
EXPECT_EQ(50.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
remaining_scroll = manager->ScrollBy(gfx::Vector2dF(0.f, -50.f));
EXPECT_EQ(0.f, manager->controls_top_offset());
EXPECT_EQ(100.f, manager->content_top_offset());
EXPECT_FALSE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollDelta(
client.rootScrollLayer()->scrollDelta() + remaining_scroll);
}
TEST(TopControlsManagerTest, partialShownHideAnimation) {
MockTopControlsManagerClient client;
TopControlsManager* manager = client.manager();
client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 300));
manager->ScrollBy(gfx::Vector2dF(0.f, 300.f));
EXPECT_EQ(-100.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 270));
manager->ScrollBy(gfx::Vector2dF(0.f, -15.f));
EXPECT_EQ(-85.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
manager->ScrollEnd();
EXPECT_TRUE(manager->animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous_offset = manager->controls_top_offset();
while(manager->animation()) {
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_LT(manager->controls_top_offset(), previous_offset);
previous_offset = manager->controls_top_offset();
}
EXPECT_FALSE(manager->animation());
EXPECT_EQ(-100.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
}
TEST(TopControlsManagerTest, partialShownShowAnimation) {
MockTopControlsManagerClient client;
TopControlsManager* manager = client.manager();
client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 300));
manager->ScrollBy(gfx::Vector2dF(0.f, 300.f));
EXPECT_EQ(-100.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
client.rootScrollLayer()->setScrollOffset(gfx::Vector2d(0, 230));
manager->ScrollBy(gfx::Vector2dF(0.f, -70.f));
EXPECT_EQ(-30.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
manager->ScrollEnd();
EXPECT_TRUE(manager->animation());
base::TimeTicks time = base::TimeTicks::Now();
float previous_offset = manager->controls_top_offset();
while(manager->animation()) {
time = base::TimeDelta::FromMicroseconds(100) + time;
manager->Animate(time);
EXPECT_GT(manager->controls_top_offset(), previous_offset);
previous_offset = manager->controls_top_offset();
}
EXPECT_FALSE(manager->animation());
EXPECT_EQ(0.f, manager->controls_top_offset());
EXPECT_EQ(0.f, manager->content_top_offset());
EXPECT_TRUE(manager->is_overlay_mode());
}
} // namespace
} // namespace cc
|