OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 5 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
9 | 9 |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #import "ios/chrome/test/app/chrome_test_util.h" | 11 #import "ios/chrome/test/app/chrome_test_util.h" |
12 #import "ios/chrome/test/app/history_test_util.h" | 12 #import "ios/chrome/test/app/history_test_util.h" |
13 #include "ios/chrome/test/app/navigation_test_util.h" | 13 #include "ios/chrome/test/app/navigation_test_util.h" |
14 #import "ios/testing/wait_util.h" | 14 #import "ios/testing/wait_util.h" |
15 #import "ios/web/public/test/earl_grey/js_test_util.h" | 15 #import "ios/web/public/test/earl_grey/js_test_util.h" |
16 #import "ios/web/public/test/web_view_interaction_test_util.h" | 16 #import "ios/web/public/test/web_view_interaction_test_util.h" |
17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
18 #import "ios/web/public/web_state/web_state.h" | 18 #import "ios/web/public/web_state/web_state.h" |
19 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
20 namespace chrome_test_util { | 24 namespace chrome_test_util { |
21 | 25 |
22 id ExecuteJavaScript(NSString* javascript, NSError** out_error) { | 26 id ExecuteJavaScript(NSString* javascript, |
| 27 NSError* __unsafe_unretained* out_error) { |
23 __block bool did_complete = false; | 28 __block bool did_complete = false; |
24 __block id result = nil; | 29 __block id result = nil; |
25 __block NSError* temp_error = nil; | 30 __block NSError* temp_error = nil; |
26 CRWJSInjectionReceiver* evaluator = | 31 CRWJSInjectionReceiver* evaluator = |
27 chrome_test_util::GetCurrentWebState()->GetJSInjectionReceiver(); | 32 chrome_test_util::GetCurrentWebState()->GetJSInjectionReceiver(); |
28 [evaluator executeJavaScript:javascript | 33 [evaluator executeJavaScript:javascript |
29 completionHandler:^(id value, NSError* error) { | 34 completionHandler:^(id value, NSError* error) { |
30 did_complete = true; | 35 did_complete = true; |
31 result = [value copy]; | 36 result = [value copy]; |
32 temp_error = [error copy]; | 37 temp_error = [error copy]; |
33 }]; | 38 }]; |
34 | 39 |
35 // Wait for completion. | 40 // Wait for completion. |
36 GREYCondition* condition = [GREYCondition | 41 GREYCondition* condition = [GREYCondition |
37 conditionWithName:@"Wait for JavaScript execution to complete." | 42 conditionWithName:@"Wait for JavaScript execution to complete." |
38 block:^BOOL { | 43 block:^BOOL { |
39 return did_complete; | 44 return did_complete; |
40 }]; | 45 }]; |
41 [condition waitWithTimeout:testing::kWaitForJSCompletionTimeout]; | 46 [condition waitWithTimeout:testing::kWaitForJSCompletionTimeout]; |
42 if (!did_complete) | 47 if (!did_complete) |
43 return nil; | 48 return nil; |
44 [temp_error autorelease]; | 49 if (out_error) { |
45 if (out_error) | 50 NSError* __autoreleasing auto_released_error = temp_error; |
46 *out_error = temp_error; | 51 *out_error = auto_released_error; |
47 return [result autorelease]; | 52 } |
| 53 return result; |
48 } | 54 } |
49 | 55 |
50 } // namespace chrome_test_util | 56 } // namespace chrome_test_util |
51 | 57 |
52 @implementation ChromeEarlGrey | 58 @implementation ChromeEarlGrey |
53 | 59 |
54 #pragma mark - History Utilities | 60 #pragma mark - History Utilities |
55 | 61 |
56 + (void)clearBrowsingHistory { | 62 + (void)clearBrowsingHistory { |
57 chrome_test_util::ClearBrowsingHistory(); | 63 chrome_test_util::ClearBrowsingHistory(); |
(...skipping 27 matching lines...) Expand all Loading... |
85 | 91 |
86 + (void)tapWebViewElementWithID:(NSString*)elementID { | 92 + (void)tapWebViewElementWithID:(NSString*)elementID { |
87 BOOL success = | 93 BOOL success = |
88 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), | 94 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), |
89 base::SysNSStringToUTF8(elementID)); | 95 base::SysNSStringToUTF8(elementID)); |
90 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", | 96 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", |
91 elementID); | 97 elementID); |
92 } | 98 } |
93 | 99 |
94 @end | 100 @end |
OLD | NEW |