WebProcesses don't handle DatabaseProcess going away uncleanly..
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jul 2016 15:30:50 +0000 (15:30 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Jul 2016 15:30:50 +0000 (15:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159371

Reviewed by Alex Christensen.

Source/WebCore:

Covered by new API test.

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::didCloseFromServer):
(WebCore::IDBDatabase::connectionToServerLost):
* Modules/indexeddb/IDBDatabase.h:

* Modules/indexeddb/client/IDBConnectionProxy.cpp:
(WebCore::IDBClient::IDBConnectionProxy::connectionToServerLost): Notify all IDBDatabase
  connections, as well as all pending IDBOpenDBRequests, with the error about the
  server connection dropping.
* Modules/indexeddb/client/IDBConnectionProxy.h:

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::connectionToServerLost):
* Modules/indexeddb/client/IDBConnectionToServer.h:

* Modules/indexeddb/shared/IDBError.h:

Source/WebKit2:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::terminateDatabaseProcess): Deleted.

* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
(WebKit::WebIDBConnectionToServer::connectionToServerLost):
* WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:

* WebProcess/Databases/WebToDatabaseProcessConnection.cpp:
(WebKit::WebToDatabaseProcessConnection::didReceiveMessage):
(WebKit::WebToDatabaseProcessConnection::didClose): Notify each connection
  that the database server connection dropped.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill-1.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm: Added.
(-[DatabaseProcessKillNavigationDelegate webView:didFinishNavigation:]):
(-[DatabaseProcessKillMessageHandler userContentController:didReceiveScriptMessage:]):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.h
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h
Source/WebCore/Modules/indexeddb/shared/IDBError.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebProcessPool.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp
Source/WebKit2/WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h
Source/WebKit2/WebProcess/Databases/WebToDatabaseProcessConnection.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill-1.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm [new file with mode: 0644]

index de94356..afbe02b 100644 (file)
@@ -1,3 +1,29 @@
+2016-07-04  Brady Eidson  <beidson@apple.com>
+
+        WebProcesses don't handle DatabaseProcess going away uncleanly..
+        https://bugs.webkit.org/show_bug.cgi?id=159371
+
+        Reviewed by Alex Christensen.
+
+        Covered by new API test.
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::didCloseFromServer):
+        (WebCore::IDBDatabase::connectionToServerLost):
+        * Modules/indexeddb/IDBDatabase.h:
+        
+        * Modules/indexeddb/client/IDBConnectionProxy.cpp:
+        (WebCore::IDBClient::IDBConnectionProxy::connectionToServerLost): Notify all IDBDatabase
+          connections, as well as all pending IDBOpenDBRequests, with the error about the
+          server connection dropping.
+        * Modules/indexeddb/client/IDBConnectionProxy.h:
+        
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::connectionToServerLost):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+        
+        * Modules/indexeddb/shared/IDBError.h:
+
 2016-07-04  Philippe Normand  <pnormand@igalia.com>
 
         Release build with logging enabled fails
index db52511..bbf7532 100644 (file)
@@ -257,6 +257,15 @@ void IDBDatabase::didCloseFromServer(const IDBError& error)
 {
     LOG(IndexedDB, "IDBDatabase::didCloseFromServer - %" PRIu64, m_databaseConnectionIdentifier);
 
+    connectionToServerLost(error);
+
+    m_connectionProxy->confirmDidCloseFromServer(*this);
+}
+
+void IDBDatabase::connectionToServerLost(const IDBError& error)
+{
+    LOG(IndexedDB, "IDBDatabase::connectionToServerLost - %" PRIu64, m_databaseConnectionIdentifier);
+
     ASSERT(currentThread() == originThreadID());
 
     m_closePending = true;
@@ -268,8 +277,6 @@ void IDBDatabase::didCloseFromServer(const IDBError& error)
     Ref<Event> event = Event::create(eventNames().errorEvent, true, false);
     event->setTarget(this);
     scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event));
-
-    m_connectionProxy->confirmDidCloseFromServer(*this);
 }
 
 void IDBDatabase::maybeCloseInServer()
