| 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 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 EXPECT_EQ(0, model->up_or_down_count()); | 140 EXPECT_EQ(0, model->up_or_down_count()); |
| 141 | 141 |
| 142 // With popup open verify that tab does autocomplete. | 142 // With popup open verify that tab does autocomplete. |
| 143 popup_view.set_is_open(true); | 143 popup_view.set_is_open(true); |
| 144 view.OnDoCommandBySelector(@selector(insertTab:)); | 144 view.OnDoCommandBySelector(@selector(insertTab:)); |
| 145 EXPECT_EQ(1, model->up_or_down_count()); | 145 EXPECT_EQ(1, model->up_or_down_count()); |
| 146 view.OnDoCommandBySelector(@selector(insertBacktab:)); | 146 view.OnDoCommandBySelector(@selector(insertBacktab:)); |
| 147 EXPECT_EQ(-1, model->up_or_down_count()); | 147 EXPECT_EQ(-1, model->up_or_down_count()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(OmniboxViewMacTest, SetGrayTextAutocompletion) { | |
| 151 const NSRect frame = NSMakeRect(0, 0, 50, 30); | |
| 152 base::scoped_nsobject<AutocompleteTextField> field( | |
| 153 [[AutocompleteTextField alloc] initWithFrame:frame]); | |
| 154 | |
| 155 TestingToolbarModelDelegate delegate; | |
| 156 ToolbarModelImpl toolbar_model(&delegate, content::kMaxURLDisplayChars); | |
| 157 TestingOmniboxEditController controller(&toolbar_model); | |
| 158 OmniboxViewMac view(&controller, profile(), NULL, field.get()); | |
| 159 | |
| 160 // This is deleted by the omnibox view. | |
| 161 MockOmniboxEditModel* model = | |
| 162 new MockOmniboxEditModel(&view, &controller, profile()); | |
| 163 SetModel(&view, model); | |
| 164 | |
| 165 MockOmniboxPopupView popup_view; | |
| 166 OmniboxPopupModel popup_model(&popup_view, model); | |
| 167 | |
| 168 view.SetUserText(base::ASCIIToUTF16("Alfred")); | |
| 169 EXPECT_EQ("Alfred", base::UTF16ToUTF8(view.GetText())); | |
| 170 view.SetGrayTextAutocompletion(base::ASCIIToUTF16(" Hitchcock")); | |
| 171 EXPECT_EQ("Alfred", base::UTF16ToUTF8(view.GetText())); | |
| 172 EXPECT_EQ(" Hitchcock", base::UTF16ToUTF8(view.GetGrayTextAutocompletion())); | |
| 173 | |
| 174 view.SetUserText(base::string16()); | |
| 175 EXPECT_EQ(base::string16(), view.GetText()); | |
| 176 EXPECT_EQ(base::string16(), view.GetGrayTextAutocompletion()); | |
| 177 } | |
| 178 | |
| 179 TEST_F(OmniboxViewMacTest, UpDownArrow) { | 150 TEST_F(OmniboxViewMacTest, UpDownArrow) { |
| 180 OmniboxViewMac view(NULL, profile(), NULL, NULL); | 151 OmniboxViewMac view(NULL, profile(), NULL, NULL); |
| 181 | 152 |
| 182 // This is deleted by the omnibox view. | 153 // This is deleted by the omnibox view. |
| 183 MockOmniboxEditModel* model = | 154 MockOmniboxEditModel* model = |
| 184 new MockOmniboxEditModel(&view, NULL, profile()); | 155 new MockOmniboxEditModel(&view, NULL, profile()); |
| 185 SetModel(&view, model); | 156 SetModel(&view, model); |
| 186 | 157 |
| 187 MockOmniboxPopupView popup_view; | 158 MockOmniboxPopupView popup_view; |
| 188 OmniboxPopupModel popup_model(&popup_view, model); | 159 OmniboxPopupModel popup_model(&popup_view, model); |
| 189 | 160 |
| 190 // With popup closed verify that pressing up and down arrow works. | 161 // With popup closed verify that pressing up and down arrow works. |
| 191 popup_view.set_is_open(false); | 162 popup_view.set_is_open(false); |
| 192 model->set_up_or_down_count(0); | 163 model->set_up_or_down_count(0); |
| 193 view.OnDoCommandBySelector(@selector(moveDown:)); | 164 view.OnDoCommandBySelector(@selector(moveDown:)); |
| 194 EXPECT_EQ(1, model->up_or_down_count()); | 165 EXPECT_EQ(1, model->up_or_down_count()); |
| 195 model->set_up_or_down_count(0); | 166 model->set_up_or_down_count(0); |
| 196 view.OnDoCommandBySelector(@selector(moveUp:)); | 167 view.OnDoCommandBySelector(@selector(moveUp:)); |
| 197 EXPECT_EQ(-1, model->up_or_down_count()); | 168 EXPECT_EQ(-1, model->up_or_down_count()); |
| 198 | 169 |
| 199 // With popup open verify that pressing up and down arrow works. | 170 // With popup open verify that pressing up and down arrow works. |
| 200 popup_view.set_is_open(true); | 171 popup_view.set_is_open(true); |
| 201 model->set_up_or_down_count(0); | 172 model->set_up_or_down_count(0); |
| 202 view.OnDoCommandBySelector(@selector(moveDown:)); | 173 view.OnDoCommandBySelector(@selector(moveDown:)); |
| 203 EXPECT_EQ(1, model->up_or_down_count()); | 174 EXPECT_EQ(1, model->up_or_down_count()); |
| 204 model->set_up_or_down_count(0); | 175 model->set_up_or_down_count(0); |
| 205 view.OnDoCommandBySelector(@selector(moveUp:)); | 176 view.OnDoCommandBySelector(@selector(moveUp:)); |
| 206 EXPECT_EQ(-1, model->up_or_down_count()); | 177 EXPECT_EQ(-1, model->up_or_down_count()); |
| 207 } | 178 } |
| OLD | NEW |