| 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 "ash/display/event_transformation_handler.h" | 7 #include "ash/display/event_transformation_handler.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 13 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/tabs/tab.h" | 17 #include "chrome/browser/ui/views/tabs/tab.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
| 24 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 25 #include "ui/aura/test/event_generator.h" |
| 25 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 26 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
| 27 #include "ui/events/test/event_generator.h" | |
| 28 | 28 |
| 29 #if defined(OS_CHROMEOS) | 29 #if defined(OS_CHROMEOS) |
| 30 #include "chromeos/chromeos_switches.h" | 30 #include "chromeos/chromeos_switches.h" |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 class TabScrubberTest : public InProcessBrowserTest, | 35 class TabScrubberTest : public InProcessBrowserTest, |
| 36 public TabStripModelObserver { | 36 public TabStripModelObserver { |
| 37 public: | 37 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 int GetTabCenter(Browser* browser, int index) { | 74 int GetTabCenter(Browser* browser, int index) { |
| 75 return GetTabStrip(browser)->tab_at(index)->bounds().CenterPoint().x(); | 75 return GetTabStrip(browser)->tab_at(index)->bounds().CenterPoint().x(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Sends one scroll event synchronously without initial or final | 78 // Sends one scroll event synchronously without initial or final |
| 79 // fling events. | 79 // fling events. |
| 80 void SendScrubEvent(Browser* browser, int index) { | 80 void SendScrubEvent(Browser* browser, int index) { |
| 81 aura::Window* window = browser->window()->GetNativeWindow(); | 81 aura::Window* window = browser->window()->GetNativeWindow(); |
| 82 aura::Window* root = window->GetRootWindow(); | 82 aura::Window* root = window->GetRootWindow(); |
| 83 ui::test::EventGenerator event_generator(root, window); | 83 aura::test::EventGenerator event_generator(root, window); |
| 84 int active_index = browser->tab_strip_model()->active_index(); | 84 int active_index = browser->tab_strip_model()->active_index(); |
| 85 TabScrubber::Direction direction = index < active_index ? | 85 TabScrubber::Direction direction = index < active_index ? |
| 86 TabScrubber::LEFT : TabScrubber::RIGHT; | 86 TabScrubber::LEFT : TabScrubber::RIGHT; |
| 87 int offset = GetTabCenter(browser, index) - | 87 int offset = GetTabCenter(browser, index) - |
| 88 GetStartX(browser, active_index, direction); | 88 GetStartX(browser, active_index, direction); |
| 89 ui::ScrollEvent scroll_event(ui::ET_SCROLL, | 89 ui::ScrollEvent scroll_event(ui::ET_SCROLL, |
| 90 gfx::Point(0, 0), | 90 gfx::Point(0, 0), |
| 91 ui::EventTimeForNow(), | 91 ui::EventTimeForNow(), |
| 92 0, | 92 0, |
| 93 offset, 0, | 93 offset, 0, |
| 94 offset, 0, | 94 offset, 0, |
| 95 3); | 95 3); |
| 96 event_generator.Dispatch(&scroll_event); | 96 event_generator.Dispatch(&scroll_event); |
| 97 } | 97 } |
| 98 | 98 |
| 99 enum ScrubType { | 99 enum ScrubType { |
| 100 EACH_TAB, | 100 EACH_TAB, |
| 101 SKIP_TABS, | 101 SKIP_TABS, |
| 102 REPEAT_TABS, | 102 REPEAT_TABS, |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 // Sends asynchronous events and waits for tab at |index| to become | 105 // Sends asynchronous events and waits for tab at |index| to become |
| 106 // active. | 106 // active. |
| 107 void Scrub(Browser* browser, int index, ScrubType scrub_type) { | 107 void Scrub(Browser* browser, int index, ScrubType scrub_type) { |
| 108 aura::Window* window = browser->window()->GetNativeWindow(); | 108 aura::Window* window = browser->window()->GetNativeWindow(); |
| 109 aura::Window* root = window->GetRootWindow(); | 109 aura::Window* root = window->GetRootWindow(); |
| 110 ui::test::EventGenerator event_generator(root, window); | 110 aura::test::EventGenerator event_generator(root, window); |
| 111 event_generator.set_async(true); | 111 event_generator.set_async(true); |
| 112 activation_order_.clear(); | 112 activation_order_.clear(); |
| 113 int active_index = browser->tab_strip_model()->active_index(); | 113 int active_index = browser->tab_strip_model()->active_index(); |
| 114 ASSERT_NE(index, active_index); | 114 ASSERT_NE(index, active_index); |
| 115 ASSERT_TRUE(scrub_type != SKIP_TABS || ((index - active_index) % 2) == 0); | 115 ASSERT_TRUE(scrub_type != SKIP_TABS || ((index - active_index) % 2) == 0); |
| 116 TabScrubber::Direction direction; | 116 TabScrubber::Direction direction; |
| 117 int increment; | 117 int increment; |
| 118 if (index < active_index) { | 118 if (index < active_index) { |
| 119 direction = TabScrubber::LEFT; | 119 direction = TabScrubber::LEFT; |
| 120 increment = -1; | 120 increment = -1; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 RunUntilTabActive(browser, index); | 143 RunUntilTabActive(browser, index); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Sends events and waits for tab at |index| to become active | 146 // Sends events and waits for tab at |index| to become active |
| 147 // if it's different from the currently active tab. | 147 // if it's different from the currently active tab. |
| 148 // If the active tab is expected to stay the same, send events | 148 // If the active tab is expected to stay the same, send events |
| 149 // synchronously (as we don't have anything to wait for). | 149 // synchronously (as we don't have anything to wait for). |
| 150 void SendScrubSequence(Browser* browser, int x_offset, int index) { | 150 void SendScrubSequence(Browser* browser, int x_offset, int index) { |
| 151 aura::Window* window = browser->window()->GetNativeWindow(); | 151 aura::Window* window = browser->window()->GetNativeWindow(); |
| 152 aura::Window* root = window->GetRootWindow(); | 152 aura::Window* root = window->GetRootWindow(); |
| 153 ui::test::EventGenerator event_generator(root, window); | 153 aura::test::EventGenerator event_generator(root, window); |
| 154 bool wait_for_active = false; | 154 bool wait_for_active = false; |
| 155 if (index != browser->tab_strip_model()->active_index()) { | 155 if (index != browser->tab_strip_model()->active_index()) { |
| 156 wait_for_active = true; | 156 wait_for_active = true; |
| 157 event_generator.set_async(true); | 157 event_generator.set_async(true); |
| 158 } | 158 } |
| 159 event_generator.ScrollSequence(gfx::Point(0, 0), | 159 event_generator.ScrollSequence(gfx::Point(0, 0), |
| 160 ui::EventTimeForNow(), | 160 ui::EventTimeForNow(), |
| 161 x_offset, | 161 x_offset, |
| 162 0, | 162 0, |
| 163 1, | 163 1, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 IN_PROC_BROWSER_TEST_F(TabScrubberTest, CloseBrowser) { | 414 IN_PROC_BROWSER_TEST_F(TabScrubberTest, CloseBrowser) { |
| 415 AddTabs(browser(), 1); | 415 AddTabs(browser(), 1); |
| 416 | 416 |
| 417 SendScrubEvent(browser(), 0); | 417 SendScrubEvent(browser(), 0); |
| 418 EXPECT_TRUE(TabScrubber::GetInstance()->IsActivationPending()); | 418 EXPECT_TRUE(TabScrubber::GetInstance()->IsActivationPending()); |
| 419 browser()->window()->Close(); | 419 browser()->window()->Close(); |
| 420 EXPECT_FALSE(TabScrubber::GetInstance()->IsActivationPending()); | 420 EXPECT_FALSE(TabScrubber::GetInstance()->IsActivationPending()); |
| 421 } | 421 } |
| 422 | 422 |
| 423 #endif // defined(OS_CHROMEOS) | 423 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |