<!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>[193784] trunk</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/193784">193784</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2015-12-08 14:12:34 -0800 (Tue, 08 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Fire blocked events for upgrade requests that are blocked.
https://bugs.webkit.org/show_bug.cgi?id=152007

Reviewed by Alex Christensen.

Source/WebCore:

Test: storage/indexeddb/modern/blocked-open-db-requests.html
      And some that used to fail now pass.
      And some that used to timeout now complete.

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

* Modules/indexeddb/client/IDBDatabaseImpl.cpp:
(WebCore::IDBClient::IDBDatabase::IDBDatabase):

* Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
(WebCore::IDBClient::IDBOpenDBRequest::requestBlocked):
* Modules/indexeddb/client/IDBOpenDBRequestImpl.h:

* Modules/indexeddb/client/IDBRequestImpl.cpp:
(WebCore::IDBClient::IDBRequest::dispatchEvent):

* Modules/indexeddb/server/IDBConnectionToClient.cpp:
(WebCore::IDBServer::IDBConnectionToClient::notifyOpenDBRequestBlocked):
* Modules/indexeddb/server/IDBConnectionToClient.h:
* Modules/indexeddb/server/IDBConnectionToClientDelegate.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations): When a request that would
  result in a version change transaction is blocked by open connections, notify it.

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::notifyOpenDBRequestBlocked):
* Modules/indexeddb/shared/InProcessIDBServer.h:

LayoutTests:

* platform/mac-wk1/TestExpectations:

* storage/indexeddb/modern/blocked-open-db-requests-expected.txt: Added.
* storage/indexeddb/modern/blocked-open-db-requests.html: Added.
* storage/indexeddb/modern/resources/blocked-open-db-requests.js: Added.

* storage/indexeddb/modern/deleteobjectstore-1.html: Fix subtly broken test.
* storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html: Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk1TestExpectations">trunk/LayoutTests/platform/mac-wk1/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmoderndeleteobjectstore1html">trunk/LayoutTests/storage/indexeddb/modern/deleteobjectstore-1.html</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernidbdatabasedeleteobjectstorefailureshtml">trunk/LayoutTests/storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServercpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerh">trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBDatabaseImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBOpenDBRequestImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBOpenDBRequestImplh">trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbclientIDBRequestImplcpp">trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientcpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClienth">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientDelegateh">trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp">trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblockedopendbrequestsexpectedtxt">trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests-expected.txt</a></li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernblockedopendbrequestshtml">trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests.html</a></li>
<li>trunk/LayoutTests/storage/indexeddb/modern/resources/</li>
<li><a href="#trunkLayoutTestsstorageindexeddbmodernresourcesblockedopendbrequestsjs">trunk/LayoutTests/storage/indexeddb/modern/resources/blocked-open-db-requests.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/LayoutTests/ChangeLog        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-12-08  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Fire blocked events for upgrade requests that are blocked.
+        https://bugs.webkit.org/show_bug.cgi?id=152007
+
+        Reviewed by Alex Christensen.
+
+        * platform/mac-wk1/TestExpectations:
+
+        * storage/indexeddb/modern/blocked-open-db-requests-expected.txt: Added.
+        * storage/indexeddb/modern/blocked-open-db-requests.html: Added.
+        * storage/indexeddb/modern/resources/blocked-open-db-requests.js: Added.
+        
+        * storage/indexeddb/modern/deleteobjectstore-1.html: Fix subtly broken test.
+        * storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html: Ditto.
+        
</ins><span class="cx"> 2015-12-08  Mark Lam  &lt;mark.lam@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Polymorphic operand types for DFG and FTL div.
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/TestExpectations        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -74,6 +74,7 @@
</span><span class="cx"> storage/indexeddb/deleted-objects.html [ Skip ]
</span><span class="cx"> storage/indexeddb/dont-wedge.html [ Skip ]
</span><span class="cx"> storage/indexeddb/index-multientry.html [ Skip ]
</span><ins>+storage/indexeddb/intversion-long-queue.html [ Skip ]
</ins><span class="cx"> storage/indexeddb/intversion-two-opens-no-versions.html [ Skip ]
</span><span class="cx"> storage/indexeddb/keypath-basics.html [ Skip ]
</span><span class="cx"> storage/indexeddb/keypath-fetch-key.html [ Skip ]
</span><span class="lines">@@ -92,17 +93,10 @@
</span><span class="cx"> 
</span><span class="cx"> # IDB tests that timeout                                                               
</span><span class="cx"> storage/indexeddb/database-closepending-flag.html [ Skip ]
</span><del>-storage/indexeddb/delete-closed-database-object.html [ Skip ]
</del><span class="cx"> storage/indexeddb/deletedatabase-blocked.html [ Skip ]
</span><span class="cx"> storage/indexeddb/deletedatabase-delayed-by-versionchange.html [ Skip ] 
</span><del>-storage/indexeddb/intversion-blocked.html [ Skip ]
-storage/indexeddb/intversion-long-queue.html [ Skip ]
</del><span class="cx"> storage/indexeddb/intversion-pending-version-changes-ascending.html [ Skip ]
</span><del>-storage/indexeddb/intversion-pending-version-changes-descending.html [ Skip ]
-storage/indexeddb/intversion-pending-version-changes-same.html [ Skip ]
-storage/indexeddb/objectstore-basics.html [ Skip ]
</del><span class="cx"> storage/indexeddb/odd-strings.html [ Skip ]
</span><del>-storage/indexeddb/set_version_blocked.html [ Skip ]
</del><span class="cx"> storage/indexeddb/transaction-basics.html [ Skip ]
</span><span class="cx"> storage/indexeddb/transaction-starvation.html [ Skip ]
</span><span class="cx"> storage/indexeddb/unblocked-version-changes.html [ Skip ]
</span><span class="lines">@@ -111,7 +105,7 @@
</span><span class="cx"> storage/indexeddb/createIndex-after-failure.html [ Failure ]
</span><span class="cx"> storage/indexeddb/cursor-continue.html [ Failure ]
</span><span class="cx"> storage/indexeddb/database-deletepending-flag.html [ Failure ]
</span><del>-storage/indexeddb/database-wrapper.html [ Failure ]
</del><ins>+storage/indexeddb/delete-closed-database-object.html [ Failure ]
</ins><span class="cx"> storage/indexeddb/delete-in-upgradeneeded-close-in-open-success.html [ Failure ]
</span><span class="cx"> storage/indexeddb/delete-in-upgradeneeded-close-in-versionchange.html [ Failure ]
</span><span class="cx"> storage/indexeddb/deletedatabase-delayed-by-open-and-versionchange.html [ Failure ]
</span><span class="lines">@@ -126,12 +120,15 @@
</span><span class="cx"> storage/indexeddb/intversion-close-in-upgradeneeded.html [ Failure ]
</span><span class="cx"> storage/indexeddb/intversion-gated-on-delete.html [ Failure ]
</span><span class="cx"> storage/indexeddb/intversion-open-in-upgradeneeded.html [ Failure ]
</span><ins>+storage/indexeddb/intversion-pending-version-changes-descending.html [ Failure ]
+storage/indexeddb/intversion-pending-version-changes-same.html [ Failure ]
</ins><span class="cx"> storage/indexeddb/intversion-upgrades.html [ Failure ]
</span><span class="cx"> storage/indexeddb/key-type-array.html [ Failure ]
</span><span class="cx"> storage/indexeddb/key-type-binary.html [ Failure ]
</span><span class="cx"> storage/indexeddb/lazy-index-types.html [ Failure ]
</span><span class="cx"> storage/indexeddb/metadata.html [ Failure ]
</span><span class="cx"> storage/indexeddb/objectstore-autoincrement.html [ Failure ]
</span><ins>+storage/indexeddb/objectstore-basics.html [ Failure ]
</ins><span class="cx"> storage/indexeddb/objectstore-count.html [ Failure ]
</span><span class="cx"> storage/indexeddb/objectstore-cursor.html [ Failure ]
</span><span class="cx"> storage/indexeddb/open-ordering.html [ Failure ]
</span><span class="lines">@@ -141,7 +138,6 @@
</span><span class="cx"> storage/indexeddb/pending-version-change-stuck.html [ Failure ]
</span><span class="cx"> storage/indexeddb/properties-disabled-at-runtime.html [ Failure ]
</span><span class="cx"> storage/indexeddb/setversion-blocked-by-versionchange-close.html [ Failure ]
</span><del>-storage/indexeddb/setversion-not-blocked.html [ Failure ]
</del><span class="cx"> storage/indexeddb/transaction-scope-sequencing.html [ Failure ]
</span><span class="cx"> storage/indexeddb/version-change-abort.html [ Failure ]
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblockedopendbrequestsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests-expected.txt (0 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests-expected.txt                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests-expected.txt        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+Makes sure that an OpenDBRequest that would result in a version change is blocked because there are still open connections, it gets the blocked event. Also makes sure that request gets unblocked when the open connections close.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+indexedDB = self.indexedDB || self.webkitIndexedDB || self.mozIndexedDB || self.msIndexedDB || self.OIndexedDB;
+
+dbname = &quot;blocked-open-db-requests.html&quot;
+indexedDB.deleteDatabase(dbname)
+indexedDB.open(dbname)
+connection = event.target.result;
+connection.onversionchange = firstVersionChange;
+objectStore = connection.createObjectStore('testObjectStore');
+First version change transaction complete
+firstTransaction = connection.transaction('testObjectStore', 'readwrite');
+objectStore = firstTransaction.objectStore('testObjectStore');
+objectStorePutLoop();
+secondRequest = indexedDB.open(dbname, 2);
+secondRequest.onblocked = secondBlocked;
+secondRequest.onupgradeneeded = secondUpgradeNeeded;
+receivedVersionChange = true;
+++blockedCount
+PASS blockedEvent.oldVersion is 1
+PASS blockedEvent.newVersion is 2
+PASS blockedEvent.target.readyState is 'pending'
+2nd upgradeNeeded
+PASS blockedCount is 1
+PASS event.target.result.version is 2
+event.target.result.close();
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernblockedopendbrequestshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests.html (0 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests.html                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/blocked-open-db-requests.html        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../resources/shared.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script src=&quot;resources/blocked-open-db-requests.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmoderndeleteobjectstore1html"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/storage/indexeddb/modern/deleteobjectstore-1.html (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/deleteobjectstore-1.html        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/LayoutTests/storage/indexeddb/modern/deleteobjectstore-1.html        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -33,8 +33,8 @@
</span><span class="cx"> 
</span><span class="cx">     versionTransaction.oncomplete = function(event) {
</span><span class="cx">         alert(&quot;Initial upgrade versionchange transaction complete&quot;);
</span><ins>+        database.close();
</ins><span class="cx">         continueTest1();
</span><del>-        database.close();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     versionTransaction.onerror = function(event) {
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernidbdatabasedeleteobjectstorefailureshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/LayoutTests/storage/indexeddb/modern/idbdatabase-deleteobjectstore-failures.html        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -62,8 +62,8 @@
</span><span class="cx"> 
</span><span class="cx">     transaction.oncomplete = function(event) {
</span><span class="cx">         alert(&quot;readwrite transaction complete&quot;);
</span><ins>+        database.close();
</ins><span class="cx">         continueTest2();
</span><del>-        database.close();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     transaction.onerror = function(event) {
</span></span></pre></div>
<a id="trunkLayoutTestsstorageindexeddbmodernresourcesblockedopendbrequestsjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/storage/indexeddb/modern/resources/blocked-open-db-requests.js (0 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/storage/indexeddb/modern/resources/blocked-open-db-requests.js                                (rev 0)
+++ trunk/LayoutTests/storage/indexeddb/modern/resources/blocked-open-db-requests.js        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+description(&quot;Makes sure that an OpenDBRequest that would result in a version change is blocked because there are still open connections, it gets the blocked event. Also makes sure that request gets unblocked when the open connections close.&quot;);
+
+indexedDBTest(prepareDatabase, versionChangeSuccessCallback);
+
+blockedCount = 0;
+receivedVersionChange = false;
+function prepareDatabase()
+{
+    evalAndLog(&quot;connection = event.target.result;&quot;);
+    evalAndLog(&quot;connection.onversionchange = firstVersionChange;&quot;);
+    evalAndLog(&quot;objectStore = connection.createObjectStore('testObjectStore');&quot;);
+}
+
+function versionChangeSuccessCallback()
+{
+    debug(&quot;First version change transaction complete&quot;);
+    evalAndLog(&quot;firstTransaction = connection.transaction('testObjectStore', 'readwrite');&quot;);
+    evalAndLog(&quot;objectStore = firstTransaction.objectStore('testObjectStore');&quot;);
+    evalAndLog(&quot;objectStorePutLoop();&quot;);
+
+    evalAndLog(&quot;secondRequest = indexedDB.open(dbname, 2);&quot;);
+    evalAndLog(&quot;secondRequest.onblocked = secondBlocked;&quot;);
+    evalAndLog(&quot;secondRequest.onupgradeneeded = secondUpgradeNeeded;&quot;);
+}
+
+function firstVersionChange()
+{
+    evalAndLog(&quot;receivedVersionChange = true;&quot;);
+}
+
+function objectStorePutLoop()
+{
+    if (blockedCount == 1 &amp;&amp; receivedVersionChange) {
+        connection.close();
+        return;
+    }
+
+    request = objectStore.put(&quot;bar&quot;, &quot;foo&quot;);
+    request.onsuccess = objectStorePutLoop;
+}
+
+function secondBlocked()
+{
+    evalAndLog(&quot;++blockedCount&quot;);
+    blockedEvent = event;
+    shouldBe(&quot;blockedEvent.oldVersion&quot;, &quot;1&quot;);
+    shouldBe(&quot;blockedEvent.newVersion&quot;, &quot;2&quot;);
+    shouldEvaluateTo(&quot;blockedEvent.target.readyState&quot;, &quot;'pending'&quot;);
+}
+
+function secondUpgradeNeeded()
+{
+    debug(&quot;2nd upgradeNeeded&quot;);
+    shouldBe(&quot;blockedCount&quot;, &quot;1&quot;);
+    shouldBe(&quot;event.target.result.version&quot;, &quot;2&quot;);
+    evalAndLog(&quot;event.target.result.close();&quot;);
+    finishJSTest();
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/ChangeLog        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2015-12-08  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Fire blocked events for upgrade requests that are blocked.
+        https://bugs.webkit.org/show_bug.cgi?id=152007
+
+        Reviewed by Alex Christensen.
+
+        Test: storage/indexeddb/modern/blocked-open-db-requests.html
+              And some that used to fail now pass.
+              And some that used to timeout now complete.
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::notifyOpenDBRequestBlocked):
+        * Modules/indexeddb/client/IDBConnectionToServer.h:
+
+        * Modules/indexeddb/client/IDBDatabaseImpl.cpp:
+        (WebCore::IDBClient::IDBDatabase::IDBDatabase):
+
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBOpenDBRequest::requestBlocked):
+        * Modules/indexeddb/client/IDBOpenDBRequestImpl.h:
+
+        * Modules/indexeddb/client/IDBRequestImpl.cpp:
+        (WebCore::IDBClient::IDBRequest::dispatchEvent):
+
+        * Modules/indexeddb/server/IDBConnectionToClient.cpp:
+        (WebCore::IDBServer::IDBConnectionToClient::notifyOpenDBRequestBlocked):
+        * Modules/indexeddb/server/IDBConnectionToClient.h:
+        * Modules/indexeddb/server/IDBConnectionToClientDelegate.h:
+
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::handleOpenDatabaseOperations): When a request that would
+          result in a version change transaction is blocked by open connections, notify it.
+
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::notifyOpenDBRequestBlocked):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
</ins><span class="cx"> 2015-12-08  Per Arne Vollan  &lt;peavo@outlook.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WinCairo] Compile error.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -331,6 +331,16 @@
</span><span class="cx">     transaction-&gt;didStart(error);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBConnectionToServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
+{
+    LOG(IndexedDB, &quot;IDBConnectionToServer::didStartTransaction&quot;);
+
+    auto openDBRequest = m_openDBRequestMap.get(requestIdentifier);
+    ASSERT(openDBRequest);
+
+    openDBRequest-&gt;requestBlocked(oldVersion, newVersion);
+}
+
</ins><span class="cx"> void IDBConnectionToServer::databaseConnectionClosed(IDBDatabase&amp; database)
</span><span class="cx"> {
</span><span class="cx">     LOG(IndexedDB, &quot;IDBConnectionToServer::databaseConnectionClosed&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBConnectionToServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.h        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -103,6 +103,7 @@
</span><span class="cx"> 
</span><span class="cx">     void fireVersionChangeEvent(uint64_t databaseConnectionIdentifier, uint64_t requestedVersion);
</span><span class="cx">     void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;);
</span><ins>+    void notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
</ins><span class="cx"> 
</span><span class="cx">     void establishTransaction(IDBTransaction&amp;);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBDatabaseImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBDatabaseImpl.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx">     , m_info(resultData.databaseInfo())
</span><span class="cx">     , m_databaseConnectionIdentifier(resultData.databaseConnectionIdentifier())
</span><span class="cx"> {
</span><ins>+    LOG(IndexedDB, &quot;IDBDatabase::IDBDatabase - Creating database %s with version %&quot; PRIu64, m_info.name().utf8().data(), m_info.version());
</ins><span class="cx">     suspendIfNeeded();
</span><span class="cx">     relaxAdoptionRequirement();
</span><span class="cx">     m_serverConnection-&gt;registerDatabaseConnection(*this);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBOpenDBRequestImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -168,6 +168,12 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBOpenDBRequest::requestBlocked(uint64_t oldVersion, uint64_t newVersion)
+{
+    LOG(IndexedDB, &quot;IDBOpenDBRequest::requestBlocked&quot;);
+    enqueueEvent(IDBVersionChangeEvent::create(oldVersion, newVersion, eventNames().blockedEvent));
+}
+
</ins><span class="cx"> } // namespace IDBClient
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBOpenDBRequestImplh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBOpenDBRequestImpl.h        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx">     uint64_t version() const { return m_version; }
</span><span class="cx"> 
</span><span class="cx">     void requestCompleted(const IDBResultData&amp;);
</span><ins>+    void requestBlocked(uint64_t oldVersion, uint64_t newVersion);
</ins><span class="cx"> 
</span><span class="cx">     void versionChangeTransactionWillFinish();
</span><span class="cx">     void fireSuccessAfterVersionChangeCommit();
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbclientIDBRequestImplcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBRequestImpl.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -281,10 +281,10 @@
</span><span class="cx">     // IDBEventDispatcher::dispatch() might have set the pending activity flag back to true, suggesting the request will be reused.
</span><span class="cx">     // We might also re-use the request if this event was the upgradeneeded event for an IDBOpenDBRequest.
</span><span class="cx">     if (!m_hasPendingActivity)
</span><del>-        m_hasPendingActivity = isOpenDBRequest() &amp;&amp; event.type() == eventNames().upgradeneededEvent;
</del><ins>+        m_hasPendingActivity = isOpenDBRequest() &amp;&amp; (event.type() == eventNames().upgradeneededEvent || event.type() == eventNames().blockedEvent);
</ins><span class="cx"> 
</span><del>-    // The request should only remain in the transaction's request list if it represents a pending cursor operation.
-    if (m_transaction &amp;&amp; !m_pendingCursor)
</del><ins>+    // The request should only remain in the transaction's request list if it represents a pending cursor operation, or this is an open request that was blocked.
+    if (m_transaction &amp;&amp; !m_pendingCursor &amp;&amp; event.type() != eventNames().blockedEvent)
</ins><span class="cx">         m_transaction-&gt;removeRequest(*this);
</span><span class="cx"> 
</span><span class="cx">     if (dontPreventDefault &amp;&amp; event.type() == eventNames().errorEvent &amp;&amp; m_transaction &amp;&amp; !m_transaction-&gt;isFinishedOrFinishing()) {
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -133,6 +133,11 @@
</span><span class="cx">     m_delegate-&gt;didStartTransaction(transactionIdentifier, error);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void IDBConnectionToClient::notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
+{
+    m_delegate-&gt;notifyOpenDBRequestBlocked(requestIdentifier, oldVersion, newVersion);
+}
+
</ins><span class="cx"> } // namespace IDBServer
</span><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -67,6 +67,8 @@
</span><span class="cx">     void fireVersionChangeEvent(UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion);
</span><span class="cx">     void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;);
</span><span class="cx"> 
</span><ins>+    void notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion);
+
</ins><span class="cx"> private:
</span><span class="cx">     IDBConnectionToClient(IDBConnectionToClientDelegate&amp;);
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBConnectionToClientDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClientDelegate.h        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -62,6 +62,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void fireVersionChangeEvent(UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion) = 0;
</span><span class="cx">     virtual void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;) = 0;
</span><ins>+    virtual void notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion) = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual void ref() = 0;
</span><span class="cx">     virtual void deref() = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -170,6 +170,9 @@
</span><span class="cx"> 
</span><span class="cx">     // Otherwise we have to notify all those open connections and wait for them to close.
</span><span class="cx">     notifyConnectionsOfVersionChangeForUpgrade();
</span><ins>+
+    // And we notify this OpenDBRequest that it is blocked until those connections close.
+    m_versionChangeDatabaseConnection-&gt;connectionToClient().notifyOpenDBRequestBlocked(m_versionChangeOperation-&gt;requestData().requestIdentifier(), m_databaseInfo-&gt;version(), requestedVersion);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool UniqueIDBDatabase::hasAnyOpenConnections() const
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -345,6 +345,14 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InProcessIDBServer::notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion)
+{
+    RefPtr&lt;InProcessIDBServer&gt; self(this);
+    RunLoop::current().dispatch([this, self, requestIdentifier, oldVersion, newVersion] {
+        m_connectionToServer-&gt;notifyOpenDBRequestBlocked(requestIdentifier, oldVersion, newVersion);
+    });
+}
+
</ins><span class="cx"> void InProcessIDBServer::databaseConnectionClosed(uint64_t databaseConnectionIdentifier)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;InProcessIDBServer&gt; self(this);
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h (193783 => 193784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2015-12-08 21:49:26 UTC (rev 193783)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2015-12-08 22:12:34 UTC (rev 193784)
</span><span class="lines">@@ -91,6 +91,7 @@
</span><span class="cx">     virtual void didIterateCursor(const IDBResultData&amp;) override final;
</span><span class="cx">     virtual void fireVersionChangeEvent(IDBServer::UniqueIDBDatabaseConnection&amp;, uint64_t requestedVersion) override final;
</span><span class="cx">     virtual void didStartTransaction(const IDBResourceIdentifier&amp; transactionIdentifier, const IDBError&amp;) override final;
</span><ins>+    virtual void notifyOpenDBRequestBlocked(const IDBResourceIdentifier&amp; requestIdentifier, uint64_t oldVersion, uint64_t newVersion) override final;
</ins><span class="cx"> 
</span><span class="cx">     virtual void ref() override { RefCounted&lt;InProcessIDBServer&gt;::ref(); }
</span><span class="cx">     virtual void deref() override { RefCounted&lt;InProcessIDBServer&gt;::deref(); }
</span></span></pre>
</div>
</div>

</body>
</html>