|
34 | 34 |
|
35 | 35 | #if WK_API_ENABLED
|
36 | 36 |
|
37 |
| -CGSize platformAttachmentIconElementSize() |
38 |
| -{ |
39 |
| -#if PLATFORM(IOS) |
40 |
| - return CGSizeMake(160, 119); |
41 |
| -#else |
42 |
| - return CGSizeMake(61, 89); |
43 |
| -#endif |
44 |
| -} |
45 |
| - |
46 | 37 | @interface AttachmentUpdateObserver : NSObject <WKUIDelegatePrivate>
|
47 | 38 | @property (nonatomic, readonly) NSArray *inserted;
|
48 | 39 | @property (nonatomic, readonly) NSArray *removed;
|
@@ -192,18 +183,22 @@ - (_WKAttachment *)synchronouslyInsertAttachmentWithFilename:(NSString *)filenam
|
192 | 183 | return attachment.autorelease();
|
193 | 184 | }
|
194 | 185 |
|
| 186 | +- (CGSize)attachmentElementSize |
| 187 | +{ |
| 188 | + __block CGSize size; |
| 189 | + __block bool doneEvaluatingScript = false; |
| 190 | + [self evaluateJavaScript:@"r = document.querySelector('attachment').getBoundingClientRect(); [r.width, r.height]" completionHandler:^(NSArray<NSNumber *> *sizeResult, NSError *) { |
| 191 | + size = CGSizeMake(sizeResult.firstObject.floatValue, sizeResult.lastObject.floatValue); |
| 192 | + doneEvaluatingScript = true; |
| 193 | + }]; |
| 194 | + TestWebKitAPI::Util::run(&doneEvaluatingScript); |
| 195 | + return size; |
| 196 | +} |
| 197 | + |
195 | 198 | - (void)waitForAttachmentElementSizeToBecome:(CGSize)expectedSize
|
196 | 199 | {
|
197 | 200 | while ([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantPast]]) {
|
198 |
| - __block bool doneEvaluatingScript = false; |
199 |
| - __block BOOL sizeIsEqual = NO; |
200 |
| - [self evaluateJavaScript:@"r = document.querySelector('attachment').getBoundingClientRect(); [r.width, r.height]" completionHandler:^(NSArray<NSNumber *> *sizeResult, NSError *) { |
201 |
| - CGSize observedSize { sizeResult.firstObject.floatValue, sizeResult.lastObject.floatValue }; |
202 |
| - sizeIsEqual = CGSizeEqualToSize(expectedSize, observedSize); |
203 |
| - doneEvaluatingScript = true; |
204 |
| - }]; |
205 |
| - TestWebKitAPI::Util::run(&doneEvaluatingScript); |
206 |
| - if (sizeIsEqual) |
| 201 | + if (CGSizeEqualToSize(self.attachmentElementSize, expectedSize)) |
207 | 202 | break;
|
208 | 203 | }
|
209 | 204 | }
|
@@ -499,15 +494,19 @@ - (void)expectRequestedDataToBe:(NSData *)expectedData
|
499 | 494 | RetainPtr<_WKAttachment> attachment;
|
500 | 495 | {
|
501 | 496 | ObserveAttachmentUpdatesForScope observer(webView.get());
|
502 |
| - attachment = retainPtr([webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)]); |
503 |
| - observer.expectAttachmentUpdates(@[], @[attachment.get()]); |
| 497 | + attachment = retainPtr([webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon)]); |
504 | 498 | [attachment expectRequestedDataToBe:imageData.get()];
|
505 |
| - [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)]; |
| 499 | + observer.expectAttachmentUpdates(@[], @[attachment.get()]); |
506 | 500 | }
|
| 501 | + CGSize iconAttachmentSize = [webView attachmentElementSize]; |
| 502 | + |
| 503 | + [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace) error:nil]; |
| 504 | + [attachment expectRequestedDataToBe:imageData.get()]; |
| 505 | + [webView waitForAttachmentElementSizeToBecome:CGSizeMake(215, 174)]; |
507 | 506 |
|
508 | 507 | [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeAsIcon) error:nil];
|
509 | 508 | [attachment expectRequestedDataToBe:imageData.get()];
|
510 |
| - [webView waitForAttachmentElementSizeToBecome:platformAttachmentIconElementSize()]; |
| 509 | + [webView waitForAttachmentElementSizeToBecome:iconAttachmentSize]; |
511 | 510 |
|
512 | 511 | [attachment synchronouslySetDisplayOptions:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace) error:nil];
|
513 | 512 | [attachment expectRequestedDataToBe:imageData.get()];
|
|
0 commit comments