OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/mac/bundle_locations.h" | 5 #include "base/mac/bundle_locations.h" |
6 #include "base/mac/scoped_nsobject.h" | |
7 #include "base/timer/elapsed_timer.h" | 6 #include "base/timer/elapsed_timer.h" |
8 #include "ios/chrome/test/base/perf_test_ios.h" | 7 #include "ios/chrome/test/base/perf_test_ios.h" |
9 #include "ios/web/public/test/fakes/test_browser_state.h" | 8 #include "ios/web/public/test/fakes/test_browser_state.h" |
10 #import "ios/web/public/test/js_test_util.h" | 9 #import "ios/web/public/test/js_test_util.h" |
11 #import "ios/web/public/web_view_creation_util.h" | 10 #import "ios/web/public/web_view_creation_util.h" |
12 #import "ios/web/web_state/js/page_script_util.h" | 11 #import "ios/web/web_state/js/page_script_util.h" |
13 | 12 |
14 #import <Foundation/Foundation.h> | 13 #import <Foundation/Foundation.h> |
15 #import <WebKit/WebKit.h> | 14 #import <WebKit/WebKit.h> |
16 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 // Class for testing early page script injection into WKWebView. | 22 // Class for testing early page script injection into WKWebView. |
20 // TODO(crbug.com/583218): improve this test to use WKUserScript injections. | 23 // TODO(crbug.com/583218): improve this test to use WKUserScript injections. |
21 class EarlyPageScriptPerfTest : public PerfTest { | 24 class EarlyPageScriptPerfTest : public PerfTest { |
22 protected: | 25 protected: |
23 EarlyPageScriptPerfTest() : PerfTest("Early Page Script for WKWebView") { | 26 EarlyPageScriptPerfTest() : PerfTest("Early Page Script for WKWebView") { |
24 web_view_.reset([web::BuildWKWebView(CGRectZero, &browser_state_) retain]); | 27 web_view_ = web::BuildWKWebView(CGRectZero, &browser_state_); |
25 } | 28 } |
26 | 29 |
27 // Injects early script into WKWebView. | 30 // Injects early script into WKWebView. |
28 void InjectEarlyScript() { | 31 void InjectEarlyScript() { |
29 web::ExecuteJavaScript(web_view_, web::GetEarlyPageScript(&browser_state_)); | 32 web::ExecuteJavaScript(web_view_, web::GetEarlyPageScript(&browser_state_)); |
30 } | 33 } |
31 | 34 |
32 // BrowserState required for web view creation. | 35 // BrowserState required for web view creation. |
33 web::TestBrowserState browser_state_; | 36 web::TestBrowserState browser_state_; |
34 // WKWebView to test scripts injections. | 37 // WKWebView to test scripts injections. |
35 base::scoped_nsobject<WKWebView> web_view_; | 38 WKWebView* web_view_; |
36 }; | 39 }; |
37 | 40 |
38 // Tests script loading time. | 41 // Tests script loading time. |
39 TEST_F(EarlyPageScriptPerfTest, ScriptLoading) { | 42 TEST_F(EarlyPageScriptPerfTest, ScriptLoading) { |
40 RepeatTimedRuns("Loading", | 43 RepeatTimedRuns("Loading", |
41 ^base::TimeDelta(int) { | 44 ^base::TimeDelta(int) { |
42 base::ElapsedTimer timer; | 45 base::ElapsedTimer timer; |
43 web::GetEarlyPageScript(&browser_state_); | 46 web::GetEarlyPageScript(&browser_state_); |
44 return timer.Elapsed(); | 47 return timer.Elapsed(); |
45 }, | 48 }, |
46 nil); | 49 nil); |
47 } | 50 } |
48 | 51 |
49 // Tests injection time into a bare web view. | 52 // Tests injection time into a bare web view. |
50 TEST_F(EarlyPageScriptPerfTest, BareWebViewInjection) { | 53 TEST_F(EarlyPageScriptPerfTest, BareWebViewInjection) { |
51 RepeatTimedRuns("Bare web view injection", | 54 RepeatTimedRuns("Bare web view injection", |
52 ^base::TimeDelta(int) { | 55 ^base::TimeDelta(int) { |
53 base::ElapsedTimer timer; | 56 base::ElapsedTimer timer; |
54 InjectEarlyScript(); | 57 InjectEarlyScript(); |
55 return timer.Elapsed(); | 58 return timer.Elapsed(); |
56 }, | 59 }, |
57 nil); | 60 nil); |
58 } | 61 } |
59 | 62 |
60 } // namespace | 63 } // namespace |
OLD | NEW |