OLD | NEW |
---|---|
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/public/test/earl_grey/web_view_matchers.h" | 5 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import <WebKit/WebKit.h> | 9 #import <WebKit/WebKit.h> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 [description appendText:base::SysUTF8ToNSString(text)]; | 95 [description appendText:base::SysUTF8ToNSString(text)]; |
96 }; | 96 }; |
97 | 97 |
98 return grey_allOf(webViewInWebState(web_state), | 98 return grey_allOf(webViewInWebState(web_state), |
99 [[[GREYElementMatcherBlock alloc] | 99 [[[GREYElementMatcherBlock alloc] |
100 initWithMatchesBlock:matches | 100 initWithMatchesBlock:matches |
101 descriptionBlock:describe] autorelease], | 101 descriptionBlock:describe] autorelease], |
102 nil); | 102 nil); |
103 } | 103 } |
104 | 104 |
105 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.
| |
106 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?
| |
107 WebState* web_state) { | |
108 MatchesBlock matches = ^BOOL(WKWebView*) { | |
109 __block BOOL did_succeed = NO; | |
110 NSDate* deadline = | |
111 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; | |
112 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && | |
113 !did_succeed) { | |
114 NSString* const kGetElementAttributesScript = [NSString | |
115 stringWithFormat:@"var image = document.getElementById('%@');" | |
116 @"var imageHeight = image.height;" | |
117 @"var imageWidth = image.width;" | |
118 @"JSON.stringify({" | |
119 @" height:imageHeight," | |
120 @" width:imageWidth" | |
121 @"});", | |
122 base::SysUTF8ToNSString(image_id)]; | |
123 std::unique_ptr<base::Value> value = ExecuteScript( | |
124 web_state, base::SysNSStringToUTF8(kGetElementAttributesScript)); | |
125 std::string result; | |
126 if (value && value->GetAsString(&result)) { | |
127 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.
| |
128 NSData* imageAttributesAsData = | |
129 [evaluationResult dataUsingEncoding:NSUTF8StringEncoding]; | |
130 NSDictionary* imageAttributes = | |
131 [NSJSONSerialization JSONObjectWithData:imageAttributesAsData | |
132 options:0 | |
133 error:nil]; | |
134 CGFloat height = [imageAttributes[@"height"] floatValue]; | |
135 CGFloat width = [imageAttributes[@"width"] floatValue]; | |
136 did_succeed = | |
137 (height < expected_size.height && width < expected_size.width); | |
138 } | |
139 base::test::ios::SpinRunLoopWithMaxDelay( | |
140 base::TimeDelta::FromSecondsD(testing::kSpinDelaySeconds)); | |
141 } | |
142 return did_succeed; | |
143 }; | |
144 | |
145 DescribeToBlock describe = ^(id<GREYDescription> description) { | |
146 [description appendText:@"web view blocking resource with id "]; | |
147 [description appendText:base::SysUTF8ToNSString(image_id)]; | |
148 }; | |
149 | |
150 return grey_allOf(webViewInWebState(web_state), | |
151 [[[GREYElementMatcherBlock alloc] | |
152 initWithMatchesBlock:matches | |
153 descriptionBlock:describe] autorelease], | |
154 nil); | |
155 } | |
156 | |
105 id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) { | 157 id<GREYMatcher> webViewCssSelector(std::string selector, WebState* web_state) { |
106 MatchesBlock matches = ^BOOL(WKWebView*) { | 158 MatchesBlock matches = ^BOOL(WKWebView*) { |
107 std::string script = base::StringPrintf(kTestCssSelectorJavaScriptTemplate, | 159 std::string script = base::StringPrintf(kTestCssSelectorJavaScriptTemplate, |
108 selector.c_str()); | 160 selector.c_str()); |
109 __block bool did_succeed = false; | 161 __block bool did_succeed = false; |
110 NSDate* deadline = | 162 NSDate* deadline = |
111 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; | 163 [NSDate dateWithTimeIntervalSinceNow:testing::kWaitForUIElementTimeout]; |
112 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && | 164 while (([[NSDate date] compare:deadline] != NSOrderedDescending) && |
113 !did_succeed) { | 165 !did_succeed) { |
114 std::unique_ptr<base::Value> value = ExecuteScript(web_state, script); | 166 std::unique_ptr<base::Value> value = ExecuteScript(web_state, script); |
(...skipping 27 matching lines...) Expand all Loading... | |
142 DescribeToBlock describe = ^(id<GREYDescription> description) { | 194 DescribeToBlock describe = ^(id<GREYDescription> description) { |
143 [description appendText:@"web view scroll view"]; | 195 [description appendText:@"web view scroll view"]; |
144 }; | 196 }; |
145 | 197 |
146 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches | 198 return [[[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches |
147 descriptionBlock:describe] | 199 descriptionBlock:describe] |
148 autorelease]; | 200 autorelease]; |
149 } | 201 } |
150 | 202 |
151 } // namespace web | 203 } // namespace web |
OLD | NEW |