OLD | NEW |
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_->RemoveObserver(this); |
| 74 immersive_controller_ = nullptr; |
| 75 } |
| 76 |
| 77 ImmersiveModeController* immersive_controller_; |
| 78 base::Closure quit_closure_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(ImmersiveRevealEndedWaiter); |
| 81 }; |
| 82 |
36 class TabScrubberTest : public InProcessBrowserTest, | 83 class TabScrubberTest : public InProcessBrowserTest, |
37 public TabStripModelObserver { | 84 public TabStripModelObserver { |
38 public: | 85 public: |
39 TabScrubberTest() | 86 TabScrubberTest() |
40 : target_index_(-1) { | 87 : target_index_(-1) { |
41 } | 88 } |
42 | 89 |
43 void SetUpCommandLine(base::CommandLine* command_line) override { | 90 void SetUpCommandLine(base::CommandLine* command_line) override { |
44 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
45 command_line->AppendSwitch(chromeos::switches::kNaturalScrollDefault); | 92 command_line->AppendSwitch(chromeos::switches::kNaturalScrollDefault); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 Browser* browser2 = CreateBrowser(browser()->profile()); | 321 Browser* browser2 = CreateBrowser(browser()->profile()); |
275 browser2->window()->Activate(); | 322 browser2->window()->Activate(); |
276 ASSERT_TRUE(browser2->window()->IsActive()); | 323 ASSERT_TRUE(browser2->window()->IsActive()); |
277 ASSERT_FALSE(browser()->window()->IsActive()); | 324 ASSERT_FALSE(browser()->window()->IsActive()); |
278 AddTabs(browser2, 1); | 325 AddTabs(browser2, 1); |
279 | 326 |
280 Scrub(browser2, 0, EACH_TAB); | 327 Scrub(browser2, 0, EACH_TAB); |
281 EXPECT_EQ(0, browser2->tab_strip_model()->active_index()); | 328 EXPECT_EQ(0, browser2->tab_strip_model()->active_index()); |
282 } | 329 } |
283 | 330 |
| 331 // Tests that tab scrubbing works correctly for a full-screen browser. |
| 332 IN_PROC_BROWSER_TEST_F(TabScrubberTest, FullScreenBrowser) { |
| 333 AddTabs(browser(), 6); |
| 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 Loading... |
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) |
OLD | NEW |