Skip to content
Permalink
Browse files
Several PasteImage API tests are flaky
https://bugs.webkit.org/show_bug.cgi?id=195160

Reviewed by Tim Horton.

Some of these tests, such as PasteTIFFImage, don't wait for the inserted image element to finish loading before
querying the image element's size; a few other tests, such as PastePNGFile, are racy since they may begin
listening for a "load" event after image load is already complete.

To address this, make these tests first register a "load" event handler, then run script to insert an image
element into the document, and finally wait until the load event is observed before checking image size.

* TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm:


Canonical link: https://commits.webkit.org/209505@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242216 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
whsieh committed Feb 28, 2019
1 parent de35d5f commit 506b32050ace740c847b1224a0e07cb92d39476e
Showing 2 changed files with 22 additions and 10 deletions.
@@ -1,3 +1,19 @@
2019-02-28 Wenson Hsieh <wenson_hsieh@apple.com>

Several PasteImage API tests are flaky
https://bugs.webkit.org/show_bug.cgi?id=195160

Reviewed by Tim Horton.

Some of these tests, such as PasteTIFFImage, don't wait for the inserted image element to finish loading before
querying the image element's size; a few other tests, such as PastePNGFile, are racy since they may begin
listening for a "load" event after image load is already complete.

To address this, make these tests first register a "load" event handler, then run script to insert an image
element into the document, and finally wait until the load event is observed before checking image size.

* TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm:

2019-02-28 Chris Dumez <cdumez@apple.com>

Flaky API Test: TestWebKitAPI.ProcessSwap.PageZoomLevelAfterSwap
@@ -160,8 +160,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("sunset-in-cupertino-400px.gif", [webView stringByEvaluatingJavaScript:@"file.name"]);
EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(file)"];
[webView waitForMessage:@"loaded"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("400", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}
@@ -182,8 +181,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("sunset-in-cupertino-600px.jpg", [webView stringByEvaluatingJavaScript:@"file.name"]);
EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(file)"];
[webView waitForMessage:@"loaded"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("600", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}
@@ -204,8 +202,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("sunset-in-cupertino-200px.png", [webView stringByEvaluatingJavaScript:@"file.name"]);
EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(file)"];
[webView waitForMessage:@"loaded"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("200", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}
@@ -226,8 +223,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("sunset-in-cupertino-100px.tiff", [webView stringByEvaluatingJavaScript:@"file.name"]);
EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"editor.textContent"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(file)"];
[webView waitForMessage:@"loaded"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("100", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}
@@ -248,7 +244,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("image/png", [webView stringByEvaluatingJavaScript:@"file = dataTransfer.files[0]; file.type"]);
EXPECT_WK_STREQ("image.png", [webView stringByEvaluatingJavaScript:@"file.name"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(file)"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("100", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}
@@ -270,7 +266,7 @@ void writeBundleFileToPasteboard(id object)
EXPECT_WK_STREQ("image.png", [webView stringByEvaluatingJavaScript:@"pngItem.file.name"]);
EXPECT_WK_STREQ("true", [webView stringByEvaluatingJavaScript:@"dataTransfer.files.includes(pngItem.file).toString()"]);

[webView stringByEvaluatingJavaScript:@"insertFileAsImage(pngItem.file)"];
[webView waitForMessage:@"loaded" afterEvaluatingScript:@"insertFileAsImage(pngItem.file)"];
EXPECT_WK_STREQ("blob:", [webView stringByEvaluatingJavaScript:@"url = new URL(imageElement.src); url.protocol"]);
EXPECT_WK_STREQ("100", [webView stringByEvaluatingJavaScript:@"imageElement.width"]);
}

0 comments on commit 506b320

Please sign in to comment.