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