Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: ios/chrome/browser/ui/omnibox_perftest.mm

Issue 2798903002: [ObjC ARC] Converts ios/chrome/browser/ui:perf_tests to ARC. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
10 #include "base/memory/ptr_util.h" 9 #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"
17 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" 16 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
18 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h" 17 #include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
19 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h" 18 #include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h"
20 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" 19 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
21 #include "ios/chrome/test/base/perf_test_ios.h" 20 #include "ios/chrome/test/base/perf_test_ios.h"
22 #include "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h" 21 #include "ios/shared/chrome/browser/tabs/fake_web_state_list_delegate.h"
23 #include "ios/shared/chrome/browser/tabs/web_state_list.h" 22 #include "ios/shared/chrome/browser/tabs/web_state_list.h"
24 #include "ios/web/public/test/fakes/test_web_state.h" 23 #include "ios/web/public/test/fakes/test_web_state.h"
25 #include "testing/platform_test.h" 24 #include "testing/platform_test.h"
26 #import "third_party/ocmock/OCMock/OCMock.h" 25 #import "third_party/ocmock/OCMock/OCMock.h"
27 #import "ui/base/test/ios/keyboard_appearance_listener.h" 26 #import "ui/base/test/ios/keyboard_appearance_listener.h"
28 27
28 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support."
30 #endif
31
29 namespace { 32 namespace {
30 33
31 // Descends down a view hierarchy until the first view of |specificClass| 34 // Descends down a view hierarchy until the first view of |specificClass|
32 // is found. Returns nil if a view of |specificClass| cannot be found. 35 // is found. Returns nil if a view of |specificClass| cannot be found.
33 UIView* FindViewByClass(UIView* topView, Class specificClass) { 36 UIView* FindViewByClass(UIView* topView, Class specificClass) {
34 if ([topView isKindOfClass:specificClass]) 37 if ([topView isKindOfClass:specificClass])
35 return [topView window] ? topView : nil; 38 return [topView window] ? topView : nil;
36 for (UIView* subview in [topView subviews]) { 39 for (UIView* subview in [topView subviews]) {
37 UIView* foundView = FindViewByClass(subview, specificClass); 40 UIView* foundView = FindViewByClass(subview, specificClass);
38 if (foundView) 41 if (foundView)
(...skipping 19 matching lines...) Expand all
58 test_cbs_builder.AddTestingFactory( 61 test_cbs_builder.AddTestingFactory(
59 ios::AutocompleteClassifierFactory::GetInstance(), 62 ios::AutocompleteClassifierFactory::GetInstance(),
60 ios::AutocompleteClassifierFactory::GetDefaultFactory()); 63 ios::AutocompleteClassifierFactory::GetDefaultFactory());
61 chrome_browser_state_ = test_cbs_builder.Build(); 64 chrome_browser_state_ = test_cbs_builder.Build();
62 65
63 // Prepares testing profile for autocompletion. 66 // Prepares testing profile for autocompletion.
64 ios::AutocompleteClassifierFactory::GetForBrowserState( 67 ios::AutocompleteClassifierFactory::GetForBrowserState(
65 chrome_browser_state_.get()); 68 chrome_browser_state_.get());
66 69
67 // Sets up the listener for keyboard activation/deactivation notifications. 70 // Sets up the listener for keyboard activation/deactivation notifications.
68 keyboard_listener_.reset([[KeyboardAppearanceListener alloc] init]); 71 keyboard_listener_ = [[KeyboardAppearanceListener alloc] init];
69 72
70 // Create a real window to host the Toolbar. 73 // Create a real window to host the Toolbar.
71 CGRect screenBounds = [[UIScreen mainScreen] bounds]; 74 CGRect screenBounds = [[UIScreen mainScreen] bounds];
72 window_.reset([[UIWindow alloc] initWithFrame:screenBounds]); 75 window_ = [[UIWindow alloc] initWithFrame:screenBounds];
73 [window_ makeKeyAndVisible]; 76 [window_ makeKeyAndVisible];
74 77
75 // Create a WebStateList that will always return the test WebState as 78 // Create a WebStateList that will always return the test WebState as
76 // the active WebState. 79 // the active WebState.
77 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_); 80 web_state_list_ = base::MakeUnique<WebStateList>(&web_state_list_delegate_);
78 std::unique_ptr<web::TestWebState> web_state = 81 std::unique_ptr<web::TestWebState> web_state =
79 base::MakeUnique<web::TestWebState>(); 82 base::MakeUnique<web::TestWebState>();
80 web_state_list_->InsertWebState(0, std::move(web_state)); 83 web_state_list_->InsertWebState(0, std::move(web_state));
81 84
82 // Creates the Toolbar for testing and sizes it to the width of the screen. 85 // Creates the Toolbar for testing and sizes it to the width of the screen.
83 toolbar_model_delegate_.reset( 86 toolbar_model_delegate_.reset(
84 new ToolbarModelDelegateIOS(web_state_list_.get())); 87 new ToolbarModelDelegateIOS(web_state_list_.get()));
85 toolbar_model_ios_.reset( 88 toolbar_model_ios_.reset(
86 new ToolbarModelImplIOS(toolbar_model_delegate_.get())); 89 new ToolbarModelImplIOS(toolbar_model_delegate_.get()));
87 90
88 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just 91 // The OCMOCK_VALUE macro doesn't like std::unique_ptr, but it works just
89 // fine if a temporary variable is used. 92 // fine if a temporary variable is used.
90 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get(); 93 ToolbarModelIOS* model_for_mock = toolbar_model_ios_.get();
91 id webToolbarDelegate = 94 id webToolbarDelegate =
92 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)]; 95 [OCMockObject niceMockForProtocol:@protocol(WebToolbarDelegate)];
93 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)] 96 [[[webToolbarDelegate stub] andReturnValue:OCMOCK_VALUE(model_for_mock)]
94 toolbarModelIOS]; 97 toolbarModelIOS];
95 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)]; 98 id urlLoader = [OCMockObject niceMockForProtocol:@protocol(UrlLoader)];
96 toolbar_.reset([[WebToolbarController alloc] 99 toolbar_ = [[WebToolbarController alloc]
97 initWithDelegate:webToolbarDelegate 100 initWithDelegate:webToolbarDelegate
98 urlLoader:urlLoader 101 urlLoader:urlLoader
99 browserState:chrome_browser_state_.get() 102 browserState:chrome_browser_state_.get()
100 preloadProvider:nil]); 103 preloadProvider:nil];
101 UIView* toolbarView = [toolbar_ view]; 104 UIView* toolbarView = [toolbar_ view];
102 CGRect toolbarFrame = toolbarView.frame; 105 CGRect toolbarFrame = toolbarView.frame;
103 toolbarFrame.origin = CGPointZero; 106 toolbarFrame.origin = CGPointZero;
104 toolbarFrame.size.width = screenBounds.size.width; 107 toolbarFrame.size.width = screenBounds.size.width;
105 toolbarView.frame = toolbarFrame; 108 toolbarView.frame = toolbarFrame;
106 // Add toolbar to window. 109 // Add toolbar to window.
107 [window_ addSubview:toolbarView]; 110 [window_ addSubview:toolbarView];
108 base::test::ios::WaitUntilCondition(^bool() { 111 base::test::ios::WaitUntilCondition(^bool() {
109 return IsToolbarLoaded(window_.get()); 112 return IsToolbarLoaded(window_);
110 }); 113 });
111 } 114 }
112 115
113 void TearDown() override { 116 void TearDown() override {
114 // Remove toolbar from window. 117 // Remove toolbar from window.
115 [[toolbar_ view] removeFromSuperview]; 118 [[toolbar_ view] removeFromSuperview];
116 base::test::ios::WaitUntilCondition(^bool() { 119 base::test::ios::WaitUntilCondition(^bool() {
117 return !IsToolbarLoaded(window_.get()); 120 return !IsToolbarLoaded(window_);
118 }); 121 });
119 [toolbar_ browserStateDestroyed]; 122 [toolbar_ browserStateDestroyed];
120 PerfTest::TearDown(); 123 PerfTest::TearDown();
121 } 124 }
122 125
123 // Returns whether Omnibox has been loaded. 126 // Returns whether Omnibox has been loaded.
124 bool IsToolbarLoaded(UIView* topView) { 127 bool IsToolbarLoaded(UIView* topView) {
125 return FindViewByClass(topView, [OmniboxTextFieldIOS class]) != nil; 128 return FindViewByClass(topView, [OmniboxTextFieldIOS class]) != nil;
126 } 129 }
127 130
(...skipping 13 matching lines...) Expand all
141 base::TimeDelta::FromSecondsD(kSpinDelaySeconds)); 144 base::TimeDelta::FromSecondsD(kSpinDelaySeconds));
142 return elapsed; 145 return elapsed;
143 } 146 }
144 147
145 // Creates a dummy text field and make it be a first responder so keyboard 148 // Creates a dummy text field and make it be a first responder so keyboard
146 // comes up. In general, there's a lot of time spent in loading up various 149 // comes up. In general, there's a lot of time spent in loading up various
147 // graphics assets on a keyboard which may distort the measurement of Chrome 150 // graphics assets on a keyboard which may distort the measurement of Chrome
148 // Omnibox focus timings. Call this function to preload keyboard before 151 // Omnibox focus timings. Call this function to preload keyboard before
149 // doing the real test. 152 // doing the real test.
150 base::TimeDelta PreLoadKeyboard() { 153 base::TimeDelta PreLoadKeyboard() {
151 base::scoped_nsobject<UITextField> textField( 154 UITextField* textField =
152 [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 280, 29)]); 155 [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 280, 29)];
153 [textField setBorderStyle:UITextBorderStyleRoundedRect]; 156 [textField setBorderStyle:UITextBorderStyleRoundedRect];
154 [window_ addSubview:textField]; 157 [window_ addSubview:textField];
155 base::TimeDelta elapsed = base::test::ios::TimeUntilCondition( 158 base::TimeDelta elapsed = base::test::ios::TimeUntilCondition(
156 ^{ 159 ^{
157 [textField becomeFirstResponder]; 160 [textField becomeFirstResponder];
158 }, 161 },
159 ^bool() { 162 ^bool() {
160 return [keyboard_listener_ isKeyboardVisible]; 163 return [keyboard_listener_ isKeyboardVisible];
161 }, 164 },
162 false, base::TimeDelta()); 165 false, base::TimeDelta());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return ![keyboard_listener_ isKeyboardVisible]; 201 return ![keyboard_listener_ isKeyboardVisible];
199 }, 202 },
200 false, base::TimeDelta()); 203 false, base::TimeDelta());
201 } 204 }
202 205
203 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 206 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
204 FakeWebStateListDelegate web_state_list_delegate_; 207 FakeWebStateListDelegate web_state_list_delegate_;
205 std::unique_ptr<WebStateList> web_state_list_; 208 std::unique_ptr<WebStateList> web_state_list_;
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 WebToolbarController* toolbar_;
209 base::scoped_nsobject<UIWindow> window_; 212 UIWindow* window_;
210 base::scoped_nsobject<KeyboardAppearanceListener> keyboard_listener_; 213 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) {
216 LogPerfTiming("Keyboard preload", PreLoadKeyboard()); 219 LogPerfTiming("Keyboard preload", PreLoadKeyboard());
217 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass( 220 OmniboxTextFieldIOS* textField = (OmniboxTextFieldIOS*)FindViewByClass(
218 [toolbar_ view], [OmniboxTextFieldIOS class]); 221 [toolbar_ view], [OmniboxTextFieldIOS class]);
219 222
220 // Time how long it takes to "focus" on omnibox. 223 // Time how long it takes to "focus" on omnibox.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698