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