OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/web/shell/test/utils/web_view_egutil.h" | |
6 | |
7 #import <WebKit/WebKit.h> | |
8 | |
9 #import "base/test/ios/wait_util.h" | |
10 #import "ios/web/shell/view_controller.h" | |
11 #include "ios/web/shell/test/utils/eg_util.h" | |
12 | |
13 namespace { | |
14 | |
15 // Constant for UI wait loop in seconds. | |
16 const NSTimeInterval kSpinDelaySeconds = 0.01; | |
17 | |
18 // Constant for timeout in seconds while waiting for web element. | |
19 const NSTimeInterval kWaitForWebElementTimeout = 4.0; | |
20 | |
21 // Script that returns document.body as a string. | |
22 NSString* const kGetDocumentBodyJavaScript = | |
23 @"document.body ? document.body.textContent : null"; | |
24 } | |
25 | |
26 @implementation GREYMatchers (WebShellAdditions) | |
27 | |
28 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { | |
29 MatchesBlock matches = ^BOOL(UIView* view) { | |
30 if (![view isKindOfClass:[WKWebView class]]) { | |
31 return NO; | |
32 } | |
33 | |
34 CRWWebController* webController = earl_grey_util::GetCurrentWebController(); | |
35 DCHECK(webController); | |
36 | |
37 __block id script = nil; | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
This is not |script|...
baxley
2016/04/21 16:09:17
A lot of this logic went away as I switched to Web
| |
38 __block BOOL didSuceed = NO; | |
39 __block BOOL timeout = NO; | |
40 NSDate* deadline = | |
41 [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout]; | |
42 script = ^(NSString* evaluationResult, NSError* error) { | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Please log |error| if any.
baxley
2016/04/21 16:09:17
N/A with new API
| |
43 if (![evaluationResult containsString:text]) { | |
44 if ([[NSDate date] compare:deadline] == NSOrderedDescending) { | |
45 timeout = YES; | |
46 return; | |
47 } | |
48 [webController evaluateJavaScript:kGetDocumentBodyJavaScript | |
49 stringResultHandler:script]; | |
50 } else { | |
51 didSuceed = YES; | |
52 } | |
53 }; | |
54 | |
55 [webController evaluateJavaScript:kGetDocumentBodyJavaScript | |
56 stringResultHandler:script]; | |
57 while (!didSuceed && !timeout) { | |
58 base::test::ios::SpinRunLoopWithMaxDelay( | |
59 base::TimeDelta::FromSecondsD(kSpinDelaySeconds)); | |
60 } | |
61 return didSuceed; | |
62 | |
63 }; | |
64 | |
65 DescribeToBlock describe = ^void(id<GREYDescription> description) { | |
66 [description | |
67 appendText:[NSString stringWithFormat:@"web view containing %@", text]]; | |
68 }; | |
69 | |
70 base::scoped_nsobject<GREYElementMatcherBlock> matcherBlock( | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
base::mac::ScopedBlock
Eugene But (OOO till 7-30)
2016/04/16 02:00:51
Oh, this is not a block... nevermind....
| |
71 [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | |
72 descriptionBlock:describe] retain]); | |
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
Blocks should be copied, not retained.
Eugene But (OOO till 7-30)
2016/04/16 00:38:40
This is a memory leak
Eugene But (OOO till 7-30)
2016/04/16 02:00:51
Ignore this as well :)
EG is so confusing. They u
rohitrao (ping after 24h)
2016/04/18 11:44:25
Isn't this still a leak? Alloc/init will return a
Eugene But (OOO till 7-30)
2016/04/18 15:22:54
"Ignore this as well" was related to copy vs. reta
baxley
2016/04/21 16:09:17
Done.
baxley
2016/04/21 16:09:17
Done.
| |
73 return matcherBlock; | |
74 } | |
75 | |
76 @end | |
77 | |
78 #if !(GREY_DISABLE_SHORTHAND) | |
79 | |
80 id<GREYMatcher> shell_webViewContainingText(NSString* text) { | |
81 return [GREYMatchers matcherForWebViewContainingText:text]; | |
82 } | |
83 | |
84 #endif | |
OLD | NEW |