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 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
10 #include "chrome/browser/ui/omnibox/location_bar.h"
11 #include "chrome/test/base/in_process_browser_test.h"
13 class OmniboxViewMacBrowserTest : public InProcessBrowserTest {
15 OmniboxViewMac* GetOmnibox() {
16 return static_cast<OmniboxViewMac*>(
17 browser()->window()->GetLocationBar()->GetOmniboxView());
21 // Verify that the OmniboxViewMac::SetFocus API works.
22 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, SetFocus) {
23 EXPECT_FALSE([[GetOmnibox()->field() window] firstResponder] ==
24 GetOmnibox()->field());
25 GetOmnibox()->SetFocus();
26 // Unfortunately there's no way to test that the field has keyboard focus.
29 // Verify that the OmniboxViewMac::ApplyCaretVisibility API works.
30 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, ApplyCaretVisibility) {
31 EXPECT_FALSE([[GetOmnibox()->field() cell] hideFocusState]);
33 // |SetCaretVisibility(false)| should hide focus state.
34 GetOmnibox()->model()->SetCaretVisibility(false);
35 GetOmnibox()->ApplyCaretVisibility();
36 EXPECT_TRUE([[GetOmnibox()->field() cell] hideFocusState]);
38 // |SetCaretVisibility(true)| should show focus state.
39 GetOmnibox()->model()->SetCaretVisibility(true);
40 GetOmnibox()->ApplyCaretVisibility();
41 EXPECT_FALSE([[GetOmnibox()->field() cell] hideFocusState]);
43 // Focusing on the omnibox should show focus state.
44 GetOmnibox()->model()->SetCaretVisibility(false);
45 GetOmnibox()->ApplyCaretVisibility();
46 EXPECT_TRUE([[GetOmnibox()->field() cell] hideFocusState]);
47 GetOmnibox()->SetFocus();
48 EXPECT_FALSE([[GetOmnibox()->field() cell] hideFocusState]);
52 // Verify that mouse down sets caret visibility to true.
53 IN_PROC_BROWSER_TEST_F(OmniboxViewMacBrowserTest, MouseDownCaretVisibility) {
54 GetOmnibox()->model()->SetCaretVisibility(false);
55 EXPECT_FALSE(GetOmnibox()->model()->is_caret_visible());
56 GetOmnibox()->OnMouseDown(0);
57 EXPECT_TRUE(GetOmnibox()->model()->is_caret_visible());