index a671bc1..a0f8c5d 100644 (file)
@@ -88,6 +88,7 @@ public:
 
     void fireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion);
     void didCloseFromServer(const IDBError&);
+    void connectionToServerLost(const IDBError&);
 
     IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }
 
index a1b1f44..8363619 100644 (file)
@@ -386,6 +386,48 @@ void IDBConnectionProxy::confirmDidCloseFromServer(IDBDatabase& database)
     callConnectionOnMainThread(&IDBConnectionToServer::confirmDidCloseFromServer, database.databaseConnectionIdentifier());
 }
 
+void IDBConnectionProxy::connectionToServerLost(const IDBError& error)
+{
+    Vector<uint64_t> databaseConnectionIdentifiers;
+    {
+        Locker<Lock> locker(m_databaseConnectionMapLock);
+        copyKeysToVector(m_databaseConnectionMap, databaseConnectionIdentifiers);
+    }
+
+    for (auto connectionIdentifier : databaseConnectionIdentifiers) {
+        RefPtr<IDBDatabase> database;
+        {
+            Locker<Lock> locker(m_databaseConnectionMapLock);
+            database = m_databaseConnectionMap.get(connectionIdentifier);
+        }
+
+        if (!database)
+            continue;
+
+        database->performCallbackOnOriginThread(*database, &IDBDatabase::connectionToServerLost, error);
+    }
+
+    Vector<IDBResourceIdentifier> openDBRequestIdentifiers;
+    {
+        Locker<Lock> locker(m_openDBRequestMapLock);
+        copyKeysToVector(m_openDBRequestMap, openDBRequestIdentifiers);
+    }
+
+    for (auto& requestIdentifier : openDBRequestIdentifiers) {
+        RefPtr<IDBOpenDBRequest> request;
+        {
+            Locker<Lock> locker(m_openDBRequestMapLock);
+            request = m_openDBRequestMap.get(requestIdentifier);
+        }
+
+        if (!request)
+            continue;
+
+        auto result = IDBResultData::error(requestIdentifier, error);
+        request->performCallbackOnOriginThread(*request, &IDBOpenDBRequest::requestCompleted, result);
+    }
+}
+
 void IDBConnectionProxy::scheduleMainThreadTasks()
 {
     Locker<Lock> locker(m_mainThreadTaskLock);
index 9d58a81..1a5d721 100644 (file)
@@ -97,6 +97,8 @@ public:
     void didCloseFromServer(uint64_t databaseConnectionIdentifier, const IDBError&);
     void confirmDidCloseFromServer(IDBDatabase&);
 
+    void connectionToServerLost(const IDBError&);
+
     void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier);
 
     void completeOperation(const IDBResultData&);
index 662ac4b..4d93834 100644 (file)
@@ -332,6 +332,14 @@ void IDBConnectionToServer::confirmDidCloseFromServer(uint64_t databaseConnectio
     m_delegate->confirmDidCloseFromServer(databaseConnectionIdentifier);
 }
 
+void IDBConnectionToServer::connectionToServerLost(const IDBError& error)
+{
+    LOG(IndexedDB, "IDBConnectionToServer::connectionToServerLost");
+    ASSERT(isMainThread());
+
+    m_proxy->connectionToServerLost(error);
+}
+
 void IDBConnectionToServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
 {
     LOG(IndexedDB, "IDBConnectionToServer::didStartTransaction");
index c7933c8..a6ace57 100644 (file)
@@ -110,6 +110,8 @@ public:
     WEBCORE_EXPORT void didCloseFromServer(uint64_t databaseConnectionIdentifier, const IDBError&);
     void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier);
 
