Skip to content

Commit

Permalink
Use a copy of string in EG web_view_matchers
Browse files Browse the repository at this point in the history
This CL fixes webViewMatcher for EG tests by adding a copy of the argument
string before passing it to the handler.
As the handler is asynchronous, this prevents occasional loss of reference.

BUG=none

Review-Url: https://codereview.chromium.org/2183863002
Cr-Commit-Position: refs/heads/master@{#407814}
  • Loading branch information
gambard authored and Commit bot committed Jul 26, 2016
1 parent 5f3be87 commit 8cfdb1e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ios/web/public/test/earl_grey/web_view_matchers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ @implementation GREYMatchers (WebViewAdditions)

+ (id<GREYMatcher>)matcherForWebViewContainingText:(const std::string&)text
inWebState:(web::WebState*)webState {
std::string textCopyForBlock = text;
MatchesBlock matches = ^BOOL(UIView* view) {
if (![view isKindOfClass:[WKWebView class]]) {
return NO;
Expand All @@ -57,7 +58,7 @@ @implementation GREYMatchers (WebViewAdditions)
std::string response;
if (value && value->IsType(base::Value::TYPE_STRING) &&
value->GetAsString(&response)) {
didSucceed = response.find(text) != std::string::npos;
didSucceed = response.find(textCopyForBlock) != std::string::npos;
}
}));
base::test::ios::SpinRunLoopWithMaxDelay(
Expand All @@ -68,7 +69,7 @@ @implementation GREYMatchers (WebViewAdditions)

DescribeToBlock describe = ^(id<GREYDescription> description) {
[description appendText:@"web view containing "];
[description appendText:base::SysUTF8ToNSString(text)];
[description appendText:base::SysUTF8ToNSString(textCopyForBlock)];
};

return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
Expand Down

0 comments on commit 8cfdb1e

Please sign in to comment.