<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[203859] branches/safari-602-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/203859">203859</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-07-29 00:11:05 -0700 (Fri, 29 Jul 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/203622">r203622</a>. rdar://problem/27495748</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebCoreChangeLog">branches/safari-602-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebCoreModulesindexeddbserverIDBServercpp">branches/safari-602-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#branchessafari602branchToolsChangeLog">branches/safari-602-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaStoreBlobThenDeletemm">branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm</a></li>
<li><a href="#branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaStoreBlobToBeDeletedhtml">branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobToBeDeleted.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (203858 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/ChangeLog        2016-07-29 06:45:21 UTC (rev 203858)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r203622. rdar://problem/27495748
+
+    2016-07-22  Brady Eidson  &lt;beidson@apple.com&gt;
+
+            Removing IndexedDatabases that have stored blobs doesn't remove the blob files.
+            https://bugs.webkit.org/show_bug.cgi?id=160089
+
+            Reviewed by Darin Adler.
+
+            Tested by API test IndexedDB.StoreBlobThenDelete.
+
+            Blob filenames exist in the IDB directory with the name &quot;[0-9]+.blob&quot;.
+
+            That is, one or more digits, followed by &quot;.blob&quot;.
+
+            So when we delete an IndexedDB.sqlite3 and related files, we should delete those blob files as well.
+
+            * Modules/indexeddb/server/IDBServer.cpp:
+            (WebCore::IDBServer::removeAllDatabasesForOriginPath):
+
</ins><span class="cx"> 2016-07-22  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r203626. rdar://problem/27453479
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (203858 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-07-29 06:45:21 UTC (rev 203858)
+++ branches/safari-602-branch/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -555,10 +555,52 @@
</span><span class="cx">                 continue;
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        // Deleting this database means we need to delete all files that represent it.
+        // This includes:
+        //     - The directory itself, which is named after the database.
+        //     - IndexedDB.sqlite3 and related SQLite files.
+        //     - Blob files that we stored in the directory.
+        //
+        // To be conservative, we should *not* try to delete files that are unexpected;
+        // We should only delete files we think we put there.
+        //
+        // IndexedDB blob files are named &quot;N.blob&quot; where N is a decimal integer,
+        // so those are the only blob files we should be trying to delete.
+        for (auto&amp; blobPath : listDirectory(databasePath, &quot;[0-9]*.blob&quot;)) {
+            // Globbing can't give us only filenames starting with 1-or-more digits.
+            // The above globbing gives us files that start with a digit and ends with &quot;.blob&quot;, but there might be non-digits in between.
+            // We need to validate that each filename contains only digits before deleting it, as any other files are not ones we put there.
+            String filename = pathGetFileName(blobPath);
+            auto filenameLength = filename.length();
+
+            ASSERT(filenameLength &gt;= 6);
+            ASSERT(filename.endsWith(&quot;.blob&quot;));
+
+            if (filename.length() &lt; 6)
+                continue;
+            if (!filename.endsWith(&quot;.blob&quot;))
+                continue;
+
+            bool validFilename = true;
+            for (unsigned i = 0; i &lt; filenameLength - 5; ++i) {
+                if (!isASCIIDigit(filename[i])) {
+                    validFilename = false;
+                    break;
+                }
+            }
+
+            if (validFilename)
+                deleteFile(blobPath);
+        }
+
+        // Now delete IndexedDB.sqlite3 and related SQLite files.
</ins><span class="cx">         SQLiteFileSystem::deleteDatabaseFile(databaseFile);
</span><ins>+
+        // And finally, if we can, delete the empty directory.
</ins><span class="cx">         deleteEmptyDirectory(databasePath);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // If no databases remain for this origin, we can delete the origin directory as well.
</ins><span class="cx">     deleteEmptyDirectory(originPath);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari602branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/ChangeLog (203858 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/ChangeLog        2016-07-29 06:45:21 UTC (rev 203858)
+++ branches/safari-602-branch/Tools/ChangeLog        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-07-28  Babak Shafiei  &lt;bshafiei@apple.com&gt;
+
+        Merge r203622. rdar://problem/27495748
+
+    2016-07-22  Brady Eidson  &lt;beidson@apple.com&gt;
+
+            Removing IndexedDatabases that have stored blobs doesn't remove the blob files.
+            https://bugs.webkit.org/show_bug.cgi?id=160089
+
+            Reviewed by Darin Adler.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm: Added.
+            * TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobToBeDeleted.html: Added.
+
</ins><span class="cx"> 2016-07-22  Babak Shafiei  &lt;bshafiei@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Merge r203545. rdar://problem/26964090
</span></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (203858 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-07-29 06:45:21 UTC (rev 203858)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -79,6 +79,8 @@
</span><span class="cx">                 510477781D29923B009747EB /* IDBDeleteRecovery.mm in Sources */ = {isa = PBXBuildFile; fileRef = 510477751D298E03009747EB /* IDBDeleteRecovery.mm */; };
</span><span class="cx">                 51393E221523952D005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51393E1D1523944A005F39C5 /* DOMWindowExtensionBasic_Bundle.cpp */; };
</span><span class="cx">                 5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */; };
</span><ins>+                515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */; };
+                515BE1711D428E4B00DD7C68 /* StoreBlobThenDelete.mm in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */; };
</ins><span class="cx">                 51714EB41CF8C78C004723C4 /* WebProcessKillIDBCleanup-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */; };
</span><span class="cx">                 51714EB51CF8C78C004723C4 /* WebProcessKillIDBCleanup-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */; };
</span><span class="cx">                 51714EB81CF8CA17004723C4 /* WebProcessKillIDBCleanup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */; };
</span><span class="lines">@@ -495,6 +497,7 @@
</span><span class="cx">                         dstPath = TestWebKitAPI.resources;
</span><span class="cx">                         dstSubfolderSpec = 7;
</span><span class="cx">                         files = (
</span><ins>+                                515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */,
</ins><span class="cx">                                 5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
</span><span class="cx">                                 5C9E59421D3EB5AC00E3C62E /* ApplicationCache.db-shm in Copy Resources */,
</span><span class="cx">                                 5C9E59431D3EB5AC00E3C62E /* ApplicationCache.db-wal in Copy Resources */,
</span><span class="lines">@@ -748,6 +751,8 @@
</span><span class="cx">                 51393E1E1523944A005F39C5 /* DOMWindowExtensionBasic.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMWindowExtensionBasic.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5142B2701517C88B00C32B19 /* ContextMenuCanCopyURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuCanCopyURL.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = ContextMenuCanCopyURL.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = StoreBlobToBeDeleted.html; sourceTree = &quot;&lt;group&gt;&quot;; };
+                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StoreBlobThenDelete.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;WebProcessKillIDBCleanup-1.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = &quot;WebProcessKillIDBCleanup-2.html&quot;; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessKillIDBCleanup.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -1242,6 +1247,7 @@
</span><span class="cx">                                 CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
</span><span class="cx">                                 37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
</span><span class="cx">                                 2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
</span><ins>+                                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
</ins><span class="cx">                                 7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
</span><span class="cx">                                 7C882E031C80C624006BF731 /* UserContentWorld.mm */,
</span><span class="cx">                                 7C882E041C80C624006BF731 /* UserContentWorldPlugIn.mm */,
</span><span class="lines">@@ -1360,6 +1366,7 @@
</span><span class="cx">                                 46C519E31D35629600DAA51A /* LocalStorageNullEntries.localstorage */,
</span><span class="cx">                                 46C519E41D35629600DAA51A /* LocalStorageNullEntries.localstorage-shm */,
</span><span class="cx">                                 7CCB99221D3B44E7003922F6 /* open-multiple-external-url.html */,
</span><ins>+                                515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */,
</ins><span class="cx">                                 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */,
</span><span class="cx">                                 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
</span><span class="cx">                         );
</span><span class="lines">@@ -2212,6 +2219,7 @@
</span><span class="cx">                                 7CCE7EA61A411A0F00447C4C /* PlatformUtilitiesMac.mm in Sources */,
</span><span class="cx">                                 7CCE7EA71A411A1300447C4C /* PlatformWebViewMac.mm in Sources */,
</span><span class="cx">                                 835CF9671D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp in Sources */,
</span><ins>+                                515BE1711D428E4B00DD7C68 /* StoreBlobThenDelete.mm in Sources */,
</ins><span class="cx">                                 7CCE7F261A411AF600447C4C /* Preferences.mm in Sources */,
</span><span class="cx">                                 7CCE7F0B1A411AE600447C4C /* PreventEmptyUserAgent.cpp in Sources */,
</span><span class="cx">                                 7C83E0BD1D0A650C00FEBCF3 /* FullscreenTopContentInset.mm in Sources */,
</span></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaStoreBlobThenDeletemm"></a>
<div class="addfile"><h4>Added: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm (0 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm                                (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -0,0 +1,112 @@
</span><ins>+/*
+ * 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 &quot;config.h&quot;
+
+#import &quot;PlatformUtilities.h&quot;
+#import &quot;Test.h&quot;
+#import &lt;WebKit/WebKit.h&gt;
+#import &lt;WebKit/WKProcessPoolPrivate.h&gt;
+#import &lt;WebKit/WKUserContentControllerPrivate.h&gt;
+#import &lt;WebKit/WKWebViewConfigurationPrivate.h&gt;
+#import &lt;WebKit/_WKProcessPoolConfiguration.h&gt;
+#import &lt;WebKit/_WKUserStyleSheet.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+
+#if WK_API_ENABLED
+
+static bool readyToContinue;
+static RetainPtr&lt;WKScriptMessage&gt; lastScriptMessage;
+
+@interface StoreBlobMessageHandler : NSObject &lt;WKScriptMessageHandler&gt;
+@end
+
+@implementation StoreBlobMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+    readyToContinue = true;
+    lastScriptMessage = message;
+}
+
+@end
+
+TEST(IndexedDB, StoreBlobThenDelete)
+{
+    RetainPtr&lt;StoreBlobMessageHandler&gt; handler = adoptNS([[StoreBlobMessageHandler alloc] init]);
+    RetainPtr&lt;WKWebViewConfiguration&gt; configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@&quot;testHandler&quot;];
+
+    [configuration _setAllowUniversalAccessFromFileURLs:YES];
+
+    RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@&quot;StoreBlobToBeDeleted&quot; withExtension:@&quot;html&quot; subdirectory:@&quot;TestWebKitAPI.resources&quot;]];
+    [webView loadRequest:request];
+
+    TestWebKitAPI::Util::run(&amp;readyToContinue);
+    EXPECT_WK_STREQ(@&quot;Success&quot;, (NSString *)[lastScriptMessage body]);
+
+    NSString *blobFilePath = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/1.blob&quot; stringByExpandingTildeInPath];
+    NSString *databaseFilePath = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/IndexedDB.sqlite3&quot; stringByExpandingTildeInPath];
+
+    // The database file and blob file should definitely be there right now.
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
+    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
+
+    // Make some other .blob files in the database directory to later validate that only appropriate files are deleted.
+    NSString *otherBlob1 = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/7182.blob&quot; stringByExpandingTildeInPath];
+    NSString *otherBlob2 = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/1a.blob&quot; stringByExpandingTildeInPath];
+    NSString *otherBlob3 = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/a1.blob&quot; stringByExpandingTildeInPath];
+    NSString *otherBlob4 = [@&quot;~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/.blob&quot; stringByExpandingTildeInPath];
+    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob1 error:nil];
+    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob2 error:nil];
+    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob3 error:nil];
+    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob4 error:nil];
+
+    readyToContinue = false;
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() {
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
+
+        // Make sure the fake blob file with a valid blob file name is gone.
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob1]);
+
+        // Make sure the fake blob files with invalid blob file names are still there.
+        EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob2]);
+        EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob3]);
+        EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob4]);
+
+        // Now delete them so we're not leaving files around.
+        [[NSFileManager defaultManager] removeItemAtPath:otherBlob2 error:nil];
+        [[NSFileManager defaultManager] removeItemAtPath:otherBlob3 error:nil];
+        [[NSFileManager defaultManager] removeItemAtPath:otherBlob4 error:nil];
+
+        readyToContinue = true;
+    }];
+    TestWebKitAPI::Util::run(&amp;readyToContinue);
+}
+
+#endif
</ins></span></pre></div>
<a id="branchessafari602branchToolsTestWebKitAPITestsWebKit2CocoaStoreBlobToBeDeletedhtml"></a>
<div class="addfile"><h4>Added: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobToBeDeleted.html (0 => 203859)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobToBeDeleted.html                                (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobToBeDeleted.html        2016-07-29 07:11:05 UTC (rev 203859)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+&lt;script&gt;
+
+var dbName = &quot;StoreBlobToBeDeleted&quot;;
+var request = window.indexedDB.deleteDatabase(dbName);
+request.onsuccess = function(e)
+{
+    continueTest();
+}
+request.onerror = function(e)
+{
+    window.webkit.messageHandlers.testHandler.postMessage('Error deleting database');
+}
+
+var db;
+
+function continueTest(event)
+{
+    var request = window.indexedDB.open(dbName);
+
+    request.onupgradeneeded = function(e) {
+        db = e.target.result;
+        var objectStore = db.createObjectStore(&quot;TestStore&quot;);
+
+        const blobData = [&quot;fun &quot;, &quot;times &quot;, &quot;all &quot;, &quot;around!&quot;];
+        let blob = new Blob(blobData, { type: &quot;text/plain&quot; });
+
+        var addRequest = objectStore.add(blob, &quot;BlobKey&quot;);
+        addRequest.onerror = function() {
+            window.webkit.messageHandlers.testHandler.postMessage('Error storing blob in database');
+        }
+    }
+
+    request.onsuccess = function() {
+        db.close();
+        window.webkit.messageHandlers.testHandler.postMessage('Success');
+    }
+    request.onerror = function() {
+        window.webkit.messageHandlers.testHandler.postMessage('Error storing blob in database');
+    }
+}
+&lt;/script&gt;
</ins></span></pre>
</div>
</div>

</body>
</html>