Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: ios/web/public/test/earl_grey/web_view_matchers.mm

Issue 1950323002: Refactor web shell integration tests utilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean up import/include Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/web/shell/test/web_view_matchers.h" 5 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/ios/wait_util.h" 12 #include "base/test/ios/wait_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "ios/web/public/web_state/web_state.h"
15 #include "ios/web/shell/test/navigation_test_util.h"
16 #include "ios/web/shell/test/web_shell_test_util.h"
17 14
18 namespace { 15 namespace {
19 16
20 // Constant for UI wait loop in seconds. 17 // Constant for UI wait loop in seconds.
21 const NSTimeInterval kSpinDelaySeconds = 0.01; 18 const NSTimeInterval kSpinDelaySeconds = 0.01;
22 19
23 // Constant for timeout in seconds while waiting for web element. 20 // Constant for timeout in seconds while waiting for web element.
24 const NSTimeInterval kWaitForWebElementTimeout = 4.0; 21 const NSTimeInterval kWaitForWebElementTimeout = 4.0;
25 22
26 // Script that returns document.body as a string. 23 // Script that returns document.body as a string.
27 char kGetDocumentBodyJavaScript[] = 24 char kGetDocumentBodyJavaScript[] =
28 "document.body ? document.body.textContent : null"; 25 "document.body ? document.body.textContent : null";
29 } 26 }
30 27
31 namespace web { 28 namespace web {
32 29
33 id<GREYMatcher> webViewContainingText(NSString* text) { 30 id<GREYMatcher> webViewContainingText(NSString* text, web::WebState* webState) {
34 return [GREYMatchers matcherForWebViewContainingText:text]; 31 return
32 [GREYMatchers matcherForWebViewContainingText:text inWebState:webState];
35 } 33 }
36 34
37 } // namespace web 35 } // namespace web
38 36
39 @implementation GREYMatchers (WebViewAdditions) 37 @implementation GREYMatchers (WebViewAdditions)
40 38
41 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { 39 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text
40 inWebState:(web::WebState*)webState {
42 MatchesBlock matches = ^BOOL(UIView* view) { 41 MatchesBlock matches = ^BOOL(UIView* view) {
43 if (![view isKindOfClass:[WKWebView class]]) { 42 if (![view isKindOfClass:[WKWebView class]]) {
44 return NO; 43 return NO;
45 } 44 }
46 45
47 ViewController* viewController =
48 web::web_shell_test_util::GetCurrentViewController();
49 web::WebState* webState = [viewController webState];
50
51 __block BOOL didSucceed = NO; 46 __block BOOL didSucceed = NO;
52 NSDate* deadline = 47 NSDate* deadline =
53 [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout]; 48 [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout];
54 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && 49 while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
55 !didSucceed) { 50 !didSucceed) {
56 webState->ExecuteJavaScript( 51 webState->ExecuteJavaScript(
57 base::UTF8ToUTF16(kGetDocumentBodyJavaScript), 52 base::UTF8ToUTF16(kGetDocumentBodyJavaScript),
58 base::BindBlock(^(const base::Value* value) { 53 base::BindBlock(^(const base::Value* value) {
59 std::string response; 54 std::string response;
60 if (value && value->IsType(base::Value::TYPE_STRING) && 55 if (value && value->IsType(base::Value::TYPE_STRING) &&
(...skipping 11 matching lines...) Expand all
72 DescribeToBlock describe = ^(id<GREYDescription> description) { 67 DescribeToBlock describe = ^(id<GREYDescription> description) {
73 [description 68 [description
74 appendText:[NSString stringWithFormat:@"web view containing %@", text]]; 69 appendText:[NSString stringWithFormat:@"web view containing %@", text]];
75 }; 70 };
76 71
77 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 72 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
78 descriptionBlock:describe] 73 descriptionBlock:describe]
79 autorelease]; 74 autorelease];
80 } 75 }
81 76
82 @end 77 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698