[macOS] API tests ChangeAttachmentDataUpdatesWithInPlaceDisplay and InPlaceVideoAttac...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jan 2018 05:30:57 +0000 (05:30 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Jan 2018 05:30:57 +0000 (05:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181626

Reviewed by Joseph Pecoraro.

Make the web view for WKAttachmentTests slightly bigger to avoid size clamping behavior introduced in r226915.
Additionally, write a new API test covering the change in r226915.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(webViewForTestingAttachments):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

index d3ba7fd..7865258 100644 (file)
@@ -1,3 +1,17 @@
+2018-01-12  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [macOS] API tests ChangeAttachmentDataUpdatesWithInPlaceDisplay and InPlaceVideoAttachmentInsertionWithinList are failing
+        https://bugs.webkit.org/show_bug.cgi?id=181626
+
+        Reviewed by Joseph Pecoraro.
+
+        Make the web view for WKAttachmentTests slightly bigger to avoid size clamping behavior introduced in r226915.
+        Additionally, write a new API test covering the change in r226915.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (webViewForTestingAttachments):
+        (TestWebKitAPI::TEST):
+
 2018-01-12  Alex Christensen  <achristensen@webkit.org>
 
         History state should be updated during client redirects with asynchronous policy decisions
index a858993..d175639 100644 (file)
@@ -126,18 +126,23 @@ private:
 @interface TestWKWebView (AttachmentTesting)
 @end
 
-static RetainPtr<TestWKWebView> webViewForTestingAttachments()
+static RetainPtr<TestWKWebView> webViewForTestingAttachments(CGSize webViewSize)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [configuration _setAttachmentElementEnabled:YES];
     WKPreferencesSetCustomPasteboardDataEnabled((WKPreferencesRef)[configuration preferences], YES);
 
-    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
-    [webView synchronouslyLoadHTMLString:@"<script>focus = () => document.body.focus()</script><body onload=focus() contenteditable></body>"];
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, webViewSize.width, webViewSize.height) configuration:configuration.get()]);
+    [webView synchronouslyLoadHTMLString:@"<meta name='viewport' content='width=device-width, initial-scale=1'><script>focus = () => document.body.focus()</script><body onload=focus() contenteditable></body>"];
 
     return webView;
 }
 
+static RetainPtr<TestWKWebView> webViewForTestingAttachments()
+{
+    return webViewForTestingAttachments(CGSizeMake(500, 500));
+}
+
 static NSData *testZIPData()
 {
     NSURL *zipFileURL = [[NSBundle mainBundle] URLForResource:@"compressed-files" withExtension:@"zip" subdirectory:@"TestWebKitAPI.resources"];
@@ -666,6 +671,20 @@ TEST(WKAttachmentTests, AttachmentDataForEmptyFile)
     [attachment expectRequestedDataToBe:nil];
 }
 
+TEST(WKAttachmentTests, InsertedImageSizeIsClampedByMaxWidth)
+{
+    auto webView = webViewForTestingAttachments(CGSizeMake(100, 100));
+    RetainPtr<NSData> imageData = testImageData();
+    RetainPtr<_WKAttachment> attachment;
+    {
+        ObserveAttachmentUpdatesForScope observer(webView.get());
+        attachment = [webView synchronouslyInsertAttachmentWithFilename:@"icon.png" contentType:@"image/png" data:imageData.get() options:displayOptionsWithMode(_WKAttachmentDisplayModeInPlace)];
+        [attachment expectRequestedDataToBe:imageData.get()];
+        observer.expectAttachmentUpdates(@[], @[attachment.get()]);
+    }
+    [webView waitForAttachmentElementSizeToBecome:CGSizeMake(84, 67)];
+}
+
 TEST(WKAttachmentTests, MultipleSimultaneousAttachmentDataRequests)
 {
     auto webView = webViewForTestingAttachments();
@@ -1372,7 +1391,7 @@ TEST(WKAttachmentTestsIOS, MoveAttachmentElementAsIconByDragging)
     [webView expectElementTag:@"ATTACHMENT" toComeBefore:@"STRONG"];
 
     auto draggingSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
-    [draggingSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(25, 125)];
+    [draggingSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(25, 425)];
 
     attachment = [[draggingSimulator insertedAttachments] firstObject];
     [attachment expectRequestedDataToBe:data.get()];
@@ -1401,7 +1420,7 @@ TEST(WKAttachmentTestsIOS, MoveInPlaceAttachmentElementByDragging)
     [webView expectElementTag:@"ATTACHMENT" toComeBefore:@"STRONG"];
 
     auto draggingSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
-    [draggingSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(25, 125)];
+    [draggingSimulator runFrom:CGPointMake(25, 25) to:CGPointMake(25, 425)];
 
     attachment = [[draggingSimulator insertedAttachments] firstObject];
     [attachment expectRequestedDataToBe:data.get()];