Changeset 254367 in webkit


Ignore:
Timestamp:
Jan 10, 2020 2:38:30 PM (4 years ago)
Author:
achristensen@apple.com
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):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r254359 r254367  
     12020-01-10  Alex Christensen  <achristensen@webkit.org>
     2
     3        Fix test assertions after r254345
     4        https://bugs.webkit.org/show_bug.cgi?id=206037
     5
     6        There were two assertions being hit in the new tests:
     7        1. Beacon sends POST requests, so the HTTP server that receives them needs to be able to handle POST requests.
     8        2. There was an assertion in the destructor of NetworkResourceLoader because we were destroying a WKWebView during a sync xhr.
     9        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
     10        keep the sync xhr assertion, which is useful to prevent hangs.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:
     13        (-[TestUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     14        (TEST):
     15        * TestWebKitAPI/cocoa/HTTPServer.mm:
     16        (TestWebKitAPI::HTTPServer::respondToRequests):
     17
    1182020-01-10  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    219
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm

    r254357 r254367  
    8181@end
    8282
     83@interface TestUIDelegate : NSObject <WKUIDelegate>
     84
     85@property (nonatomic, copy) void (^runJavaScriptAlertPanelWithMessage)(WKWebView *, NSString *, WKFrameInfo *, void (^)(void));
     86
     87@end
     88
     89@implementation TestUIDelegate
     90
     91- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
     92{
     93    if (_runJavaScriptAlertPanelWithMessage)
     94        _runJavaScriptAlertPanelWithMessage(webView, message, frame, completionHandler);
     95    else
     96        completionHandler();
     97}
     98
     99@end
     100
    83101TEST(ResourceLoadDelegate, Basic)
    84102{
     
    127145        receivedCallback = true;
    128146    }];
     147   
     148    __block bool receivedAlert = false;
     149    auto uiDelegate = adoptNS([TestUIDelegate new]);
     150    [webView setUIDelegate:uiDelegate.get()];
     151    [uiDelegate setRunJavaScriptAlertPanelWithMessage:^(WKWebView *, NSString *, WKFrameInfo *, void (^completionHandler)(void)) {
     152        receivedAlert = true;
     153        completionHandler();
     154    }];
    129155
    130156    [webView evaluateJavaScript:@"navigator.sendBeacon('/beaconTarget')" completionHandler:nil];
     
    137163        "var asynchronous = false;"
    138164        "request.open('GET', 'xhrTarget', asynchronous);"
    139         "request.send();" completionHandler:nil];
     165        "request.send();"
     166        "alert('done');" completionHandler:nil];
    140167    TestWebKitAPI::Util::run(&receivedCallback);
    141168    EXPECT_WK_STREQ("/xhrTarget", requestFromDelegate.get().URL.path);
     169    TestWebKitAPI::Util::run(&receivedAlert);
    142170}
    143171
  • trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm

    r254345 r254367  
    7777        request.append(0);
    7878
    79         const char* pathPrefix = "GET ";
     79        const char* getPathPrefix = "GET ";
     80        const char* postPathPrefix = "POST ";
    8081        const char* pathSuffix = " HTTP/1.1\r\n";
    8182        const char* pathEnd = strstr(request.data(), pathSuffix);
    8283        ASSERT_WITH_MESSAGE(pathEnd, "HTTPServer assumes request is HTTP 1.1");
    83         ASSERT_WITH_MESSAGE(!memcmp(request.data(), pathPrefix, strlen(pathPrefix)), "HTTPServer assumes request is GET");
    8484        ASSERT_WITH_MESSAGE(strstr(request.data(), "\r\n\r\n"), "HTTPServer assumes entire HTTP request is received at once");
    85         size_t pathLength = pathEnd - request.data() - strlen(pathPrefix);
    86         String path(request.data() + strlen(pathPrefix), pathLength);
     85        size_t pathPrefixLength = 0;
     86        if (!memcmp(request.data(), getPathPrefix, strlen(getPathPrefix)))
     87            pathPrefixLength = strlen(getPathPrefix);
     88        else if (!memcmp(request.data(), postPathPrefix, strlen(postPathPrefix)))
     89            pathPrefixLength = strlen(postPathPrefix);
     90        ASSERT_WITH_MESSAGE(pathPrefixLength, "HTTPServer assumes request is GET or POST");
     91        size_t pathLength = pathEnd - request.data() - pathPrefixLength;
     92        String path(request.data() + pathPrefixLength, pathLength);
    8793        ASSERT_WITH_MESSAGE(m_requestResponseMap.contains(path), "This HTTPServer does not know how to respond to a request for %s", path.utf8().data());
    8894       
Note: See TracChangeset for help on using the changeset viewer.