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

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

Issue 2656983005: Fix the TabScrubber always starting from the first tab in full screen mode. (Closed)
Patch Set: Leave only the test Created 3 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/immersive_mode_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/ash/tab_scrubber.h" 5 #include "chrome/browser/ui/views/ash/tab_scrubber.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/display/event_transformation_handler.h" 9 #include "ash/display/event_transformation_handler.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "base/callback_helpers.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
18 #include "chrome/browser/ui/views/frame/browser_view.h" 20 #include "chrome/browser/ui/views/frame/browser_view.h"
19 #include "chrome/browser/ui/views/tabs/tab.h" 21 #include "chrome/browser/ui/views/tabs/tab.h"
20 #include "chrome/browser/ui/views/tabs/tab_strip.h" 22 #include "chrome/browser/ui/views/tabs/tab_strip.h"
21 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
23 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
24 #include "content/public/common/url_constants.h" 26 #include "content/public/common/url_constants.h"
25 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
26 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
27 #include "ui/events/event_utils.h" 29 #include "ui/events/event_utils.h"
28 #include "ui/events/test/event_generator.h" 30 #include "ui/events/test/event_generator.h"
29 31
30 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
31 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
32 #endif 34 #endif
33 35
34 namespace { 36 namespace {
35 37
38 // Waits until the immersive mode reveal ends, and therefore the top view of
39 // the browser is no longer visible.
40 class ImmersiveRevealEndedWaiter : public ImmersiveModeController::Observer {
41 public:
42 explicit ImmersiveRevealEndedWaiter(
43 ImmersiveModeController* immersive_controller)
44 : immersive_controller_(immersive_controller) {
45 immersive_controller_->AddObserver(this);
46 }
47
48 ~ImmersiveRevealEndedWaiter() override {
49 if (immersive_controller_)
50 immersive_controller_->RemoveObserver(this);
51 }
52
53 void Wait() {
54 if (!immersive_controller_ || !immersive_controller_->IsRevealed())
55 return;
56
57 base::RunLoop run_loop;
58 quit_closure_ = run_loop.QuitClosure();
59 run_loop.Run();
60 }
61
62 private:
63 void MaybeQuitRunLoop() {
64 if (!quit_closure_.is_null())
65 base::ResetAndReturn(&quit_closure_).Run();
66 }
67
68 // ImmersiveModeController::Observer:
69 void OnImmersiveRevealEnded() override { MaybeQuitRunLoop(); }
70
71 void OnImmersiveModeControllerDestroyed() override {
72 MaybeQuitRunLoop();
73 immersive_controller_ = nullptr;
sky 2017/02/02 22:29:45 RemoveObserver?
afakhry 2017/02/06 18:34:33 Done, but do we really need it? At this point we a
sky 2017/02/06 22:14:03 It's nice to have ObserverLists check if there are
74 }
75
76 ImmersiveModeController* immersive_controller_;
77 base::Closure quit_closure_;
78
79 DISALLOW_COPY_AND_ASSIGN(ImmersiveRevealEndedWaiter);
80 };
81
36 class TabScrubberTest : public InProcessBrowserTest, 82 class TabScrubberTest : public InProcessBrowserTest,
37 public TabStripModelObserver { 83 public TabStripModelObserver {
38 public: 84 public:
39 TabScrubberTest() 85 TabScrubberTest()
40 : target_index_(-1) { 86 : target_index_(-1) {
41 } 87 }
42 88
43 void SetUpCommandLine(base::CommandLine* command_line) override { 89 void SetUpCommandLine(base::CommandLine* command_line) override {
44 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
45 command_line->AppendSwitch(chromeos::switches::kNaturalScrollDefault); 91 command_line->AppendSwitch(chromeos::switches::kNaturalScrollDefault);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 Browser* browser2 = CreateBrowser(browser()->profile()); 320 Browser* browser2 = CreateBrowser(browser()->profile());
275 browser2->window()->Activate(); 321 browser2->window()->Activate();
276 ASSERT_TRUE(browser2->window()->IsActive()); 322 ASSERT_TRUE(browser2->window()->IsActive());
277 ASSERT_FALSE(browser()->window()->IsActive()); 323 ASSERT_FALSE(browser()->window()->IsActive());
278 AddTabs(browser2, 1); 324 AddTabs(browser2, 1);
279 325
280 Scrub(browser2, 0, EACH_TAB); 326 Scrub(browser2, 0, EACH_TAB);
281 EXPECT_EQ(0, browser2->tab_strip_model()->active_index()); 327 EXPECT_EQ(0, browser2->tab_strip_model()->active_index());
282 } 328 }
283 329
330 // Tests that tab scrubbing works correctly for a full-screen browser.
331 IN_PROC_BROWSER_TEST_F(TabScrubberTest, FullScreenBrowser) {
332 AddTabs(browser(), 6);
333 base::RunLoop().RunUntilIdle();
sky 2017/02/02 22:29:45 Why do you need the RunUntilIdle here?
afakhry 2017/02/06 18:34:33 Removed. I don't need it. This was a leftover from
334 browser()->tab_strip_model()->ActivateTabAt(4, false);
335
336 chrome::ToggleFullscreenMode(browser());
337 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(
338 browser()->window()->GetNativeWindow());
339 ImmersiveModeController* immersive_controller =
340 browser_view->immersive_mode_controller();
341 EXPECT_TRUE(immersive_controller->IsEnabled());
342
343 ImmersiveRevealEndedWaiter waiter(immersive_controller);
344 waiter.Wait();
345
346 EXPECT_FALSE(immersive_controller->IsRevealed());
347
348 EXPECT_EQ(4, browser()->tab_strip_model()->active_index());
349 Scrub(browser(), 0, EACH_TAB);
350 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
351 EXPECT_EQ(4U, activation_order_.size());
352 EXPECT_EQ(3, activation_order_[0]);
353 EXPECT_EQ(2, activation_order_[1]);
354 EXPECT_EQ(1, activation_order_[2]);
355 EXPECT_EQ(0, activation_order_[3]);
356 }
357
284 // Swipe 4 tabs in each direction with an extra swipe within each. The same 358 // Swipe 4 tabs in each direction with an extra swipe within each. The same
285 // 4 tabs should become active. 359 // 4 tabs should become active.
286 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Repeated) { 360 IN_PROC_BROWSER_TEST_F(TabScrubberTest, Repeated) {
287 AddTabs(browser(), 4); 361 AddTabs(browser(), 4);
288 362
289 Scrub(browser(), 0, REPEAT_TABS); 363 Scrub(browser(), 0, REPEAT_TABS);
290 ASSERT_EQ(4U, activation_order_.size()); 364 ASSERT_EQ(4U, activation_order_.size());
291 EXPECT_EQ(3, activation_order_[0]); 365 EXPECT_EQ(3, activation_order_[0]);
292 EXPECT_EQ(2, activation_order_[1]); 366 EXPECT_EQ(2, activation_order_[1]);
293 EXPECT_EQ(1, activation_order_[2]); 367 EXPECT_EQ(1, activation_order_[2]);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 542
469 SendScrubEvent(browser(), 1); 543 SendScrubEvent(browser(), 1);
470 EXPECT_TRUE(TabScrubber::GetInstance()->IsActivationPending()); 544 EXPECT_TRUE(TabScrubber::GetInstance()->IsActivationPending());
471 browser()->tab_strip_model()->ToggleSelectionAt(0); 545 browser()->tab_strip_model()->ToggleSelectionAt(0);
472 browser()->tab_strip_model()->ToggleSelectionAt(2); 546 browser()->tab_strip_model()->ToggleSelectionAt(2);
473 browser()->tab_strip_model()->MoveSelectedTabsTo(2); 547 browser()->tab_strip_model()->MoveSelectedTabsTo(2);
474 EXPECT_EQ(0, TabScrubber::GetInstance()->highlighted_tab()); 548 EXPECT_EQ(0, TabScrubber::GetInstance()->highlighted_tab());
475 } 549 }
476 550
477 #endif // defined(OS_CHROMEOS) 551 #endif // defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/immersive_mode_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698