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.
5 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
7 #include "base/files/file_path.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/find_bar/find_bar_host_unittest_util.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "ui/base/accelerators/accelerator.h"
15 #include "ui/views/focus/focus_manager.h"
16 #include "ui/views/widget/widget.h"
21 const char kSimple
[] = "simple.html";
23 GURL
GetURL(const std::string
& filename
) {
24 return ui_test_utils::GetTestUrl(base::FilePath().AppendASCII("find_in_page"),
25 base::FilePath().AppendASCII(filename
));
28 class FindBarControllerTest
: public InProcessBrowserTest
{
30 FindBarControllerTest() {
31 chrome::DisableFindBarAnimationsDuringTesting(true);
35 // Make sure Find box grabs the Esc accelerator and restores it again.
36 IN_PROC_BROWSER_TEST_F(FindBarControllerTest
, AcceleratorRestoring
) {
37 // First we navigate to any page.
38 ui_test_utils::NavigateToURL(browser(), GetURL(kSimple
));
40 gfx::NativeWindow window
= browser()->window()->GetNativeWindow();
41 views::Widget
* widget
= views::Widget::GetWidgetForNativeWindow(window
);
42 views::FocusManager
* focus_manager
= widget
->GetFocusManager();
44 // See where Escape is registered.
45 ui::Accelerator
escape(ui::VKEY_ESCAPE
, ui::EF_NONE
);
46 ui::AcceleratorTarget
* old_target
=
47 focus_manager
->GetCurrentTargetForAccelerator(escape
);
48 EXPECT_TRUE(old_target
!= NULL
);
50 chrome::ShowFindBar(browser());
52 // Our Find bar should be the new target.
53 ui::AcceleratorTarget
* new_target
=
54 focus_manager
->GetCurrentTargetForAccelerator(escape
);
56 EXPECT_TRUE(new_target
!= NULL
);
57 EXPECT_NE(new_target
, old_target
);
59 // Close the Find box.
60 browser()->GetFindBarController()->EndFindSession(
61 FindBarController::kKeepSelectionOnPage
,
62 FindBarController::kKeepResultsInFindBox
);
64 // The accelerator for Escape should be back to what it was before.
66 focus_manager
->GetCurrentTargetForAccelerator(escape
));
68 // Show find bar again with animation on, and the target should be on
70 chrome::DisableFindBarAnimationsDuringTesting(false);
71 chrome::ShowFindBar(browser());
73 focus_manager
->GetCurrentTargetForAccelerator(escape
));