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

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: alphabetize 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/test/navigation_test_util.h"
14 #include "ios/web/public/web_state/web_state.h" 15 #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 16
18 namespace { 17 namespace {
19 18
20 // Constant for UI wait loop in seconds. 19 // Constant for UI wait loop in seconds.
21 const NSTimeInterval kSpinDelaySeconds = 0.01; 20 const NSTimeInterval kSpinDelaySeconds = 0.01;
22 21
23 // Constant for timeout in seconds while waiting for web element. 22 // Constant for timeout in seconds while waiting for web element.
24 const NSTimeInterval kWaitForWebElementTimeout = 4.0; 23 const NSTimeInterval kWaitForWebElementTimeout = 4.0;
25 24
26 // Script that returns document.body as a string. 25 // Script that returns document.body as a string.
27 char kGetDocumentBodyJavaScript[] = 26 char kGetDocumentBodyJavaScript[] =
28 "document.body ? document.body.textContent : null"; 27 "document.body ? document.body.textContent : null";
29 } 28 }
30 29
31 namespace web { 30 namespace web {
32 31
33 id<GREYMatcher> webViewContainingText(NSString* text) { 32 id<GREYMatcher> webViewContainingText(NSString* text, web::WebState* webState) {
34 return [GREYMatchers matcherForWebViewContainingText:text]; 33 return
34 [GREYMatchers matcherForWebViewContainingText:text inWebState:webState];
35 } 35 }
36 36
37 } // namespace web 37 } // namespace web
38 38
39 @implementation GREYMatchers (WebViewAdditions) 39 @implementation GREYMatchers (WebViewAdditions)
40 40
41 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text { 41 + (id<GREYMatcher>)matcherForWebViewContainingText:(NSString*)text
42 inWebState:(web::WebState*)webState {
42 MatchesBlock matches = ^BOOL(UIView* view) { 43 MatchesBlock matches = ^BOOL(UIView* view) {
43 if (![view isKindOfClass:[WKWebView class]]) { 44 if (![view isKindOfClass:[WKWebView class]]) {
44 return NO; 45 return NO;
45 } 46 }
46 47
Eugene But (OOO till 7-30) 2016/05/05 18:01:11 Check that |view| is descendant of |webState->GetV
baxley 2016/05/05 21:13:53 Done.
47 ViewController* viewController =
48 web::web_shell_test_util::GetCurrentViewController();
49 web::WebState* webState = [viewController webState];
50
51 __block BOOL didSucceed = NO; 48 __block BOOL didSucceed = NO;
52 NSDate* deadline = 49 NSDate* deadline =
53 [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout]; 50 [NSDate dateWithTimeIntervalSinceNow:kWaitForWebElementTimeout];
54 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && 51 while (([[NSDate date] compare:deadline] != NSOrderedDescending) &&
55 !didSucceed) { 52 !didSucceed) {
56 webState->ExecuteJavaScript( 53 webState->ExecuteJavaScript(
57 base::UTF8ToUTF16(kGetDocumentBodyJavaScript), 54 base::UTF8ToUTF16(kGetDocumentBodyJavaScript),
58 base::BindBlock(^(const base::Value* value) { 55 base::BindBlock(^(const base::Value* value) {
59 std::string response; 56 std::string response;
60 if (value && value->IsType(base::Value::TYPE_STRING) && 57 if (value && value->IsType(base::Value::TYPE_STRING) &&
(...skipping 11 matching lines...) Expand all
72 DescribeToBlock describe = ^(id<GREYDescription> description) { 69 DescribeToBlock describe = ^(id<GREYDescription> description) {
73 [description 70 [description
74 appendText:[NSString stringWithFormat:@"web view containing %@", text]]; 71 appendText:[NSString stringWithFormat:@"web view containing %@", text]];
75 }; 72 };
76 73
77 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches 74 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
78 descriptionBlock:describe] 75 descriptionBlock:describe]
79 autorelease]; 76 autorelease];
80 } 77 }
81 78
82 @end 79 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698