+    WEBCORE_EXPORT void connectionToServerLost(const IDBError&);
+
     WEBCORE_EXPORT void notifyOpenDBRequestBlocked(const IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
     void openDBRequestCancelled(const IDBRequestData&);
 
index 2ca5bc1..bb5531b 100644 (file)
@@ -37,7 +37,7 @@ class IDBError {
 public:
     IDBError() { }
     IDBError(ExceptionCode);
-    IDBError(ExceptionCode, const String& message);
+    WEBCORE_EXPORT IDBError(ExceptionCode, const String& message);
 
     static IDBError userDeleteError()
     {
index 7a072de..fe1cb4e 100644 (file)
@@ -1,3 +1,22 @@
+2016-07-04  Brady Eidson  <beidson@apple.com>
+
+        WebProcesses don't handle DatabaseProcess going away uncleanly..
+        https://bugs.webkit.org/show_bug.cgi?id=159371
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::terminateDatabaseProcess): Deleted.
+
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.cpp:
+        (WebKit::WebIDBConnectionToServer::connectionToServerLost):
+        * WebProcess/Databases/IndexedDB/WebIDBConnectionToServer.h:
+
+        * WebProcess/Databases/WebToDatabaseProcessConnection.cpp:
+        (WebKit::WebToDatabaseProcessConnection::didReceiveMessage):
+        (WebKit::WebToDatabaseProcessConnection::didClose): Notify each connection
+          that the database server connection dropped.
+
 2016-07-04  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [GTK] Null WebCore::Range dereference in WebEditorClient::updateGlobalSelection
index a7e0346..2f9bf09 100644 (file)
@@ -1100,7 +1100,6 @@ void WebProcessPool::clearCachedCredentials()
 void WebProcessPool::terminateDatabaseProcess()
 {
 #if ENABLE(DATABASE_PROCESS)
-    ASSERT(m_processes.isEmpty());
     if (!m_databaseProcess)
         return;
 
index 1588cd3..f6f80d5 100644 (file)
@@ -38,6 +38,7 @@
 #include "WebToDatabaseProcessConnection.h"
 #include <WebCore/IDBConnectionToServer.h>
 #include <WebCore/IDBCursorInfo.h>
+#include <WebCore/IDBDatabaseException.h>
 #include <WebCore/IDBError.h>
 #include <WebCore/IDBIndexInfo.h>
 #include <WebCore/IDBKeyRangeData.h>
@@ -316,6 +317,11 @@ void WebIDBConnectionToServer::didGetAllDatabaseNames(uint64_t callbackID, const
     m_connectionToServer->didGetAllDatabaseNames(callbackID, databaseNames);
 }
 
+void WebIDBConnectionToServer::connectionToServerLost()
+{
+    m_connectionToServer->connectionToServerLost({ WebCore::IDBDatabaseException::UnknownError, ASCIILiteral("An internal error was encountered in the Indexed Database server") });
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(INDEXED_DATABASE)
index 29d50a0..0e5c505 100644 (file)
@@ -98,6 +98,8 @@ public:
 
     void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&);
 
+    void connectionToServerLost();
+
 private:
     WebIDBConnectionToServer();
 
index fd51fdc..b71fc77 100644 (file)
@@ -52,9 +52,9 @@ void WebToDatabaseProcessConnection::didReceiveMessage(IPC::Connection& connecti
 {
 #if ENABLE(INDEXED_DATABASE)
     if (decoder.messageReceiverName() == Messages::WebIDBConnectionToServer::messageReceiverName()) {
-        auto iterator = m_webIDBConnectionsByIdentifier.find(decoder.destinationID());
-        if (iterator != m_webIDBConnectionsByIdentifier.end())
-            iterator->value->didReceiveMessage(connection, decoder);
+        auto idbConnection = m_webIDBConnectionsByIdentifier.get(decoder.destinationID());
+        if (idbConnection)
+            idbConnection->didReceiveMessage(connection, decoder);
         return;
     }
 #endif
@@ -64,6 +64,12 @@ void WebToDatabaseProcessConnection::didReceiveMessage(IPC::Connection& connecti
 
 void WebToDatabaseProcessConnection::didClose(IPC::Connection& connection)
 {
+    for (auto& connection : m_webIDBConnectionsByIdentifier.values())
+        connection->connectionToServerLost();
+
+    m_webIDBConnectionsByIdentifier.clear();
+    m_webIDBConnectionsBySession.clear();
+
     WebProcess::singleton().webToDatabaseProcessConnectionClosed(this);
 }
 
index 00cd1b4..60c9d8b 100644 (file)
@@ -1,3 +1,16 @@
+2016-07-04  Brady Eidson  <beidson@apple.com>
+
+        WebProcesses don't handle DatabaseProcess going away uncleanly..
+        https://bugs.webkit.org/show_bug.cgi?id=159371
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill-1.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm: Added.
+        (-[DatabaseProcessKillNavigationDelegate webView:didFinishNavigation:]):
+        (-[DatabaseProcessKillMessageHandler userContentController:didReceiveScriptMessage:]):
+
 2016-07-04  Carlos Alberto Lopez Perez  <clopez@igalia.com>
 
         [EFL][GTK] Layout Test doesn't run on Ubuntu 16.04
index dfb4b15..080f155 100644 (file)
@@ -71,6 +71,8 @@
                51714EB81CF8CA17004723C4 /* WebProcessKillIDBCleanup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */; };
                517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */; };
                51A5877D1D1B49CD004BA9AF /* IndexedDBMultiProcess-3.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51A5877C1D1B3D8D004BA9AF /* IndexedDBMultiProcess-3.html */; };
+               51A587851D2739E3004BA9AF /* IndexedDBDatabaseProcessKill-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51A587821D272EB5004BA9AF /* IndexedDBDatabaseProcessKill-1.html */; };
+               51A587861D273AA9004BA9AF /* IndexedDBDatabaseProcessKill.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51A587841D272EF3004BA9AF /* IndexedDBDatabaseProcessKill.mm */; };
                51B1EE961C80FAEF0064FB98 /* IndexedDBPersistence-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */; };
                51B1EE971C80FAEF0064FB98 /* IndexedDBPersistence-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */; };
                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               51A587851D2739E3004BA9AF /* IndexedDBDatabaseProcessKill-1.html in Copy Resources */,
                                51A5877D1D1B49CD004BA9AF /* IndexedDBMultiProcess-3.html in Copy Resources */,
                                9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */,
                                51714EB41CF8C78C004723C4 /* WebProcessKillIDBCleanup-1.html in Copy Resources */,
                517E7DFB15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCachePruneWithinResourceLoadDelegate.mm; sourceTree = "<group>"; };
                517E7E031511187500D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = MemoryCachePruneWithinResourceLoadDelegate.html; sourceTree = "<group>"; };
                51A5877C1D1B3D8D004BA9AF /* IndexedDBMultiProcess-3.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBMultiProcess-3.html"; sourceTree = "<group>"; };
+               51A587821D272EB5004BA9AF /* IndexedDBDatabaseProcessKill-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBDatabaseProcessKill-1.html"; sourceTree = "<group>"; };
+               51A587841D272EF3004BA9AF /* IndexedDBDatabaseProcessKill.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBDatabaseProcessKill.mm; sourceTree = "<group>"; };
                51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBPersistence.mm; sourceTree = "<group>"; };
                51B1EE941C80FADD0064FB98 /* IndexedDBPersistence-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBPersistence-1.html"; sourceTree = "<group>"; };
                51B1EE951C80FADD0064FB98 /* IndexedDBPersistence-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBPersistence-2.html"; sourceTree = "<group>"; };
                                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
                                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */,
                                CDE195B31CFE0ADE0053D256 /* FullscreenTopContentInset.mm */,
