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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_view_interactive_uitest.cc

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

Powered by Google App Engine
This is Rietveld 408576698