API tests that use URLSchemeHandler are failing.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jul 2017 23:19:50 +0000 (23:19 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Jul 2017 23:19:50 +0000 (23:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174950

Reviewed by Alex Christensen.

Source/WebKit:

Make sure that in all cases where we remove the last task from the page->task map...
...We also remove the map itself.

* UIProcess/WebURLSchemeHandler.cpp:
(WebKit::WebURLSchemeHandler::stopTask):
(WebKit::WebURLSchemeHandler::taskCompleted):
(WebKit::WebURLSchemeHandler::removeTaskFromPageMap):
* UIProcess/WebURLSchemeHandler.h:

Tools:

Fix the NoMIMEType test to be correct.

* TestWebKitAPI/Tests/WebKit2Cocoa/WKURLSchemeHandler-1.mm:
(-[SchemeHandler initWithData:mimeType:]):
(-[SchemeHandler webView:startURLSchemeTask:]):
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebURLSchemeHandler.cpp
Source/WebKit/UIProcess/WebURLSchemeHandler.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKURLSchemeHandler-1.mm

index dd6a4b8..77ac3b1 100644 (file)
@@ -1,5 +1,21 @@
 2017-07-28  Brady Eidson  <beidson@apple.com>
 
+        API tests that use URLSchemeHandler are failing.
+        https://bugs.webkit.org/show_bug.cgi?id=174950
+
+        Reviewed by Alex Christensen.
+
+        Make sure that in all cases where we remove the last task from the page->task map...
+        ...We also remove the map itself.
+
+        * UIProcess/WebURLSchemeHandler.cpp:
+        (WebKit::WebURLSchemeHandler::stopTask):
+        (WebKit::WebURLSchemeHandler::taskCompleted):
+        (WebKit::WebURLSchemeHandler::removeTaskFromPageMap):
+        * UIProcess/WebURLSchemeHandler.h:
+
+2017-07-28  Brady Eidson  <beidson@apple.com>
+
         WKURLSchemeTaskImpl instances are being abandoned (except if the task is stopped).
         <rdar://problem/33568276> and https://bugs.webkit.org/show_bug.cgi?id=174895
 
index 4a8233e..798d499 100644 (file)
@@ -80,28 +80,30 @@ void WebURLSchemeHandler::stopTask(WebPageProxy& page, uint64_t taskIdentifier)
     if (iterator == m_tasks.end())
         return;
 
-    auto pageIterator = m_tasksByPageIdentifier.find(page.pageID());
-    ASSERT(pageIterator != m_tasksByPageIdentifier.end());
-    ASSERT(pageIterator->value.contains(taskIdentifier));
-    pageIterator->value.remove(taskIdentifier);
-
     iterator->value->stop();
     platformStopTask(page, iterator->value);
 
+    removeTaskFromPageMap(page.pageID(), taskIdentifier);
     m_tasks.remove(iterator);
-    if (pageIterator->value.isEmpty())
-        m_tasksByPageIdentifier.remove(pageIterator);
 }
 
 void WebURLSchemeHandler::taskCompleted(WebURLSchemeTask& task)
 {
     auto takenTask = m_tasks.take(task.identifier());
     ASSERT_UNUSED(takenTask, takenTask->ptr() == &task);
-
-    ASSERT(m_tasksByPageIdentifier.get(task.pageID()).contains(task.identifier()));
-    m_tasksByPageIdentifier.get(task.pageID()).remove(task.identifier());
+    removeTaskFromPageMap(task.pageID(), task.identifier());
 
     platformTaskCompleted(task);
 }
 
+void WebURLSchemeHandler::removeTaskFromPageMap(uint64_t pageID, uint64_t taskID)
+{
+    auto iterator = m_tasksByPageIdentifier.find(pageID);
+    ASSERT(iterator != m_tasksByPageIdentifier.end());
+    ASSERT(iterator->value.contains(taskID));
+    iterator->value.remove(taskID);
+    if (iterator->value.isEmpty())
+        m_tasksByPageIdentifier.remove(iterator);
+}
+
 } // namespace WebKit
index 6b76405..3e92a21 100644 (file)
@@ -59,6 +59,8 @@ private:
     virtual void platformStopTask(WebPageProxy&, WebURLSchemeTask&) = 0;
     virtual void platformTaskCompleted(WebURLSchemeTask&) = 0;
 
+    void removeTaskFromPageMap(uint64_t pageID, uint64_t taskID);
+
     uint64_t m_identifier;
 
     HashMap<uint64_t, Ref<WebURLSchemeTask>> m_tasks;
index 36480c7..8ad94ed 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-28  Brady Eidson  <beidson@apple.com>
+
+        API tests that use URLSchemeHandler are failing.
+        https://bugs.webkit.org/show_bug.cgi?id=174950
+
+        Reviewed by Alex Christensen.
+
+        Fix the NoMIMEType test to be correct.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKURLSchemeHandler-1.mm:
+        (-[SchemeHandler initWithData:mimeType:]):
+        (-[SchemeHandler webView:startURLSchemeTask:]):
+        (TEST):
+
 2017-07-28  Daniel Bates  <dabates@apple.com>
 
         prepare-ChangeLog should not list added layout tests in PAL ChangeLog
index 3a1bd4b..d3c472e 100644 (file)
@@ -41,6 +41,7 @@ static bool done;
 @interface SchemeHandler : NSObject <WKURLSchemeHandler>
 @property (readonly) NSMutableArray<NSURL *> *startedURLs;
 @property (readonly) NSMutableArray<NSURL *> *stoppedURLs;
+@property (assign) BOOL shouldFinish;
 - (instancetype)initWithData:(NSData *)data mimeType:(NSString *)inMIMEType;
 @end
 
@@ -59,6 +60,7 @@ static bool done;
     mimeType = inMIMEType;
     _startedURLs = [[NSMutableArray alloc] init];
     _stoppedURLs = [[NSMutableArray alloc] init];
+    _shouldFinish = YES;
 
     return self;
 }
@@ -84,7 +86,8 @@ static bool done;
     RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:mimeType.get() expectedContentLength:1 textEncodingName:nil]);
     [task didReceiveResponse:response.get()];
     [task didReceiveData:resourceData.get()];
-    [task didFinish];
+    if (_shouldFinish)
+        [task didFinish];
 }
 
 - (void)webView:(WKWebView *)webView stopURLSchemeTask:(id <WKURLSchemeTask>)task
@@ -133,6 +136,7 @@ TEST(URLSchemeHandler, NoMIMEType)
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
 
     RetainPtr<SchemeHandler> handler = adoptNS([[SchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes) freeWhenDone:NO] mimeType:nil]);
+    handler.get().shouldFinish = NO;
     [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testing"];
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);