+                               51A587841D272EF3004BA9AF /* IndexedDBDatabaseProcessKill.mm */,
                                51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */,
                                51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */,
                                37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
                                5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */,
                                5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */,
                                5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */,
+                               51A587821D272EB5004BA9AF /* IndexedDBDatabaseProcessKill-1.html */,
                                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */,
                                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */,
                                51A5877C1D1B3D8D004BA9AF /* IndexedDBMultiProcess-3.html */,
                                7CCE7F241A411AF600447C4C /* Navigation.mm in Sources */,
                                A14FC5881B8991BF00D107EB /* ContentFiltering.mm in Sources */,
                                7CCE7F021A411AE600447C4C /* NewFirstVisuallyNonEmptyLayout.cpp in Sources */,
+                               51A587861D273AA9004BA9AF /* IndexedDBDatabaseProcessKill.mm in Sources */,
                                7CCE7F031A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
                                7CCE7F041A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
                                764322D71B61CCC30024F801 /* WordBoundaryTypingAttributes.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill-1.html b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill-1.html
new file mode 100644 (file)
index 0000000..ab4299b
--- /dev/null
@@ -0,0 +1,33 @@
+<script>
+
+var database;
+
+for (var i = 0; i < 100; ++i) {
+    var request = window.indexedDB.deleteDatabase("IndexedDBDatabaseProcessKill");
+    request.onsuccess = function() {
+        window.webkit.messageHandlers.testHandler.postMessage('DeleteRequestDone');
+    }
+    request.onerror = function() {
+        window.webkit.messageHandlers.testHandler.postMessage('DeleteRequestError');
+    }
+
+    request = window.indexedDB.open("IndexedDBDatabaseProcessKill");
+    request.onsuccess = function() {
+        window.webkit.messageHandlers.testHandler.postMessage('OpenRequestDone');
+    }
+    request.onerror = function() {
+        window.webkit.messageHandlers.testHandler.postMessage('OpenRequestError');
+    }
+    request.onupgradeneeded = function(e) {
+        database = e.target.result;
+        database.onerror = function() {
+            notifyDatabaseErrorReceived = function() {
+                window.webkit.messageHandlers.testHandler.postMessage('DatabaseErrorReceived');
+            }
+            setTimeout("setTimeout(notifyDatabaseErrorReceived, 0)", 0);
+        }
+        window.webkit.messageHandlers.testHandler.postMessage('OpenRequestUpgradeNeeded');
+    }
+}
+
+</script>
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm b/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm
new file mode 100644 (file)
index 0000000..759f98b
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKUserContentControllerPrivate.h>
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WebKit.h>
+#import <WebKit/_WKProcessPoolConfiguration.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+static bool isDoneWithNavigation;
+
+@interface DatabaseProcessKillNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation DatabaseProcessKillNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    isDoneWithNavigation = true;
+}
+
+@end
+
+static bool receivedScriptMessage;
+static bool receivedAtLeastOneOpenError;
+static bool receivedAtLeastOneDeleteError;
+static bool openRequestUpgradeNeeded;
+static bool databaseErrorReceived;
+
+@interface DatabaseProcessKillMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation DatabaseProcessKillMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    receivedScriptMessage = true;
+
+    if ([[message body] isEqualToString:@"DatabaseErrorReceived"]) {
+        databaseErrorReceived = true;
+        return;
+    }
+
+    if ([[message body] isEqualToString:@"OpenRequestUpgradeNeeded"]) {
+        openRequestUpgradeNeeded = true;
+        return;
+    }
+
+    if ([[message body] isEqualToString:@"DeleteRequestError"]) {
+        receivedAtLeastOneDeleteError = true;
+        return;
+    }
+
+    if ([[message body] isEqualToString:@"OpenRequestError"])
+        receivedAtLeastOneOpenError = true;
+}
+
+@end
+
+TEST(IndexedDB, DatabaseProcessKill)
+{
+    RetainPtr<DatabaseProcessKillMessageHandler> handler = adoptNS([[DatabaseProcessKillMessageHandler alloc] init]);
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+    // Allow file URLs to load non-file resources
+    [configuration _setAllowUniversalAccessFromFileURLs:YES];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    DatabaseProcessKillNavigationDelegate *delegate = [[DatabaseProcessKillNavigationDelegate alloc] init];
+    [webView setNavigationDelegate:delegate];
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBDatabaseProcessKill-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+
+    bool killedDBProcess = false;
+    while (true) {
+        if (databaseErrorReceived)
+            break;
+
+        receivedScriptMessage = false;
+        TestWebKitAPI::Util::run(&receivedScriptMessage);
+        if (!killedDBProcess && openRequestUpgradeNeeded) {
+            killedDBProcess = true;
+            [configuration.get().processPool _terminateDatabaseProcess];
+        }
+    }
+
+    EXPECT_EQ(receivedAtLeastOneOpenError, true);
+    EXPECT_EQ(receivedAtLeastOneDeleteError, true);
+    EXPECT_EQ(databaseErrorReceived, true);
+}
+
+#endif