| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_command_controller.h" | 16 #include "chrome/browser/ui/browser_command_controller.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
| 18 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 void ToolbarViewTest::RunToolbarCycleFocusTest(Browser* browser) { | 41 void ToolbarViewTest::RunToolbarCycleFocusTest(Browser* browser) { |
| 41 gfx::NativeWindow window = browser->window()->GetNativeWindow(); | 42 gfx::NativeWindow window = browser->window()->GetNativeWindow(); |
| 42 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 43 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 43 views::FocusManager* focus_manager = widget->GetFocusManager(); | 44 views::FocusManager* focus_manager = widget->GetFocusManager(); |
| 44 CommandUpdater* updater = browser->command_controller()->command_updater(); | 45 CommandUpdater* updater = browser->command_controller()->command_updater(); |
| 45 | 46 |
| 46 // Send focus to the toolbar as if the user pressed Alt+Shift+T. | 47 // Send focus to the toolbar as if the user pressed Alt+Shift+T. |
| 47 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); | 48 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); |
| 48 | 49 |
| 50 // This is needed as test relies on browser window activation, while platform |
| 51 // such as Linux's window activation is asynchronous. |
| 52 base::RunLoop().RunUntilIdle(); |
| 53 |
| 49 views::View* first_view = focus_manager->GetFocusedView(); | 54 views::View* first_view = focus_manager->GetFocusedView(); |
| 50 std::vector<int> ids; | 55 std::vector<int> ids; |
| 51 | 56 |
| 52 // Press Tab to cycle through all of the controls in the toolbar until | 57 // Press Tab to cycle through all of the controls in the toolbar until |
| 53 // we end up back where we started. | 58 // we end up back where we started. |
| 54 bool found_reload = false; | 59 bool found_reload = false; |
| 55 bool found_location_bar = false; | 60 bool found_location_bar = false; |
| 56 bool found_app_menu = false; | 61 bool found_app_menu = false; |
| 57 const views::View* view = NULL; | 62 const views::View* view = NULL; |
| 58 while (view != first_view) { | 63 while (view != first_view) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 for (size_t i = 0; i < count - 1; i++) | 98 for (size_t i = 0; i < count - 1; i++) |
| 94 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); | 99 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); |
| 95 } | 100 } |
| 96 | 101 |
| 97 // The test is flaky on Win (http://crbug.com/152938) and crashes on CrOS under | 102 // The test is flaky on Win (http://crbug.com/152938) and crashes on CrOS under |
| 98 // AddressSanitizer (http://crbug.com/154657). | 103 // AddressSanitizer (http://crbug.com/154657). |
| 99 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, DISABLED_ToolbarCycleFocus) { | 104 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, DISABLED_ToolbarCycleFocus) { |
| 100 RunToolbarCycleFocusTest(browser()); | 105 RunToolbarCycleFocusTest(browser()); |
| 101 } | 106 } |
| 102 | 107 |
| 103 #if defined(OS_WIN) | 108 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocusWithBookmarkBar) { |
| 104 // http://crbug.com/152938 Flaky on win. | |
| 105 #define MAYBE_ToolbarCycleFocusWithBookmarkBar \ | |
| 106 DISABLED_ToolbarCycleFocusWithBookmarkBar | |
| 107 #else | |
| 108 #define MAYBE_ToolbarCycleFocusWithBookmarkBar ToolbarCycleFocusWithBookmarkBar | |
| 109 #endif | |
| 110 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, | |
| 111 MAYBE_ToolbarCycleFocusWithBookmarkBar) { | |
| 112 CommandUpdater* updater = browser()->command_controller()->command_updater(); | 109 CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| 113 updater->ExecuteCommand(IDC_SHOW_BOOKMARK_BAR); | 110 updater->ExecuteCommand(IDC_SHOW_BOOKMARK_BAR); |
| 114 | 111 |
| 115 BookmarkModel* model = | 112 BookmarkModel* model = |
| 116 BookmarkModelFactory::GetForBrowserContext(browser()->profile()); | 113 BookmarkModelFactory::GetForBrowserContext(browser()->profile()); |
| 117 bookmarks::AddIfNotBookmarked( | 114 bookmarks::AddIfNotBookmarked( |
| 118 model, GURL("http://foo.com"), base::ASCIIToUTF16("Foo")); | 115 model, GURL("http://foo.com"), base::ASCIIToUTF16("Foo")); |
| 119 | 116 |
| 120 // We want to specifically test the case where the bookmark bar is | 117 // We want to specifically test the case where the bookmark bar is |
| 121 // already showing when a window opens, so create a second browser | 118 // already showing when a window opens, so create a second browser |
| 122 // window with the same profile. | 119 // window with the same profile. |
| 123 Browser* second_browser = CreateBrowser(browser()->profile()); | 120 Browser* second_browser = CreateBrowser(browser()->profile()); |
| 124 RunToolbarCycleFocusTest(second_browser); | 121 RunToolbarCycleFocusTest(second_browser); |
| 125 } | 122 } |
| 126 | 123 |
| 127 } // namespace | 124 } // namespace |
| OLD | NEW |