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 #include "base/memory/ptr_util.h" | |
11 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "components/toolbar/test_toolbar_model.h" | 12 #include "components/toolbar/test_toolbar_model.h" |
14 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
15 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
16 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" | 15 #include "ios/chrome/browser/search_engines/template_url_service_factory.h" |
| 16 #import "ios/chrome/browser/tabs/tab.h" |
| 17 #import "ios/chrome/browser/tabs/tab_model.h" |
17 #include "ios/chrome/browser/ui/omnibox/location_bar_view_ios.h" | 18 #include "ios/chrome/browser/ui/omnibox/location_bar_view_ios.h" |
18 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" | 19 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |
19 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" | 20 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" |
20 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" | 21 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" |
21 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 22 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
22 #include "ios/chrome/test/base/perf_test_ios.h" | 23 #include "ios/chrome/test/base/perf_test_ios.h" |
23 #include "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h" | |
24 #include "ios/shared/chrome/browser/tabs/web_state_list.h" | |
25 #include "ios/web/public/test/fakes/test_web_state.h" | |
26 #include "testing/platform_test.h" | 24 #include "testing/platform_test.h" |
27 #import "third_party/ocmock/OCMock/OCMock.h" | 25 #import "third_party/ocmock/OCMock/OCMock.h" |
28 #import "ui/base/test/ios/keyboard_appearance_listener.h" | 26 #import "ui/base/test/ios/keyboard_appearance_listener.h" |
29 | 27 |
30 namespace { | 28 namespace { |
31 | 29 |
32 // Descends down a view hierarchy until the first view of |specificClass| | 30 // Descends down a view hierarchy until the first view of |specificClass| |
33 // is found. Returns nil if a view of |specificClass| cannot be found. | 31 // is found. Returns nil if a view of |specificClass| cannot be found. |
34 UIView* FindViewByClass(UIView* topView, Class specificClass) { | 32 UIView* FindViewByClass(UIView* topView, Class specificClass) { |
35 if ([topView isKindOfClass:specificClass]) | 33 if ([topView isKindOfClass:specificClass]) |
(...skipping 30 matching lines...) Expand all Loading... |
66 chrome_browser_state_.get()); | 64 chrome_browser_state_.get()); |
67 | 65 |
68 // Sets up the listener for keyboard activation/deactivation notifications. | 66 // Sets up the listener for keyboard activation/deactivation notifications. |
69 keyboard_listener_.reset([[KeyboardAppearanceListener alloc] init]); | 67 keyboard_listener_.reset([[KeyboardAppearanceListener alloc] init]); |
70 | 68 |
71 // Create a real window to host the Toolbar. | 69 // Create a real window to host the Toolbar. |
72 CGRect screenBounds = [[UIScreen mainScreen] bounds]; | 70 CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
73 window_.reset([[UIWindow alloc] initWithFrame:screenBounds]); | 71 window_.reset([[UIWindow alloc] initWithFrame:screenBounds]); |
74 [window_ makeKeyAndVisible]; | 72 [window_ makeKeyAndVisible]; |
75 | 73 |
76 // Create a WebStateList that will always return the test WebState as | 74 // Create a mock Tab and a TabModel that will always return the mock Tab as |
77 // the active WebState. | 75 // the current tab. |
78 web_state_list_ = base::MakeUnique<WebStateList>( | 76 current_tab_.reset( |
79 &web_state_list_delegate_, WebStateList::WebStateOwned); | 77 [(Tab*)[OCMockObject niceMockForClass:[Tab class]] retain]); |
80 std::unique_ptr<web::TestWebState> web_state = | 78 id tab_model = [OCMockObject mockForClass:[TabModel class]]; |
81 base::MakeUnique<web::TestWebState>(); | 79 [[[tab_model stub] andReturn:current_tab_] currentTab]; |
82 web_state_list_->InsertWebState(0, web_state.release()); | 80 tab_model_.reset([tab_model retain]); |
83 | 81 |
84 // Creates the Toolbar for testing and sizes it to the width of the screen. | 82 // Creates the Toolbar for testing and sizes it to the width of the screen. |
85 toolbar_model_delegate_.reset( | 83 toolbar_model_delegate_.reset( |
86 new ToolbarModelDelegateIOS(web_state_list_.get())); | 84 new ToolbarModelDelegateIOS(tab_model_.get())); |
87 toolbar_model_ios_.reset( | 85 toolbar_model_ios_.reset( |
88 new ToolbarModelImplIOS(toolbar_model_delegate_.get())); | 86 new ToolbarModelImplIOS(toolbar_model_delegate_.get())); |
89 | 87 |
90 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just | 88 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just |
91 // fine if a temporary variable is used. | 89 // fine if a temporary variable is used. |
92 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); | 90 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); |
93 id webToolbarDelegate = | 91 id webToolbarDelegate = |
94 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; | 92 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; |
95 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] | 93 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] |
96 toolbarModelIOS]; | 94 toolbarModelIOS]; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 [textField exitPreEditState]; | 194 [textField exitPreEditState]; |
197 [textField resignFirstResponder]; | 195 [textField resignFirstResponder]; |
198 }, | 196 }, |
199 ^bool() { | 197 ^bool() { |
200 return ![keyboard_listener_ isKeyboardVisible]; | 198 return ![keyboard_listener_ isKeyboardVisible]; |
201 }, | 199 }, |
202 false, base::TimeDelta()); | 200 false, base::TimeDelta()); |
203 } | 201 } |
204 | 202 |
205 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; | 203 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
206 FakeWebStateListDelegate web_state_list_delegate_; | 204 base::scoped_nsobject<Tab> current_tab_; |
207 std::unique_ptr<WebStateList> web_state_list_; | 205 base::scoped_nsobject<TabModel> tab_model_; |
208 web::WebState* web_state_; | |
209 std::unique_ptr<ToolbarModelDelegateIOS> toolbar_model_delegate_; | 206 std::unique_ptr<ToolbarModelDelegateIOS> toolbar_model_delegate_; |
210 std::unique_ptr<ToolbarModelIOS> toolbar_model_ios_; | 207 std::unique_ptr<ToolbarModelIOS> toolbar_model_ios_; |
211 base::scoped_nsobject<WebToolbarController> toolbar_; | 208 base::scoped_nsobject<WebToolbarController> toolbar_; |
212 base::scoped_nsobject<UIWindow> window_; | 209 base::scoped_nsobject<UIWindow> window_; |
213 base::scoped_nsobject<KeyboardAppearanceListener> keyboard_listener_; | 210 base::scoped_nsobject<KeyboardAppearanceListener> keyboard_listener_; |
214 }; | 211 }; |
215 | 212 |
216 // Measures the amount of time it takes the Omnibox text field to activate | 213 // Measures the amount of time it takes the Omnibox text field to activate |
217 // the on-screen keyboard. | 214 // the on-screen keyboard. |
218 TEST_F(OmniboxPerfTest, TestTextFieldDidBeginEditing) { | 215 TEST_F(OmniboxPerfTest, TestTextFieldDidBeginEditing) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 266 } |
270 NSLog(@"%2d: %@", index, logMessage); | 267 NSLog(@"%2d: %@", index, logMessage); |
271 return elapsed; | 268 return elapsed; |
272 }, | 269 }, |
273 ^() { | 270 ^() { |
274 [textField setText:@""]; | 271 [textField setText:@""]; |
275 DisableKeyboard(textField); | 272 DisableKeyboard(textField); |
276 }); | 273 }); |
277 } | 274 } |
278 } | 275 } |
OLD | NEW |