| 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 #include "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h" | 8 #include "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h" |
| 9 #include "chrome/browser/ui/find_bar/find_bar.h" | 9 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 10 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 11 #include "chrome/browser/ui/location_bar/location_bar.h" | 11 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 bool FindBarHasFocus(Browser* browser) { | 17 bool FindBarHasFocus(Browser* browser) { |
| 18 NSWindow* window = browser->window()->GetNativeWindow(); | 18 NSWindow* window = browser->window()->GetNativeWindow(); |
| 19 NSText* text_view = base::mac::ObjCCast<NSText>([window firstResponder]); | 19 NSText* text_view = base::mac::ObjCCast<NSText>([window firstResponder]); |
| 20 return [[text_view delegate] isKindOfClass:[FindBarTextField class]]; | 20 return [[text_view delegate] isKindOfClass:[FindBarTextField class]]; |
| 21 } | 21 } |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 typedef InProcessBrowserTest FindBarBrowserTest; | 25 typedef InProcessBrowserTest FindBarBrowserTest; |
| 26 | 26 |
| 27 IN_PROC_BROWSER_TEST_F(FindBarBrowserTest, FocusOnTabSwitch) { | 27 IN_PROC_BROWSER_TEST_F(FindBarBrowserTest, FocusOnTabSwitch) { |
| 28 AddTabAtIndex(1, GURL("about:blank"), content::PAGE_TRANSITION_LINK); | 28 AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK); |
| 29 browser()->GetFindBarController()->Show(); | 29 browser()->GetFindBarController()->Show(); |
| 30 | 30 |
| 31 // Verify that if the find bar has focus then switching tabs and changing | 31 // Verify that if the find bar has focus then switching tabs and changing |
| 32 // back sets focus back to the find bar. | 32 // back sets focus back to the find bar. |
| 33 browser()->GetFindBarController()->find_bar()->SetFocusAndSelection(); | 33 browser()->GetFindBarController()->find_bar()->SetFocusAndSelection(); |
| 34 EXPECT_TRUE(FindBarHasFocus(browser())); | 34 EXPECT_TRUE(FindBarHasFocus(browser())); |
| 35 browser()->tab_strip_model()->ActivateTabAt(0, true); | 35 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 36 EXPECT_FALSE(FindBarHasFocus(browser())); | 36 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 37 browser()->tab_strip_model()->ActivateTabAt(1, true); | 37 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 38 EXPECT_TRUE(FindBarHasFocus(browser())); | 38 EXPECT_TRUE(FindBarHasFocus(browser())); |
| 39 | 39 |
| 40 // Verify that if the find bar does not have focus then switching tabs and | 40 // Verify that if the find bar does not have focus then switching tabs and |
| 41 // changing does not set focus to the find bar. | 41 // changing does not set focus to the find bar. |
| 42 browser()->window()->GetLocationBar()->FocusLocation(true); | 42 browser()->window()->GetLocationBar()->FocusLocation(true); |
| 43 EXPECT_FALSE(FindBarHasFocus(browser())); | 43 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 44 browser()->tab_strip_model()->ActivateTabAt(0, true); | 44 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 45 EXPECT_FALSE(FindBarHasFocus(browser())); | 45 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 46 browser()->tab_strip_model()->ActivateTabAt(1, true); | 46 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 47 EXPECT_FALSE(FindBarHasFocus(browser())); | 47 EXPECT_FALSE(FindBarHasFocus(browser())); |
| 48 } | 48 } |
| OLD | NEW |