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/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
6 | 6 |
| 7 #include "base/utf_string_conversions.h" |
7 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
8 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
10 #include "chrome/browser/ui/browser_command_controller.h" | 14 #include "chrome/browser/ui/browser_command_controller.h" |
11 #include "chrome/browser/ui/view_ids.h" | 15 #include "chrome/browser/ui/view_ids.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "ui/views/focus/focus_manager.h" | 18 #include "ui/views/focus/focus_manager.h" |
15 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
16 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 class ToolbarViewTest : public InProcessBrowserTest { | 24 class ToolbarViewTest : public InProcessBrowserTest { |
21 public: | 25 public: |
22 ToolbarViewTest() {} | 26 ToolbarViewTest() {} |
23 | 27 |
| 28 void RunToolbarCycleFocusTest(Browser* browser); |
| 29 |
24 private: | 30 private: |
25 DISALLOW_COPY_AND_ASSIGN(ToolbarViewTest); | 31 DISALLOW_COPY_AND_ASSIGN(ToolbarViewTest); |
26 }; | 32 }; |
27 | 33 |
28 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocus) { | 34 void ToolbarViewTest::RunToolbarCycleFocusTest(Browser* browser) { |
29 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | 35 gfx::NativeWindow window = browser->window()->GetNativeWindow(); |
30 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 36 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
31 views::FocusManager* focus_manager = widget->GetFocusManager(); | 37 views::FocusManager* focus_manager = widget->GetFocusManager(); |
32 CommandUpdater* updater = browser()->command_controller()->command_updater(); | 38 CommandUpdater* updater = browser->command_controller()->command_updater(); |
33 | 39 |
34 // Send focus to the toolbar as if the user pressed Alt+Shift+T. | 40 // Send focus to the toolbar as if the user pressed Alt+Shift+T. |
35 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); | 41 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); |
36 | 42 |
37 views::View* first_view = focus_manager->GetFocusedView(); | 43 views::View* first_view = focus_manager->GetFocusedView(); |
38 std::vector<int> ids; | 44 std::vector<int> ids; |
39 | 45 |
40 // Press Tab to cycle through all of the controls in the toolbar until | 46 // Press Tab to cycle through all of the controls in the toolbar until |
41 // we end up back where we started. | 47 // we end up back where we started. |
42 bool found_reload = false; | 48 bool found_reload = false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 81 |
76 // Assert that the views were focused in exactly the reverse order. | 82 // Assert that the views were focused in exactly the reverse order. |
77 // The sequences should be the same length, and the last element will | 83 // The sequences should be the same length, and the last element will |
78 // be the same, and the others are reverse. | 84 // be the same, and the others are reverse. |
79 ASSERT_EQ(ids.size(), reverse_ids.size()); | 85 ASSERT_EQ(ids.size(), reverse_ids.size()); |
80 size_t count = ids.size(); | 86 size_t count = ids.size(); |
81 for (size_t i = 0; i < count - 1; i++) | 87 for (size_t i = 0; i < count - 1; i++) |
82 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); | 88 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); |
83 } | 89 } |
84 | 90 |
| 91 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocus) { |
| 92 RunToolbarCycleFocusTest(browser()); |
| 93 } |
| 94 |
| 95 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocusWithBookmarkBar) { |
| 96 CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| 97 updater->ExecuteCommand(IDC_SHOW_BOOKMARK_BAR); |
| 98 |
| 99 BookmarkModel* model = |
| 100 BookmarkModelFactory::GetForProfile(browser()->profile()); |
| 101 bookmark_utils::AddIfNotBookmarked( |
| 102 model, GURL("http://foo.com"), ASCIIToUTF16("Foo")); |
| 103 |
| 104 // We want to specifically test the case where the bookmark bar is |
| 105 // already showing when a window opens, so create a second browser |
| 106 // window with the same profile. |
| 107 Browser* second_browser = CreateBrowser(browser()->profile()); |
| 108 RunToolbarCycleFocusTest(second_browser); |
| 109 } |
| 110 |
85 } // namespace | 111 } // namespace |
OLD | NEW |