| 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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/toolbar/test_toolbar_model.h" | 12 #include "components/toolbar/test_toolbar_model.h" |
| 13 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 13 #include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 15 #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/ui/omnibox/omnibox_text_field_ios.h" | 16 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |
| 17 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" | 17 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" |
| 18 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" | 18 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" |
| 19 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 19 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
| 20 #include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h" | 20 #include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h" |
| 21 #include "ios/chrome/browser/web_state_list/web_state_list.h" | 21 #include "ios/chrome/browser/web_state_list/web_state_list.h" |
| 22 #include "ios/chrome/test/base/perf_test_ios.h" | 22 #include "ios/chrome/test/base/perf_test_ios.h" |
| 23 #include "ios/web/public/test/fakes/test_navigation_manager.h" |
| 23 #include "ios/web/public/test/fakes/test_web_state.h" | 24 #include "ios/web/public/test/fakes/test_web_state.h" |
| 24 #include "testing/platform_test.h" | 25 #include "testing/platform_test.h" |
| 25 #import "third_party/ocmock/OCMock/OCMock.h" | 26 #import "third_party/ocmock/OCMock/OCMock.h" |
| 26 #import "ui/base/test/ios/keyboard_appearance_listener.h" | 27 #import "ui/base/test/ios/keyboard_appearance_listener.h" |
| 27 | 28 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 29 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." | 30 #error "This file requires ARC support." |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // Create a real window to host the Toolbar. | 74 // Create a real window to host the Toolbar. |
| 74 CGRect screenBounds = [[UIScreen mainScreen] bounds]; | 75 CGRect screenBounds = [[UIScreen mainScreen] bounds]; |
| 75 window_ = [[UIWindow alloc] initWithFrame:screenBounds]; | 76 window_ = [[UIWindow alloc] initWithFrame:screenBounds]; |
| 76 [window_ makeKeyAndVisible]; | 77 [window_ makeKeyAndVisible]; |
| 77 | 78 |
| 78 // Create a WebStateList that will always return the test WebState as | 79 // Create a WebStateList that will always return the test WebState as |
| 79 // the active WebState. | 80 // the active WebState. |
| 80 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); | 81 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); |
| 81 std::unique_ptr<web::TestWebState> web_state = | 82 std::unique_ptr<web::TestWebState> web_state = |
| 82 base::MakeUnique<web::TestWebState>(); | 83 base::MakeUnique<web::TestWebState>(); |
| 84 std::unique_ptr<web::TestNavigationManager> navigation_manager = |
| 85 base::MakeUnique<web::TestNavigationManager>(); |
| 86 web_state->SetNavigationManager(std::move(navigation_manager)); |
| 83 web_state_list_->InsertWebState(0, std::move(web_state)); | 87 web_state_list_->InsertWebState(0, std::move(web_state)); |
| 84 | 88 |
| 85 // Creates the Toolbar for testing and sizes it to the width of the screen. | 89 // Creates the Toolbar for testing and sizes it to the width of the screen. |
| 86 toolbar_model_delegate_.reset( | 90 toolbar_model_delegate_.reset( |
| 87 new ToolbarModelDelegateIOS(web_state_list_.get())); | 91 new ToolbarModelDelegateIOS(web_state_list_.get())); |
| 88 toolbar_model_ios_.reset( | 92 toolbar_model_ios_.reset( |
| 89 new ToolbarModelImplIOS(toolbar_model_delegate_.get())); | 93 new ToolbarModelImplIOS(toolbar_model_delegate_.get())); |
| 90 | 94 |
| 91 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just | 95 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just |
| 92 // fine if a temporary variable is used. | 96 // fine if a temporary variable is used. |
| 93 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); | 97 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); |
| 98 web::WebState* web_state_for_mock = web_state_list_->GetWebStateAt(0); |
| 94 id webToolbarDelegate = | 99 id webToolbarDelegate = |
| 95 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; | 100 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; |
| 96 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] | 101 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] |
| 97 toolbarModelIOS]; | 102 toolbarModelIOS]; |
| 103 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(web_state_for_mock)] |
| 104 currentWebState]; |
| 98 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; | 105 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; |
| 99 toolbar_ = [[WebToolbarController alloc] | 106 toolbar_ = [[WebToolbarController alloc] |
| 100 initWithDelegate:webToolbarDelegate | 107 initWithDelegate:webToolbarDelegate |
| 101 urlLoader:urlLoader | 108 urlLoader:urlLoader |
| 102 browserState:chrome_browser_state_.get() | 109 browserState:chrome_browser_state_.get() |
| 103 preloadProvider:nil]; | 110 preloadProvider:nil]; |
| 104 UIView* toolbarView = [toolbar_ view]; | 111 UIView* toolbarView = [toolbar_ view]; |
| 105 CGRect toolbarFrame = toolbarView.frame; | 112 CGRect toolbarFrame = toolbarView.frame; |
| 106 toolbarFrame.origin = CGPointZero; | 113 toolbarFrame.origin = CGPointZero; |
| 107 toolbarFrame.size.width = screenBounds.size.width; | 114 toolbarFrame.size.width = screenBounds.size.width; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 ^base::TimeDelta(int index) { | 233 ^base::TimeDelta(int index) { |
| 227 return EnableKeyboard(textField); | 234 return EnableKeyboard(textField); |
| 228 }, | 235 }, |
| 229 ^() { | 236 ^() { |
| 230 DisableKeyboard(textField); | 237 DisableKeyboard(textField); |
| 231 }); | 238 }); |
| 232 } | 239 } |
| 233 | 240 |
| 234 // Measures the amount of time it takes to type in the first character | 241 // Measures the amount of time it takes to type in the first character |
| 235 // into the Omnibox. | 242 // into the Omnibox. |
| 236 // TODO(crbug.com/717309): Test disabled because of nullptr dereferencing. | 243 TEST_F(OmniboxPerfTest, TestTypeOneCharInTextField) { |
| 237 TEST_F(OmniboxPerfTest, DISABLED_TestTypeOneCharInTextField) { | |
| 238 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass( | 244 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass( |
| 239 [toolbar_ view], [OmniboxTextFieldIOS class]); | 245 [toolbar_ view], [OmniboxTextFieldIOS class]); |
| 240 RepeatTimedRuns("Type first character", | 246 RepeatTimedRuns("Type first character", |
| 241 ^base::TimeDelta(int index) { | 247 ^base::TimeDelta(int index) { |
| 242 EnableKeyboard(textField); | 248 EnableKeyboard(textField); |
| 243 return TimeInsertText(textField, @"G"); | 249 return TimeInsertText(textField, @"G"); |
| 244 }, | 250 }, |
| 245 ^() { | 251 ^() { |
| 246 [textField setText:@""]; | 252 [textField setText:@""]; |
| 247 DisableKeyboard(textField); | 253 DisableKeyboard(textField); |
| 248 }); | 254 }); |
| 249 } | 255 } |
| 250 | 256 |
| 251 // Measures the amount of time it takes to type in the word "google" one | 257 // Measures the amount of time it takes to type in the word "google" one |
| 252 // letter at a time. | 258 // letter at a time. |
| 253 // TODO(crbug.com/717309): Test disabled because of nullptr dereferencing. | 259 TEST_F(OmniboxPerfTest, TestTypingInTextField) { |
| 254 TEST_F(OmniboxPerfTest, DISABLED_TestTypingInTextField) { | |
| 255 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass( | 260 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass( |
| 256 [toolbar_ view], [OmniboxTextFieldIOS class]); | 261 [toolbar_ view], [OmniboxTextFieldIOS class]); |
| 257 // The characters to type into the omnibox text field. | 262 // The characters to type into the omnibox text field. |
| 258 NSArray* inputCharacters = | 263 NSArray* inputCharacters = |
| 259 [NSArray arrayWithObjects:@"g", @"o", @"o", @"g", @"l", @"e", nil]; | 264 [NSArray arrayWithObjects:@"g", @"o", @"o", @"g", @"l", @"e", nil]; |
| 260 RepeatTimedRuns( | 265 RepeatTimedRuns( |
| 261 "Typing", | 266 "Typing", |
| 262 ^base::TimeDelta(int index) { | 267 ^base::TimeDelta(int index) { |
| 263 EnableKeyboard(textField); | 268 EnableKeyboard(textField); |
| 264 NSMutableString* logMessage = [NSMutableString string]; | 269 NSMutableString* logMessage = [NSMutableString string]; |
| 265 base::TimeDelta elapsed; | 270 base::TimeDelta elapsed; |
| 266 for (NSString* input in inputCharacters) { | 271 for (NSString* input in inputCharacters) { |
| 267 base::TimeDelta inputElapsed = TimeInsertText(textField, input); | 272 base::TimeDelta inputElapsed = TimeInsertText(textField, input); |
| 268 [logMessage appendFormat:@"%@'%@':%.0f", | 273 [logMessage appendFormat:@"%@'%@':%.0f", |
| 269 [logMessage length] ? @" " : @"", input, | 274 [logMessage length] ? @" " : @"", input, |
| 270 inputElapsed.InMillisecondsF()]; | 275 inputElapsed.InMillisecondsF()]; |
| 271 elapsed += inputElapsed; | 276 elapsed += inputElapsed; |
| 272 } | 277 } |
| 273 NSLog(@"%2d: %@", index, logMessage); | 278 NSLog(@"%2d: %@", index, logMessage); |
| 274 return elapsed; | 279 return elapsed; |
| 275 }, | 280 }, |
| 276 ^() { | 281 ^() { |
| 277 [textField setText:@""]; | 282 [textField setText:@""]; |
| 278 DisableKeyboard(textField); | 283 DisableKeyboard(textField); |
| 279 }); | 284 }); |
| 280 } | 285 } |
| 281 } | 286 } |
| OLD | NEW |