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

Side by Side Diff: chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc

Issue 12096014: Highlight tabs while scrubbing Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Explicitly enable scrubbing for test Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "base/command_line.h"
6 #include "base/message_loop.h"
7 #include "base/message_loop_proxy.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
10 #include "chrome/browser/ui/views/ash/tab_scrubber.h"
sky 2013/01/28 19:25:29 nit: this should be your first include (same order
DaveMoore 2013/01/29 01:11:41 Done.
11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/tabs/tab.h"
13 #include "chrome/browser/ui/views/tabs/tab_strip.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/test/test_utils.h"
19 #include "ui/aura/test/event_generator.h"
20 #include "ui/aura/window.h"
21
22 namespace {
23
24 class TabScrubberTest : public InProcessBrowserTest,
25 public TabStripModelObserver {
26 public:
27 TabScrubberTest()
28 : tab_strip_(NULL),
29 event_generator_(NULL),
30 target_index_(-1) {
31 }
32
33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
34 command_line->AppendSwitch(switches::kNaturalScrollDefault);
35 command_line->AppendSwitch(switches::kAshEnableTabScrubbing);
36 }
37
38 virtual void SetUpOnMainThread() OVERRIDE {
39 aura::Window* window = browser()->window()->GetNativeWindow();
40 BrowserView* browser_view =
41 BrowserView::GetBrowserViewForNativeWindow(window);
42 tab_strip_ = browser_view->tabstrip();
43 browser()->tab_strip_model()->AddObserver(this);
sky 2013/01/28 19:25:29 You never remove this.
DaveMoore 2013/01/29 01:11:41 Done.
44 aura::RootWindow* root = window->GetRootWindow();
45 event_generator_ = new aura::test::EventGenerator(root, window);
46 event_generator_->set_post_events(true);
47 TabScrubber::GetInstance()->set_activation_delay(
48 base::TimeDelta::FromMilliseconds(0));
49 }
50
51 int GetStartX(int index, TabScrubber::Direction direction) {
52 return TabScrubber::GetStartPoint(tab_strip_, index, direction).x();
53 }
54
55 enum ScrubType {
56 EACH_TAB,
57 SKIP_TABS,
58 REPEAT_TABS,
59 };
60
61 void Scrub(int index, ScrubType scrub_type) {
62 activation_order_.clear();
63 int active_index = browser()->tab_strip_model()->active_index();
64 DCHECK(index - active_index != 0);
sky 2013/01/28 19:25:29 Don't use DCHECKs in tests, use EXPECT/ASSERT
DaveMoore 2013/01/29 01:11:41 Done.
65 DCHECK(scrub_type != SKIP_TABS || ((index - active_index) % 2) == 0);
66 TabScrubber::Direction direction;
67 int increment;
68 if (index < active_index) {
69 direction = TabScrubber::LEFT;
70 increment = -1;
71 } else {
72 direction = TabScrubber::RIGHT;
73 increment = 1;
74 }
75 if (scrub_type == SKIP_TABS)
76 increment *= 2;
77 int last = GetStartX(active_index, direction);
78 std::vector<gfx::Point> offsets;
79 for (int i = active_index + increment; i != (index + increment);
80 i += increment) {
81 int tab_center = tab_strip_->tab_at(i)->bounds().CenterPoint().x();
82 offsets.push_back(gfx::Point(tab_center - last, 0));
83 last = GetStartX(i, direction);
84 if (scrub_type == REPEAT_TABS) {
85 offsets.push_back(gfx::Point(increment, 0));
86 last += increment;
87 }
88 }
89 event_generator_->ScrollSequence(gfx::Point(0, 0),
90 base::TimeDelta::FromMilliseconds(100),
91 offsets,
92 3);
93 }
94
95 void AddTabs(int num_tabs) {
96 for (int i = 0; i < num_tabs; ++i)
97 AddBlankTabAndShow(browser());
98 ASSERT_EQ(num_tabs + 1, browser()->tab_strip_model()->count());
99 ASSERT_EQ(num_tabs, browser()->tab_strip_model()->active_index());
100 }
101
102 void RunUntilTabActive(int target) {
103 base::RunLoop run_loop;
104 quit_closure_ = content::GetQuitTaskForRunLoop(&run_loop);
105 target_index_ = target;
106 content::RunThisRunLoop(&run_loop);
107 target_index_ = -1;
108 }
109
110 // TabStripModelObserver overrides.
111 virtual void TabInsertedAt(content::WebContents* contents,
112 int index,
113 bool foreground) {}
114 virtual void TabClosingAt(TabStripModel* tab_strip_model,
115 content::WebContents* contents,
116 int index) {}
117 virtual void TabDetachedAt(content::WebContents* contents, int index) {}
118 virtual void TabDeactivated(content::WebContents* contents) {}
119 virtual void ActiveTabChanged(content::WebContents* old_contents,
120 content::WebContents* new_contents,
121 int index,
122 bool user_gesture) {
123 activation_order_.push_back(index);
124 if (index == target_index_)
125 quit_closure_.Run();
126 }
127
128 virtual void TabSelectionChanged(TabStripModel* tab_strip_model,
129 const ui::ListSelectionModel& old_model) {}
130 virtual void TabMoved(content::WebContents* contents,
131 int from_index,
132 int to_index) {}
133 virtual void TabChangedAt(content::WebContents* contents,
134 int index,
135 TabChangeType change_type) {}
136 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
137 content::WebContents* old_contents,
138 content::WebContents* new_contents,
139 int index) {}
140 virtual void TabPinnedStateChanged(content::WebContents* contents,
141 int index) {}
142 virtual void TabMiniStateChanged(content::WebContents* contents, int index) {}
143 virtual void TabBlockedStateChanged(content::WebContents* contents,
144 int index) {}
145 virtual void TabStripEmpty() {}
146 virtual void TabStripModelDeleted() {}
147
148 TabStrip* tab_strip_;
149 std::vector<int> activation_order_;
sky 2013/01/28 19:25:29 Would be nice to have a description for some of th
DaveMoore 2013/01/29 01:11:41 Done.
150 aura::test::EventGenerator* event_generator_;
sky 2013/01/28 19:25:29 scoped_ptr?
DaveMoore 2013/01/29 01:11:41 Done.
151
152 private:
153 base::Closure quit_closure_;
154 int target_index_;
155 };
sky 2013/01/28 19:25:29 DISALLOW_...
DaveMoore 2013/01/29 01:11:41 Done.
156
157 } // namespace
158
159 // Swipe a single tab in each direction.
160 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Single) {
161 AddTabs(1);
162
163 Scrub(0, EACH_TAB);
164 RunUntilTabActive(0);
165 EXPECT_EQ(1U, activation_order_.size());
166 EXPECT_EQ(0, activation_order_[0]);
167 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
168
169 Scrub(1, EACH_TAB);
170 RunUntilTabActive(1);
171 EXPECT_EQ(1U, activation_order_.size());
172 EXPECT_EQ(1, activation_order_[0]);
173 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
174 }
175
176 // Swipe 4 tabs in each direction. Each of the tabs should become active.
177 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Multi) {
178 AddTabs(4);
179
180 Scrub(0, EACH_TAB);
181 RunUntilTabActive(0);
182 ASSERT_EQ(4U, activation_order_.size());
183 EXPECT_EQ(3, activation_order_[0]);
184 EXPECT_EQ(2, activation_order_[1]);
185 EXPECT_EQ(1, activation_order_[2]);
186 EXPECT_EQ(0, activation_order_[3]);
187 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
188
189 Scrub(4, EACH_TAB);
190 RunUntilTabActive(4);
191 ASSERT_EQ(4U, activation_order_.size());
192 EXPECT_EQ(1, activation_order_[0]);
193 EXPECT_EQ(2, activation_order_[1]);
194 EXPECT_EQ(3, activation_order_[2]);
195 EXPECT_EQ(4, activation_order_[3]);
196 EXPECT_EQ(4, browser()->tab_strip_model()->active_index());
197 }
198
199 // Swipe 4 tabs in each direction with an extra swipe within each. The same
200 // 4 tabs should become active.
201 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Repeated) {
202 AddTabs(4);
203
204 Scrub(0, REPEAT_TABS);
205 RunUntilTabActive(0);
206 ASSERT_EQ(4U, activation_order_.size());
207 EXPECT_EQ(3, activation_order_[0]);
208 EXPECT_EQ(2, activation_order_[1]);
209 EXPECT_EQ(1, activation_order_[2]);
210 EXPECT_EQ(0, activation_order_[3]);
211 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
212
213 Scrub(4, REPEAT_TABS);
214 RunUntilTabActive(4);
215 ASSERT_EQ(4U, activation_order_.size());
216 EXPECT_EQ(1, activation_order_[0]);
217 EXPECT_EQ(2, activation_order_[1]);
218 EXPECT_EQ(3, activation_order_[2]);
219 EXPECT_EQ(4, activation_order_[3]);
220 EXPECT_EQ(4, browser()->tab_strip_model()->active_index());
221 }
222
223 // Confirm that we get the last tab made active when we skip tabs.
224 // These tests have 5 total tabs. We will only received scroll events
225 // on tabs 0, 2 and 4.
226 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Skipped) {
227 AddTabs(4);
228
229 Scrub(0, SKIP_TABS);
230 RunUntilTabActive(0);
231 EXPECT_EQ(2U, activation_order_.size());
232 EXPECT_EQ(2, activation_order_[0]);
233 EXPECT_EQ(0, activation_order_[1]);
234 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
235
236 Scrub(4, SKIP_TABS);
237 RunUntilTabActive(4);
238 EXPECT_EQ(2U, activation_order_.size());
239 EXPECT_EQ(2, activation_order_[0]);
240 EXPECT_EQ(4, activation_order_[1]);
241 EXPECT_EQ(4, browser()->tab_strip_model()->active_index());
242 }
243
244 // Confirm that nothing happens when the swipe is small.
245 IN_PROC_BROWSER_TEST_F(TabScrubberTest, NoChange) {
246 AddTabs(1);
247
248 event_generator_->ScrollSequence(gfx::Point(0, 0),
249 base::TimeDelta::FromMilliseconds(100),
250 -1,
251 0,
252 1,
253 3);
254 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
255
256 event_generator_->ScrollSequence(gfx::Point(0, 0),
257 base::TimeDelta::FromMilliseconds(100),
258 1,
259 0,
260 1,
261 3);
262 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
263 }
264
265 // Confirm that very large swipes go to the beginning and and of the tabstrip.
266 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Bounds) {
267 AddTabs(1);
268
269 event_generator_->ScrollSequence(gfx::Point(0, 0),
270 base::TimeDelta::FromMilliseconds(100),
271 -10000,
272 0,
273 1,
274 3);
275 RunUntilTabActive(0);
276 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
277
278 event_generator_->ScrollSequence(gfx::Point(0, 0),
279 base::TimeDelta::FromMilliseconds(100),
280 10000,
281 0,
282 1,
283 3);
284 RunUntilTabActive(1);
285 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
286 }
287
288
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698