Title: [254367] trunk/Tools
- Revision
- 254367
- Author
- [email protected]
- Date
- 2020-01-10 14:38:30 -0800 (Fri, 10 Jan 2020)
Log Message
Fix test assertions after r254345
https://bugs.webkit.org/show_bug.cgi?id=206037
There were two assertions being hit in the new tests:
1. Beacon sends POST requests, so the HTTP server that receives them needs to be able to handle POST requests.
2. There was an assertion in the destructor of NetworkResourceLoader because we were destroying a WKWebView during a sync xhr.
This isn't a problem in practice, but we may as well wait for the sync xhr to finish before completing the test so we can
keep the sync xhr assertion, which is useful to prevent hangs.
* TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
(-[TestUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):
* TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::HTTPServer::respondToRequests):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (254366 => 254367)
--- trunk/Tools/ChangeLog 2020-01-10 22:21:43 UTC (rev 254366)
+++ trunk/Tools/ChangeLog 2020-01-10 22:38:30 UTC (rev 254367)
@@ -1,3 +1,20 @@
+2020-01-10 Alex Christensen <[email protected]>
+
+ Fix test assertions after r254345
+ https://bugs.webkit.org/show_bug.cgi?id=206037
+
+ There were two assertions being hit in the new tests:
+ 1. Beacon sends POST requests, so the HTTP server that receives them needs to be able to handle POST requests.
+ 2. There was an assertion in the destructor of NetworkResourceLoader because we were destroying a WKWebView during a sync xhr.
+ This isn't a problem in practice, but we may as well wait for the sync xhr to finish before completing the test so we can
+ keep the sync xhr assertion, which is useful to prevent hangs.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
+ (-[TestUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+ (TEST):
+ * TestWebKitAPI/cocoa/HTTPServer.mm:
+ (TestWebKitAPI::HTTPServer::respondToRequests):
+
2020-01-10 Carlos Alberto Lopez Perez <[email protected]>
[GTK][WPE] EWS should not wipe the JHBuild in the unapply patch step
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm (254366 => 254367)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm 2020-01-10 22:21:43 UTC (rev 254366)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm 2020-01-10 22:38:30 UTC (rev 254367)
@@ -80,6 +80,24 @@
@end
+@interface TestUIDelegate : NSObject <WKUIDelegate>
+
+@property (nonatomic, copy) void (^runJavaScriptAlertPanelWithMessage)(WKWebView *, NSString *, WKFrameInfo *, void (^)(void));
+
+@end
+
+@implementation TestUIDelegate
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+ if (_runJavaScriptAlertPanelWithMessage)
+ _runJavaScriptAlertPanelWithMessage(webView, message, frame, completionHandler);
+ else
+ completionHandler();
+}
+
+@end
+
TEST(ResourceLoadDelegate, Basic)
{
auto webView = adoptNS([WKWebView new]);
@@ -126,6 +144,14 @@
requestFromDelegate = request;
receivedCallback = true;
}];
+
+ __block bool receivedAlert = false;
+ auto uiDelegate = adoptNS([TestUIDelegate new]);
+ [webView setUIDelegate:uiDelegate.get()];
+ [uiDelegate setRunJavaScriptAlertPanelWithMessage:^(WKWebView *, NSString *, WKFrameInfo *, void (^completionHandler)(void)) {
+ receivedAlert = true;
+ completionHandler();
+ }];
[webView evaluateJavaScript:@"navigator.sendBeacon('/beaconTarget')" completionHandler:nil];
TestWebKitAPI::Util::run(&receivedCallback);
@@ -136,9 +162,11 @@
@"var request = new XMLHttpRequest();"
"var asynchronous = false;"
"request.open('GET', 'xhrTarget', asynchronous);"
- "request.send();" completionHandler:nil];
+ "request.send();"
+ "alert('done');" completionHandler:nil];
TestWebKitAPI::Util::run(&receivedCallback);
EXPECT_WK_STREQ("/xhrTarget", requestFromDelegate.get().URL.path);
+ TestWebKitAPI::Util::run(&receivedAlert);
}
TEST(ResourceLoadDelegate, Redirect)
Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (254366 => 254367)
--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm 2020-01-10 22:21:43 UTC (rev 254366)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm 2020-01-10 22:38:30 UTC (rev 254367)
@@ -76,14 +76,20 @@
});
request.append(0);
- const char* pathPrefix = "GET ";
+ const char* getPathPrefix = "GET ";
+ const char* postPathPrefix = "POST ";
const char* pathSuffix = " HTTP/1.1\r\n";
const char* pathEnd = strstr(request.data(), pathSuffix);
ASSERT_WITH_MESSAGE(pathEnd, "HTTPServer assumes request is HTTP 1.1");
- ASSERT_WITH_MESSAGE(!memcmp(request.data(), pathPrefix, strlen(pathPrefix)), "HTTPServer assumes request is GET");
ASSERT_WITH_MESSAGE(strstr(request.data(), "\r\n\r\n"), "HTTPServer assumes entire HTTP request is received at once");
- size_t pathLength = pathEnd - request.data() - strlen(pathPrefix);
- String path(request.data() + strlen(pathPrefix), pathLength);
+ size_t pathPrefixLength = 0;
+ if (!memcmp(request.data(), getPathPrefix, strlen(getPathPrefix)))
+ pathPrefixLength = strlen(getPathPrefix);
+ else if (!memcmp(request.data(), postPathPrefix, strlen(postPathPrefix)))
+ pathPrefixLength = strlen(postPathPrefix);
+ ASSERT_WITH_MESSAGE(pathPrefixLength, "HTTPServer assumes request is GET or POST");
+ size_t pathLength = pathEnd - request.data() - pathPrefixLength;
+ String path(request.data() + pathPrefixLength, pathLength);
ASSERT_WITH_MESSAGE(m_requestResponseMap.contains(path), "This HTTPServer does not know how to respond to a request for %s", path.utf8().data());
auto response = m_requestResponseMap.get(path);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes