Chromium Code Reviews| Index: ios/web/public/test/earl_grey/web_view_matchers.mm |
| diff --git a/ios/web/public/test/earl_grey/web_view_matchers.mm b/ios/web/public/test/earl_grey/web_view_matchers.mm |
| index d89d836c220bff09ce5cfd64596e83e23df2c83d..b6c4ac19251ff1b9e03e912b4ef26dd29f8d7a4d 100644 |
| --- a/ios/web/public/test/earl_grey/web_view_matchers.mm |
| +++ b/ios/web/public/test/earl_grey/web_view_matchers.mm |
| @@ -102,6 +102,58 @@ id<GREYMatcher> webViewContainingText(std::string text, WebState* web_state) { |
| nil); |
| } |
| +id<GREYMatcher> webViewContainingBlockedImage(std::string image_id, |
|
Eugene But (OOO till 7-30)
2016/08/24 14:39:27
Now I think I understand why you require size to p
justincohen
2016/08/24 20:47:52
Acknowledged.
|
| + CGSize expected_size, |
|
Eugene But (OOO till 7-30)
2016/08/24 14:32:45
Is there a reason why you can non download image i
justincohen
2016/08/24 20:47:51
Since no one else uses this?
|
| + WebState* web_state) { |
| + MatchesBlock matches = ^BOOL(WKWebView*) { |
| + __block BOOL did_succeed = NO; |
| + NSDate* deadline = |
| + [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
| + while (([[NSDate date] compare:deadline] != NSOrderedDescending) && |
| + !did_succeed) { |
| + NSString* const kGetElementAttributesScript = [NSString |
| + stringWithFormat:@"var image = document.getElementById('%@');" |
| + @"var imageHeight = image.height;" |
| + @"var imageWidth = image.width;" |
| + @"JSON.stringify({" |
| + @" height:imageHeight," |
| + @" width:imageWidth" |
| + @"});", |
| + base::SysUTF8ToNSString(image_id)]; |
| + std::unique_ptr<base::Value> value = ExecuteScript( |
| + web_state, base::SysNSStringToUTF8(kGetElementAttributesScript)); |
| + std::string result; |
| + if (value && value->GetAsString(&result)) { |
| + NSString* evaluationResult = base::SysUTF8ToNSString(result); |
|
Eugene But (OOO till 7-30)
2016/08/24 14:32:45
s/evaluationResult/evaluation_result since it's C
justincohen
2016/08/24 20:47:52
Done.
|
| + NSData* imageAttributesAsData = |
| + [evaluationResult dataUsingEncoding:NSUTF8StringEncoding]; |
| + NSDictionary* imageAttributes = |
| + [NSJSONSerialization JSONObjectWithData:imageAttributesAsData |
| + options:0 |
| + error:nil]; |
| + CGFloat height = [imageAttributes[@"height"] floatValue]; |
| + CGFloat width = [imageAttributes[@"width"] floatValue]; |
| + did_succeed = |
| + (height < expected_size.height && width < expected_size.width); |
| + } |
| + base::test::ios::SpinRunLoopWithMaxDelay( |
| + base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); |
| + } |
| + return did_succeed; |
| + }; |
| + |
| + DescribeToBlock describe = ^(id<GREYDescription> description) { |
| + [description appendText:@"web view blocking resource with id "]; |
| + [description appendText:base::SysUTF8ToNSString(image_id)]; |
| + }; |
| + |
| + return grey_allOf(webViewInWebState(web_state), |
| + [[[GREYElementMatcherBlock alloc] |
| + initWithMatchesBlock:matches |
| + descriptionBlock:describe] autorelease], |
| + nil); |
| +} |
| + |
| id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) { |
| MatchesBlock matches = ^BOOL(WKWebView*) { |
| std::string script = base::StringPrintf(kTestCssSelectorJavaScriptTemplate, |