| 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 "base/mac/foundation_util.h" | 5 #include "base/mac/foundation_util.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_window.h" | 7 #include "chrome/browser/ui/browser_window.h" |
| 8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 8 #include "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h" | 9 #include "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h" |
| 10 #import "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h" |
| 9 #include "chrome/browser/ui/find_bar/find_bar.h" | 12 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 11 #include "chrome/browser/ui/location_bar/location_bar.h" | 14 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "ui/base/test/ui_controls.h" |
| 18 #import "ui/events/test/cocoa_test_event_utils.h" |
| 14 | 19 |
| 15 namespace { | 20 namespace { |
| 16 | 21 |
| 17 bool FindBarHasFocus(Browser* browser) { | 22 bool FindBarHasFocus(Browser* browser) { |
| 18 NSWindow* window = browser->window()->GetNativeWindow(); | 23 NSWindow* window = browser->window()->GetNativeWindow(); |
| 19 NSText* text_view = base::mac::ObjCCast<NSText>([window firstResponder]); | 24 NSText* text_view = base::mac::ObjCCast<NSText>([window firstResponder]); |
| 20 return [[text_view delegate] isKindOfClass:[FindBarTextField class]]; | 25 return [[text_view delegate] isKindOfClass:[FindBarTextField class]]; |
| 21 } | 26 } |
| 22 | 27 |
| 23 } // namespace | 28 } // namespace |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 | 44 |
| 40 // Verify that if the find bar does not have focus then switching tabs and | 45 // Verify that if the find bar does not have focus then switching tabs and |
| 41 // changing does not set focus to the find bar. | 46 // changing does not set focus to the find bar. |
| 42 browser()->window()->GetLocationBar()->FocusLocation(true); | 47 browser()->window()->GetLocationBar()->FocusLocation(true); |
| 43 EXPECT_FALSE(FindBarHasFocus(browser())); | 48 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 44 browser()->tab_strip_model()->ActivateTabAt(0, true); | 49 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 45 EXPECT_FALSE(FindBarHasFocus(browser())); | 50 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 46 browser()->tab_strip_model()->ActivateTabAt(1, true); | 51 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 47 EXPECT_FALSE(FindBarHasFocus(browser())); | 52 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 48 } | 53 } |
| 54 |
| 55 IN_PROC_BROWSER_TEST_F(FindBarBrowserTest, EscapeKey) { |
| 56 // Enter fullscreen. |
| 57 std::unique_ptr<FullscreenNotificationObserver> waiter( |
| 58 new FullscreenNotificationObserver()); |
| 59 browser() |
| 60 ->exclusive_access_manager() |
| 61 ->fullscreen_controller() |
| 62 ->ToggleBrowserFullscreenMode(); |
| 63 waiter->Wait(); |
| 64 |
| 65 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 66 BrowserWindowController* bwc = |
| 67 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 68 EXPECT_TRUE([bwc isInAppKitFullscreen]); |
| 69 |
| 70 // Show and focus on the find bar. |
| 71 browser()->GetFindBarController()->Show(); |
| 72 browser()->GetFindBarController()->find_bar()->SetFocusAndSelection(); |
| 73 EXPECT_TRUE(FindBarHasFocus(browser())); |
| 74 |
| 75 // Simulate a key press with the ESC key. |
| 76 base::RunLoop run_loop; |
| 77 ui_controls::EnableUIControls(); |
| 78 ui_controls::SendKeyPressNotifyWhenDone(window, ui::VKEY_ESCAPE, false, false, |
| 79 false, false, run_loop.QuitClosure()); |
| 80 run_loop.Run(); |
| 81 |
| 82 // Check that the browser is still in fullscreen and that the find bar has |
| 83 // lost focus. |
| 84 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 85 EXPECT_TRUE([bwc isInAppKitFullscreen]); |
| 86 } |
| OLD | NEW |