OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | |
6 | |
5 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/macros.h" | |
6 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
7 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/utf_string_conversions.h" | |
8 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/app/chrome_command_ids.h" | |
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | |
9 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
16 #include "chrome/browser/ui/browser.h" | |
17 #include "chrome/browser/ui/browser_command_controller.h" | |
18 #include "chrome/browser/ui/browser_window.h" | |
10 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
20 #include "chrome/browser/ui/view_ids.h" | |
11 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
12 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" | 22 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" |
13 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
14 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 24 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
15 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" | 25 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
sky
2016/10/13 16:21:21
This include should the first include, then newlin
Qiang(Joe) Xu
2016/10/14 01:42:39
Done.
| |
27 #include "chrome/test/base/in_process_browser_test.h" | |
17 #include "chrome/test/base/interactive_test_utils.h" | 28 #include "chrome/test/base/interactive_test_utils.h" |
29 #include "components/bookmarks/browser/bookmark_model.h" | |
30 #include "components/bookmarks/browser/bookmark_utils.h" | |
18 #include "extensions/common/feature_switch.h" | 31 #include "extensions/common/feature_switch.h" |
32 #include "ui/views/focus/focus_manager.h" | |
33 #include "ui/views/test/widget_test.h" | |
34 #include "ui/views/view.h" | |
35 #include "ui/views/widget/widget.h" | |
19 | 36 |
20 // Borrowed from chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc, | 37 // Borrowed from chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc, |
21 // since these are also disabled on Linux for drag and drop. | 38 // since these are also disabled on Linux for drag and drop. |
22 // TODO(erg): Fix DND tests on linux_aura. crbug.com/163931 | 39 // TODO(erg): Fix DND tests on linux_aura. crbug.com/163931 |
23 #if defined(OS_LINUX) && defined(USE_AURA) | 40 #if defined(OS_LINUX) && defined(USE_AURA) |
24 #define MAYBE(x) DISABLED_##x | 41 #define MAYBE(x) DISABLED_##x |
25 #else | 42 #else |
26 #define MAYBE(x) x | 43 #define MAYBE(x) x |
27 #endif | 44 #endif |
28 | 45 |
46 using bookmarks::BookmarkModel; | |
47 | |
29 class ToolbarViewInteractiveUITest : public ExtensionBrowserTest { | 48 class ToolbarViewInteractiveUITest : public ExtensionBrowserTest { |
30 public: | 49 public: |
31 ToolbarViewInteractiveUITest(); | 50 ToolbarViewInteractiveUITest(); |
32 ~ToolbarViewInteractiveUITest() override; | 51 ~ToolbarViewInteractiveUITest() override; |
33 | 52 |
34 protected: | 53 protected: |
35 ToolbarView* toolbar_view() { return toolbar_view_; } | 54 ToolbarView* toolbar_view() { return toolbar_view_; } |
36 BrowserActionsContainer* browser_actions() { return browser_actions_; } | 55 BrowserActionsContainer* browser_actions() { return browser_actions_; } |
37 | 56 |
38 // Performs a drag-and-drop operation by moving the mouse to |start|, clicking | 57 // Performs a drag-and-drop operation by moving the mouse to |start|, clicking |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 182 |
164 gfx::Point browser_action_view_loc = | 183 gfx::Point browser_action_view_loc = |
165 ui_test_utils::GetCenterInScreenCoordinates(view); | 184 ui_test_utils::GetCenterInScreenCoordinates(view); |
166 gfx::Point app_button_loc = ui_test_utils::GetCenterInScreenCoordinates( | 185 gfx::Point app_button_loc = ui_test_utils::GetCenterInScreenCoordinates( |
167 toolbar_view()->app_menu_button()); | 186 toolbar_view()->app_menu_button()); |
168 | 187 |
169 // Perform a drag and drop from the browser action view to the app button, | 188 // Perform a drag and drop from the browser action view to the app button, |
170 // which should open the app menu. | 189 // which should open the app menu. |
171 DoDragAndDrop(browser_action_view_loc, app_button_loc); | 190 DoDragAndDrop(browser_action_view_loc, app_button_loc); |
172 } | 191 } |
192 | |
193 class ToolbarViewTest : public InProcessBrowserTest { | |
194 public: | |
195 ToolbarViewTest() {} | |
196 | |
197 void RunToolbarCycleFocusTest(Browser* browser); | |
198 | |
199 private: | |
200 DISALLOW_COPY_AND_ASSIGN(ToolbarViewTest); | |
201 }; | |
202 | |
203 void ToolbarViewTest::RunToolbarCycleFocusTest(Browser* browser) { | |
204 gfx::NativeWindow window = browser->window()->GetNativeWindow(); | |
205 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
206 views::FocusManager* focus_manager = widget->GetFocusManager(); | |
207 CommandUpdater* updater = browser->command_controller()->command_updater(); | |
208 | |
209 // Send focus to the toolbar as if the user pressed Alt+Shift+T. | |
210 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); | |
211 | |
212 // Test relies on browser window activation, while platform such as Linux's | |
213 // window activation is asynchronous. | |
214 views::test::WidgetActivationWaiter waiter(widget, true); | |
215 waiter.Wait(); | |
216 | |
217 views::View* first_view = focus_manager->GetFocusedView(); | |
218 std::vector<int> ids; | |
219 | |
220 // Press Tab to cycle through all of the controls in the toolbar until | |
221 // we end up back where we started. | |
222 bool found_reload = false; | |
223 bool found_location_bar = false; | |
224 bool found_app_menu = false; | |
225 const views::View* view = NULL; | |
226 while (view != first_view) { | |
227 focus_manager->AdvanceFocus(false); | |
228 view = focus_manager->GetFocusedView(); | |
229 ids.push_back(view->id()); | |
230 if (view->id() == VIEW_ID_RELOAD_BUTTON) | |
231 found_reload = true; | |
232 if (view->id() == VIEW_ID_APP_MENU) | |
233 found_app_menu = true; | |
234 if (view->id() == VIEW_ID_OMNIBOX) | |
235 found_location_bar = true; | |
236 if (ids.size() > 100) | |
237 GTEST_FAIL() << "Tabbed 100 times, still haven't cycled back!"; | |
238 } | |
239 | |
240 // Make sure we found a few key items. | |
241 ASSERT_TRUE(found_reload); | |
242 ASSERT_TRUE(found_app_menu); | |
243 ASSERT_TRUE(found_location_bar); | |
244 | |
245 // Now press Shift-Tab to cycle backwards. | |
246 std::vector<int> reverse_ids; | |
247 view = NULL; | |
248 while (view != first_view) { | |
249 focus_manager->AdvanceFocus(true); | |
250 view = focus_manager->GetFocusedView(); | |
251 reverse_ids.push_back(view->id()); | |
252 if (reverse_ids.size() > 100) | |
253 GTEST_FAIL() << "Tabbed 100 times, still haven't cycled back!"; | |
254 } | |
255 | |
256 // Assert that the views were focused in exactly the reverse order. | |
257 // The sequences should be the same length, and the last element will | |
258 // be the same, and the others are reverse. | |
259 ASSERT_EQ(ids.size(), reverse_ids.size()); | |
260 size_t count = ids.size(); | |
261 for (size_t i = 0; i < count - 1; i++) | |
262 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); | |
263 } | |
264 | |
265 // The test is flaky on Win (http://crbug.com/152938) and crashes on CrOS under | |
266 // AddressSanitizer (http://crbug.com/154657). | |
267 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, DISABLED_ToolbarCycleFocus) { | |
268 RunToolbarCycleFocusTest(browser()); | |
269 } | |
270 | |
271 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocusWithBookmarkBar) { | |
272 CommandUpdater* updater = browser()->command_controller()->command_updater(); | |
273 updater->ExecuteCommand(IDC_SHOW_BOOKMARK_BAR); | |
274 | |
275 BookmarkModel* model = | |
276 BookmarkModelFactory::GetForBrowserContext(browser()->profile()); | |
277 bookmarks::AddIfNotBookmarked(model, GURL("http://foo.com"), | |
278 base::ASCIIToUTF16("Foo")); | |
279 | |
280 // We want to specifically test the case where the bookmark bar is | |
281 // already showing when a window opens, so create a second browser | |
282 // window with the same profile. | |
283 Browser* second_browser = CreateBrowser(browser()->profile()); | |
284 RunToolbarCycleFocusTest(second_browser); | |
285 } | |
OLD | NEW |