| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/translate/ios/browser/js_translate_manager.h" | 5 #import "components/translate/ios/browser/js_translate_manager.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "grit/components_resources.h" | 9 #include "grit/components_resources.h" |
| 10 #import "ios/web/public/test/fakes/crw_test_js_injection_receiver.h" | 10 #import "ios/web/public/test/fakes/crw_test_js_injection_receiver.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 bool IsDefined(NSString* name) { | 40 bool IsDefined(NSString* name) { |
| 41 NSString* script = | 41 NSString* script = |
| 42 [NSString stringWithFormat:@"typeof %@ != 'undefined'", name]; | 42 [NSString stringWithFormat:@"typeof %@ != 'undefined'", name]; |
| 43 return [web::ExecuteJavaScript(receiver_, script) boolValue]; | 43 return [web::ExecuteJavaScript(receiver_, script) boolValue]; |
| 44 } | 44 } |
| 45 | 45 |
| 46 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; | 46 base::scoped_nsobject<CRWTestJSInjectionReceiver> receiver_; |
| 47 base::scoped_nsobject<JsTranslateManager> manager_; | 47 base::scoped_nsobject<JsTranslateManager> manager_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 TEST_F(JsTranslateManagerTest, PerformancePlaceholder) { | 50 // TODO(crbug.com/658619#c47): Test reported as flaky. |
| 51 TEST_F(JsTranslateManagerTest, DISABLED_PerformancePlaceholder) { |
| 51 [manager_ inject]; | 52 [manager_ inject]; |
| 52 EXPECT_TRUE(IsDefined(@"performance")); | 53 EXPECT_TRUE(IsDefined(@"performance")); |
| 53 EXPECT_TRUE(IsDefined(@"performance.now")); | 54 EXPECT_TRUE(IsDefined(@"performance.now")); |
| 54 | 55 |
| 55 // Check that performance.now returns correct values. | 56 // Check that performance.now returns correct values. |
| 56 NSTimeInterval intervalInSeconds = 0.3; | 57 NSTimeInterval intervalInSeconds = 0.3; |
| 57 double startTime = [manager_ performanceNow]; | 58 double startTime = [manager_ performanceNow]; |
| 58 [NSThread sleepForTimeInterval:intervalInSeconds]; | 59 [NSThread sleepForTimeInterval:intervalInSeconds]; |
| 59 double endTime = [manager_ performanceNow]; | 60 double endTime = [manager_ performanceNow]; |
| 60 double timeElapsed = endTime - startTime; | 61 double timeElapsed = endTime - startTime; |
| 61 // The tolerance is high to avoid flake. | 62 // The tolerance is high to avoid flake. |
| 62 EXPECT_NEAR(timeElapsed, intervalInSeconds * 1000, 100); | 63 EXPECT_NEAR(timeElapsed, intervalInSeconds * 1000, 100); |
| 63 } | 64 } |
| 64 | 65 |
| 65 TEST_F(JsTranslateManagerTest, Inject) { | 66 TEST_F(JsTranslateManagerTest, Inject) { |
| 66 [manager_ inject]; | 67 [manager_ inject]; |
| 67 EXPECT_TRUE([manager_ hasBeenInjected]); | 68 EXPECT_TRUE([manager_ hasBeenInjected]); |
| 68 EXPECT_EQ(nil, [manager_ script]); | 69 EXPECT_EQ(nil, [manager_ script]); |
| 69 EXPECT_NSEQ(@NO, | 70 EXPECT_NSEQ(@NO, |
| 70 web::ExecuteJavaScript(manager_, @"cr.googleTranslate.libReady")); | 71 web::ExecuteJavaScript(manager_, @"cr.googleTranslate.libReady")); |
| 71 } | 72 } |
| OLD | NEW |