OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #import "base/mac/bind_objc_block.h" | 8 #import "base/mac/bind_objc_block.h" |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #import "base/test/ios/wait_util.h" | 11 #import "base/test/ios/wait_util.h" |
12 #import "ios/chrome/browser/snapshots/snapshot_manager.h" | 12 #import "ios/chrome/browser/snapshots/snapshot_manager.h" |
13 #import "ios/chrome/browser/tabs/tab.h" | 13 #import "ios/chrome/browser/tabs/tab.h" |
14 #import "ios/chrome/browser/tabs/tab_model.h" | 14 #import "ios/chrome/browser/tabs/tab_model.h" |
15 #include "ios/chrome/browser/test/perf_test_with_bvc_ios.h" | 15 #include "ios/chrome/browser/test/perf_test_with_bvc_ios.h" |
16 #import "ios/chrome/browser/ui/browser_view_controller.h" | 16 #import "ios/chrome/browser/ui/browser_view_controller.h" |
17 #import "ios/chrome/browser/ui/fullscreen_controller.h" | 17 #import "ios/chrome/browser/ui/fullscreen_controller.h" |
18 #import "ios/chrome/browser/ui/stack_view/stack_view_controller.h" | 18 #import "ios/chrome/browser/ui/stack_view/stack_view_controller.h" |
19 #include "ios/chrome/browser/ui/ui_util.h" | 19 #include "ios/chrome/browser/ui/ui_util.h" |
20 #include "ios/web/public/referrer.h" | 20 #include "ios/web/public/referrer.h" |
21 #import "net/base/mac/url_conversions.h" | 21 #import "net/base/mac/url_conversions.h" |
22 | 22 |
| 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 24 #error "This file requires ARC support." |
| 25 #endif |
| 26 |
23 // These tests measure the performance of opening the stack view controller on | 27 // These tests measure the performance of opening the stack view controller on |
24 // an iPhone. On an iPad, the tests do not run, as the iPad does not use the | 28 // an iPhone. On an iPad, the tests do not run, as the iPad does not use the |
25 // stack view controller. | 29 // stack view controller. |
26 | 30 |
27 // Opening the SVC smoothly and quickly is critical to the user experience, and | 31 // Opening the SVC smoothly and quickly is critical to the user experience, and |
28 // any sort of pause or delay is awkward and gives a poor impression. | 32 // any sort of pause or delay is awkward and gives a poor impression. |
29 // The target time of opening SVC is less than 250 ms. In order to target | 33 // The target time of opening SVC is less than 250 ms. In order to target |
30 // optimizations and ensure that improvements actually lower the time, this test | 34 // optimizations and ensure that improvements actually lower the time, this test |
31 // aims to mimic as closely as possible the application experience. | 35 // aims to mimic as closely as possible the application experience. |
32 | 36 |
(...skipping 13 matching lines...) Expand all Loading... |
46 // take a snapshot of the toolbar for the toolbar animation. | 50 // take a snapshot of the toolbar for the toolbar animation. |
47 @interface StackViewControllerPerfTestDelegate | 51 @interface StackViewControllerPerfTestDelegate |
48 : NSObject<TabSwitcherDelegate, StackViewControllerTestDelegate> { | 52 : NSObject<TabSwitcherDelegate, StackViewControllerTestDelegate> { |
49 @private | 53 @private |
50 BOOL showAnimationStarted_; | 54 BOOL showAnimationStarted_; |
51 BOOL showAnimationEnded_; | 55 BOOL showAnimationEnded_; |
52 BOOL dismissAnimationStarted_; | 56 BOOL dismissAnimationStarted_; |
53 BOOL dismissAnimationEnded_; | 57 BOOL dismissAnimationEnded_; |
54 BOOL preloadCardViewsEnded_; | 58 BOOL preloadCardViewsEnded_; |
55 @public | 59 @public |
56 BrowserViewController* bvc_; // weak | 60 __weak BrowserViewController* bvc_; |
57 } | 61 } |
58 | 62 |
59 - (void)reinitialize; | 63 - (void)reinitialize; |
60 | 64 |
61 @property(nonatomic, assign) BOOL showAnimationStarted; | 65 @property(nonatomic, assign) BOOL showAnimationStarted; |
62 @property(nonatomic, assign) BOOL showAnimationEnded; | 66 @property(nonatomic, assign) BOOL showAnimationEnded; |
63 @property(nonatomic, assign) BOOL dismissAnimationStarted; | 67 @property(nonatomic, assign) BOOL dismissAnimationStarted; |
64 @property(nonatomic, assign) BOOL dismissAnimationEnded; | 68 @property(nonatomic, assign) BOOL dismissAnimationEnded; |
65 @property(nonatomic, assign) BOOL preloadCardViewsEnded; | 69 @property(nonatomic, assign) BOOL preloadCardViewsEnded; |
66 | 70 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 if (IsIPadIdiom()) | 163 if (IsIPadIdiom()) |
160 return; | 164 return; |
161 | 165 |
162 // Base class does most of the setup. | 166 // Base class does most of the setup. |
163 PerfTestWithBVC::SetUp(); | 167 PerfTestWithBVC::SetUp(); |
164 | 168 |
165 current_url_index_ = 0; | 169 current_url_index_ = 0; |
166 reuse_svc_ = false; | 170 reuse_svc_ = false; |
167 | 171 |
168 // The testing delegate will receive stack view animation notifications. | 172 // The testing delegate will receive stack view animation notifications. |
169 delegate_.reset([[StackViewControllerPerfTestDelegate alloc] | 173 delegate_ = [[StackViewControllerPerfTestDelegate alloc] |
170 initWithBrowserViewController:bvc_]); | 174 initWithBrowserViewController:bvc_]; |
171 } | 175 } |
172 void TearDown() override { | 176 void TearDown() override { |
173 // Opening a StackViewController is done only on iPhones, not on iPads. | 177 // Opening a StackViewController is done only on iPhones, not on iPads. |
174 // This test is meaningless on an iPad. | 178 // This test is meaningless on an iPad. |
175 if (IsIPadIdiom()) | 179 if (IsIPadIdiom()) |
176 return; | 180 return; |
177 | 181 |
178 PerfTestWithBVC::TearDown(); | 182 PerfTestWithBVC::TearDown(); |
179 } | 183 } |
180 | 184 |
181 protected: | 185 protected: |
182 // Stack view controller & delegate. | 186 // Stack view controller & delegate. |
183 base::scoped_nsobject<StackViewControllerPerfTestDelegate> delegate_; | 187 StackViewControllerPerfTestDelegate* delegate_; |
184 base::scoped_nsobject<StackViewController> view_controller_; | 188 StackViewController* view_controller_; |
185 | 189 |
186 int current_url_index_; | 190 int current_url_index_; |
187 BOOL reuse_svc_; | 191 BOOL reuse_svc_; |
188 | 192 |
189 // Utility function to print out timing information for testing | 193 // Utility function to print out timing information for testing |
190 // with |number_of_tabs| tabs opened. | 194 // with |number_of_tabs| tabs opened. |
191 void PrintTestResult(std::string test_description, | 195 void PrintTestResult(std::string test_description, |
192 int number_of_tabs, | 196 int number_of_tabs, |
193 base::TimeDelta elapsed) { | 197 base::TimeDelta elapsed) { |
194 std::stringstream test_name; | 198 std::stringstream test_name; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 // Note that if the code there changes, this code should change to match. | 283 // Note that if the code there changes, this code should change to match. |
280 Tab* currentTab = [[bvc_ tabModel] currentTab]; | 284 Tab* currentTab = [[bvc_ tabModel] currentTab]; |
281 | 285 |
282 // In order to generate the transition between the current browser view | 286 // In order to generate the transition between the current browser view |
283 // controller and the tab switcher controller it's possible that multiple | 287 // controller and the tab switcher controller it's possible that multiple |
284 // screenshots of the same tab are taken. Since taking a screenshot is | 288 // screenshots of the same tab are taken. Since taking a screenshot is |
285 // expensive we activate snapshot coalescing in the scope of this function | 289 // expensive we activate snapshot coalescing in the scope of this function |
286 // which will cache the first snapshot for the tab and reuse it instead of | 290 // which will cache the first snapshot for the tab and reuse it instead of |
287 // regenerating a new one each time. | 291 // regenerating a new one each time. |
288 [currentTab setSnapshotCoalescingEnabled:YES]; | 292 [currentTab setSnapshotCoalescingEnabled:YES]; |
289 base::ScopedClosureRunner runner(base::BindBlock(^{ | 293 base::ScopedClosureRunner runner(base::BindBlockArc(^{ |
290 [currentTab setSnapshotCoalescingEnabled:NO]; | 294 [currentTab setSnapshotCoalescingEnabled:NO]; |
291 })); | 295 })); |
292 | 296 |
293 if (!view_controller_) { | 297 if (!view_controller_) { |
294 view_controller_.reset([[StackViewController alloc] | 298 view_controller_ = |
295 initWithMainTabModel:tab_model_ | 299 [[StackViewController alloc] initWithMainTabModel:tab_model_ |
296 otrTabModel:otr_tab_model_ | 300 otrTabModel:otr_tab_model_ |
297 activeTabModel:tab_model_]); | 301 activeTabModel:tab_model_]; |
298 } else { | 302 } else { |
299 [view_controller_ restoreInternalStateWithMainTabModel:tab_model_ | 303 [view_controller_ restoreInternalStateWithMainTabModel:tab_model_ |
300 otrTabModel:otr_tab_model_ | 304 otrTabModel:otr_tab_model_ |
301 activeTabModel:tab_model_]; | 305 activeTabModel:tab_model_]; |
302 } | 306 } |
303 [view_controller_ setDelegate:delegate_]; | 307 [view_controller_ setDelegate:delegate_]; |
304 | 308 |
305 // The only addition to the function for testing. | 309 // The only addition to the function for testing. |
306 [view_controller_ setTestDelegate:delegate_]; | 310 [view_controller_ setTestDelegate:delegate_]; |
307 | 311 |
308 [bvc_ presentViewController:view_controller_.get() | 312 [bvc_ presentViewController:view_controller_ |
309 animated:NO | 313 animated:NO |
310 completion:^{ | 314 completion:^{ |
311 [view_controller_ showWithSelectedTabAnimation]; | 315 [view_controller_ showWithSelectedTabAnimation]; |
312 EXPECT_TRUE([delegate_ showAnimationStarted]); | 316 EXPECT_TRUE([delegate_ showAnimationStarted]); |
313 EXPECT_FALSE([delegate_ showAnimationEnded]); | 317 EXPECT_FALSE([delegate_ showAnimationEnded]); |
314 }]; | 318 }]; |
315 } | 319 } |
316 | 320 |
317 base::TimeDelta StackViewControllerPerfTest::CloseStackView() { | 321 base::TimeDelta StackViewControllerPerfTest::CloseStackView() { |
318 base::Time startTime = base::Time::NowFromSystemTime(); | 322 base::Time startTime = base::Time::NowFromSystemTime(); |
319 // Spin and wait for the dismiss stack view animation to finish. | 323 // Spin and wait for the dismiss stack view animation to finish. |
320 base::test::ios::TimeUntilCondition( | 324 base::test::ios::TimeUntilCondition( |
321 ^{ | 325 ^{ |
322 [view_controller_ dismissWithSelectedTabAnimation]; | 326 [view_controller_ dismissWithSelectedTabAnimation]; |
323 EXPECT_TRUE([delegate_ dismissAnimationStarted]); | 327 EXPECT_TRUE([delegate_ dismissAnimationStarted]); |
324 EXPECT_FALSE([delegate_ dismissAnimationEnded]); | 328 EXPECT_FALSE([delegate_ dismissAnimationEnded]); |
325 }, | 329 }, |
326 ^bool() { | 330 ^bool() { |
327 return [delegate_ dismissAnimationEnded]; | 331 return [delegate_ dismissAnimationEnded]; |
328 }, | 332 }, |
329 false, base::TimeDelta::FromSecondsD(kTotalSpinDelay)); | 333 false, base::TimeDelta::FromSecondsD(kTotalSpinDelay)); |
330 | 334 |
331 [view_controller_ dismissViewControllerAnimated:NO completion:nil]; | 335 [view_controller_ dismissViewControllerAnimated:NO completion:nil]; |
332 if (!reuse_svc_) | 336 if (!reuse_svc_) |
333 view_controller_.reset(); | 337 view_controller_ = nil; |
334 | 338 |
335 base::TimeDelta closeTime = base::Time::NowFromSystemTime() - startTime; | 339 base::TimeDelta closeTime = base::Time::NowFromSystemTime() - startTime; |
336 | 340 |
337 // Run the runloop a bit longer to give time for temporary retains that happen | 341 // Run the runloop a bit longer to give time for temporary retains that happen |
338 // in the OS during view teardown to resolve, so that the view gets its | 342 // in the OS during view teardown to resolve, so that the view gets its |
339 // dismissal callbacks. | 343 // dismissal callbacks. |
340 base::test::ios::WaitUntilCondition( | 344 base::test::ios::WaitUntilCondition( |
341 nil, false, base::TimeDelta::FromSecondsD(kSpinDelay)); | 345 nil, false, base::TimeDelta::FromSecondsD(kSpinDelay)); |
342 | 346 |
343 return closeTime; | 347 return closeTime; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 CalculateAverage(close_times + 1, kNumTests - 1, NULL, &max_close); | 401 CalculateAverage(close_times + 1, kNumTests - 1, NULL, &max_close); |
398 LogPerfTiming("Open cold", open_times[0]); | 402 LogPerfTiming("Open cold", open_times[0]); |
399 LogPerfTiming("Open warm avg", open_avg); | 403 LogPerfTiming("Open warm avg", open_avg); |
400 LogPerfTiming("Open warm max", max_open); | 404 LogPerfTiming("Open warm max", max_open); |
401 LogPerfTiming("Close cold", close_times[0]); | 405 LogPerfTiming("Close cold", close_times[0]); |
402 LogPerfTiming("Close cold avg", close_avg); | 406 LogPerfTiming("Close cold avg", close_avg); |
403 LogPerfTiming("Close cold max", max_close); | 407 LogPerfTiming("Close cold max", max_close); |
404 } | 408 } |
405 | 409 |
406 } // anonymous namespace | 410 } // anonymous namespace |
OLD | NEW |