Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar_view_browsertest.cc |
| diff --git a/chrome/browser/ui/views/toolbar_view_browsertest.cc b/chrome/browser/ui/views/toolbar_view_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f74f2d25a6618045a35b6d095b9eb5d8f038063 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/toolbar_view_browsertest.cc |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/browser_command_controller.h" |
| +#include "chrome/browser/ui/view_ids.h" |
| +#include "chrome/browser/ui/views/frame/browser_view.h" |
| +#include "chrome/browser/ui/views/toolbar_view.h" |
|
sky
2012/09/18 21:46:06
Include this first, newline, rest of includes.
dmazzoni
2012/09/19 00:23:40
Done.
|
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "ui/views/focus/focus_manager.h" |
| +#include "ui/views/view.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace { |
| + |
| +class ToolbarViewTest : public InProcessBrowserTest { |
| + public: |
| + ToolbarViewTest() {} |
| + DISALLOW_COPY_AND_ASSIGN(ToolbarViewTest); |
|
sky
2012/09/18 21:46:06
private
dmazzoni
2012/09/19 00:23:40
Done.
|
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocus) { |
| + gfx::NativeWindow window = browser()->window()->GetNativeWindow(); |
| + views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| + views::FocusManager* focus_manager = widget->GetFocusManager(); |
| + CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| + |
| + // Send focus to the toolbar as if the user pressed Alt+Shift+T. |
| + updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); |
| + |
| + views::View* first_view = focus_manager->GetFocusedView(); |
| + std::vector<int> ids; |
| + |
| + // Press Tab to cycle through all of the controls in the toolbar until |
| + // we end up back where we started. |
| + bool found_reload = false; |
| + bool found_location_bar = false; |
| + bool found_app_menu = false; |
| + const views::View* view = NULL; |
| + while (view != first_view) { |
| + focus_manager->AdvanceFocus(false); |
| + view = focus_manager->GetFocusedView(); |
| + LOG(INFO) << "Focused view ID: " << view->id(); |
| + ids.push_back(view->id()); |
|
sky
2012/09/18 21:46:06
Remove all these logs
dmazzoni
2012/09/19 00:23:40
Done.
|
| + if (view->id() == VIEW_ID_RELOAD_BUTTON) |
| + found_reload = true; |
| + if (view->id() == VIEW_ID_APP_MENU) |
| + found_app_menu = true; |
| + if (view->id() == VIEW_ID_LOCATION_BAR) |
| + found_location_bar = true; |
| + if (ids.size() > 100) |
| + LOG(FATAL) << "Tabbed 100 times, still haven't cycled back!"; |
|
sky
2012/09/18 21:46:06
ASSERT(FALSE)
dmazzoni
2012/09/19 00:23:40
There's no ASSERT() in gtest. How about GTEST_FAIL
|
| + } |
| + |
| + // Make sure we found a few key items. |
| + ASSERT_TRUE(found_reload); |
| + ASSERT_TRUE(found_app_menu); |
| + ASSERT_TRUE(found_location_bar); |
| + |
| + // Now press Shift-Tab to cycle backwards. |
| + std::vector<int> reverse_ids; |
| + view = NULL; |
| + while (view != first_view) { |
| + focus_manager->AdvanceFocus(true); |
| + view = focus_manager->GetFocusedView(); |
| + LOG(INFO) << "REVERSE Focused view ID: " << view->id(); |
| + reverse_ids.push_back(view->id()); |
| + if (reverse_ids.size() > 100) |
| + LOG(FATAL) << "Tabbed 100 times, still haven't cycled back!"; |
|
sky
2012/09/18 21:46:06
ASSERT
|
| + } |
| + |
| + // Assert that the views were focused in exactly the reverse order. |
| + // The sequences should be the same length, and the last element will |
| + // be the same, and the others are reverse. |
| + ASSERT_EQ(ids.size(), reverse_ids.size()); |
| + size_t count = ids.size(); |
| + for (size_t i = 0; i < count - 1; i++) |
| + EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); |
| +} |
| + |
| +} // namespace |