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