Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/app/chrome_command_ids.h" | |
| 6 #include "chrome/browser/ui/browser.h" | |
| 7 #include "chrome/browser/ui/browser_window.h" | |
| 8 #include "chrome/browser/ui/browser_command_controller.h" | |
| 9 #include "chrome/browser/ui/view_ids.h" | |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 11 #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.
| |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "ui/views/focus/focus_manager.h" | |
| 14 #include "ui/views/view.h" | |
| 15 #include "ui/views/widget/widget.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 class ToolbarViewTest : public InProcessBrowserTest { | |
| 20 public: | |
| 21 ToolbarViewTest() {} | |
| 22 DISALLOW_COPY_AND_ASSIGN(ToolbarViewTest); | |
|
sky
2012/09/18 21:46:06
private
dmazzoni
2012/09/19 00:23:40
Done.
| |
| 23 }; | |
| 24 | |
| 25 IN_PROC_BROWSER_TEST_F(ToolbarViewTest, ToolbarCycleFocus) { | |
| 26 gfx::NativeWindow window = browser()->window()->GetNativeWindow(); | |
| 27 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
| 28 views::FocusManager* focus_manager = widget->GetFocusManager(); | |
| 29 CommandUpdater* updater = browser()->command_controller()->command_updater(); | |
| 30 | |
| 31 // Send focus to the toolbar as if the user pressed Alt+Shift+T. | |
| 32 updater->ExecuteCommand(IDC_FOCUS_TOOLBAR); | |
| 33 | |
| 34 views::View* first_view = focus_manager->GetFocusedView(); | |
| 35 std::vector<int> ids; | |
| 36 | |
| 37 // Press Tab to cycle through all of the controls in the toolbar until | |
| 38 // we end up back where we started. | |
| 39 bool found_reload = false; | |
| 40 bool found_location_bar = false; | |
| 41 bool found_app_menu = false; | |
| 42 const views::View* view = NULL; | |
| 43 while (view != first_view) { | |
| 44 focus_manager->AdvanceFocus(false); | |
| 45 view = focus_manager->GetFocusedView(); | |
| 46 LOG(INFO) << "Focused view ID: " << view->id(); | |
| 47 ids.push_back(view->id()); | |
|
sky
2012/09/18 21:46:06
Remove all these logs
dmazzoni
2012/09/19 00:23:40
Done.
| |
| 48 if (view->id() == VIEW_ID_RELOAD_BUTTON) | |
| 49 found_reload = true; | |
| 50 if (view->id() == VIEW_ID_APP_MENU) | |
| 51 found_app_menu = true; | |
| 52 if (view->id() == VIEW_ID_LOCATION_BAR) | |
| 53 found_location_bar = true; | |
| 54 if (ids.size() > 100) | |
| 55 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
| |
| 56 } | |
| 57 | |
| 58 // Make sure we found a few key items. | |
| 59 ASSERT_TRUE(found_reload); | |
| 60 ASSERT_TRUE(found_app_menu); | |
| 61 ASSERT_TRUE(found_location_bar); | |
| 62 | |
| 63 // Now press Shift-Tab to cycle backwards. | |
| 64 std::vector<int> reverse_ids; | |
| 65 view = NULL; | |
| 66 while (view != first_view) { | |
| 67 focus_manager->AdvanceFocus(true); | |
| 68 view = focus_manager->GetFocusedView(); | |
| 69 LOG(INFO) << "REVERSE Focused view ID: " << view->id(); | |
| 70 reverse_ids.push_back(view->id()); | |
| 71 if (reverse_ids.size() > 100) | |
| 72 LOG(FATAL) << "Tabbed 100 times, still haven't cycled back!"; | |
|
sky
2012/09/18 21:46:06
ASSERT
| |
| 73 } | |
| 74 | |
| 75 // Assert that the views were focused in exactly the reverse order. | |
| 76 // The sequences should be the same length, and the last element will | |
| 77 // be the same, and the others are reverse. | |
| 78 ASSERT_EQ(ids.size(), reverse_ids.size()); | |
| 79 size_t count = ids.size(); | |
| 80 for (size_t i = 0; i < count - 1; i++) | |
| 81 EXPECT_EQ(ids[i], reverse_ids[count - 2 - i]); | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| OLD | NEW |