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 <UIKit/UIKit.h> | 5 #import <UIKit/UIKit.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 280, 29)]); | 152 [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 280, 29)]); |
153 [textField setBorderStyle:UITextBorderStyleRoundedRect]; | 153 [textField setBorderStyle:UITextBorderStyleRoundedRect]; |
154 [window_ addSubview:textField]; | 154 [window_ addSubview:textField]; |
155 base::TimeDelta elapsed = base::test::ios::TimeUntilCondition( | 155 base::TimeDelta elapsed = base::test::ios::TimeUntilCondition( |
156 ^{ | 156 ^{ |
157 [textField becomeFirstResponder]; | 157 [textField becomeFirstResponder]; |
158 }, | 158 }, |
159 ^bool() { | 159 ^bool() { |
160 return [keyboard_listener_ isKeyboardVisible]; | 160 return [keyboard_listener_ isKeyboardVisible]; |
161 }, | 161 }, |
162 nullptr, base::TimeDelta()); | 162 false, base::TimeDelta()); |
163 base::test::ios::TimeUntilCondition( | 163 base::test::ios::TimeUntilCondition( |
164 ^{ | 164 ^{ |
165 [textField resignFirstResponder]; | 165 [textField resignFirstResponder]; |
166 }, | 166 }, |
167 ^bool() { | 167 ^bool() { |
168 return ![keyboard_listener_ isKeyboardVisible]; | 168 return ![keyboard_listener_ isKeyboardVisible]; |
169 }, | 169 }, |
170 nullptr, base::TimeDelta()); | 170 false, base::TimeDelta()); |
171 [textField removeFromSuperview]; | 171 [textField removeFromSuperview]; |
172 return elapsed; | 172 return elapsed; |
173 } | 173 } |
174 | 174 |
175 // Enables the on-screen keyboard as if user has tapped on |textField|. | 175 // Enables the on-screen keyboard as if user has tapped on |textField|. |
176 // Returns the amount of time it took for the keyboard to appear. | 176 // Returns the amount of time it took for the keyboard to appear. |
177 base::TimeDelta EnableKeyboard(OmniboxTextFieldIOS* textField) { | 177 base::TimeDelta EnableKeyboard(OmniboxTextFieldIOS* textField) { |
178 return base::test::ios::TimeUntilCondition( | 178 return base::test::ios::TimeUntilCondition( |
179 ^{ | 179 ^{ |
180 [textField becomeFirstResponder]; | 180 [textField becomeFirstResponder]; |
181 }, | 181 }, |
182 ^bool() { | 182 ^bool() { |
183 return [keyboard_listener_ isKeyboardVisible]; | 183 return [keyboard_listener_ isKeyboardVisible]; |
184 }, | 184 }, |
185 nullptr, base::TimeDelta()); | 185 false, base::TimeDelta()); |
186 } | 186 } |
187 | 187 |
188 // Performs necessary cleanup (so next pass of unit test can start from | 188 // Performs necessary cleanup (so next pass of unit test can start from |
189 // a clean slate) and then exit from |textField| to dismiss keyboard. | 189 // a clean slate) and then exit from |textField| to dismiss keyboard. |
190 void DisableKeyboard(OmniboxTextFieldIOS* textField) { | 190 void DisableKeyboard(OmniboxTextFieldIOS* textField) { |
191 // Busy wait until keyboard is hidden. | 191 // Busy wait until keyboard is hidden. |
192 base::test::ios::TimeUntilCondition( | 192 base::test::ios::TimeUntilCondition( |
193 ^{ | 193 ^{ |
194 [textField exitPreEditState]; | 194 [textField exitPreEditState]; |
195 [textField resignFirstResponder]; | 195 [textField resignFirstResponder]; |
196 }, | 196 }, |
197 ^bool() { | 197 ^bool() { |
198 return ![keyboard_listener_ isKeyboardVisible]; | 198 return ![keyboard_listener_ isKeyboardVisible]; |
199 }, | 199 }, |
200 nullptr, base::TimeDelta()); | 200 false, base::TimeDelta()); |
201 } | 201 } |
202 | 202 |
203 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 203 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
204 base::scoped_nsobject<Tab> current_tab_; | 204 base::scoped_nsobject<Tab> current_tab_; |
205 base::scoped_nsobject<TabModel> tab_model_; | 205 base::scoped_nsobject<TabModel> tab_model_; |
206 std::unique_ptr<ToolbarModelDelegateIOS> toolbar_model_delegate_; | 206 std::unique_ptr<ToolbarModelDelegateIOS> toolbar_model_delegate_; |
207 std::unique_ptr<ToolbarModelIOS> toolbar_model_ios_; | 207 std::unique_ptr<ToolbarModelIOS> toolbar_model_ios_; |
208 base::scoped_nsobject<WebToolbarController> toolbar_; | 208 base::scoped_nsobject<WebToolbarController> toolbar_; |
209 base::scoped_nsobject<UIWindow> window_; | 209 base::scoped_nsobject<UIWindow> window_; |
210 base::scoped_nsobject<KeyboardAppearanceListener> keyboard_listener_; | 210 base::scoped_nsobject<KeyboardAppearanceListener> keyboard_listener_; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 NSLog(@"%2d: %@", index, logMessage); | 267 NSLog(@"%2d: %@", index, logMessage); |
268 return elapsed; | 268 return elapsed; |
269 }, | 269 }, |
270 ^() { | 270 ^() { |
271 [textField setText:@""]; | 271 [textField setText:@""]; |
272 DisableKeyboard(textField); | 272 DisableKeyboard(textField); |
273 }); | 273 }); |
274 } | 274 } |
275 } | 275 } |
OLD | NEW |