Commit d52a9d07 authored by Sertay Sener's avatar Sertay Sener Committed by Commit Bot

Port IndexedDB Blob Web Tests to web-platform-tests.

This CL ports the Blob related IndexedDB Web Tests to WPT tests.

Bug: 866164

Change-Id: Ie2b1b6ddc0c1ddbbb92478a2d5c81bd669c30e45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807963Reviewed-by: default avatarJoshua Bell <jsbell@chromium.org>
Commit-Queue: Sertay Sener <sesener@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#704755}
parent 2daa348c
<!DOCTYPE html> // META: title=Blob Content Type
<script src="../../resources/testharness.js"></script> // META: script=support.js
<script src="../../resources/testharnessreport.js"></script>
<script>
function indexeddb_test(upgrade_func, body_func, description) {
async_test(function(t) {
var dbname = location.pathname + ' - ' + description;
var deleteRequest = indexedDB.deleteDatabase(dbname);
deleteRequest.onsuccess = t.step_func(function() {
var openRequest = indexedDB.open(dbname);
openRequest.onupgradeneeded = t.step_func(function() {
upgrade_func(t, openRequest.result);
});
openRequest.onsuccess = t.step_func(function() {
body_func(t, openRequest.result);
});
openRequest.onerror = t.unreached_func('open failed');
});
}, description);
}
indexeddb_test( indexeddb_test(
function upgrade(t, db) { function upgrade(t, db) {
...@@ -54,6 +35,4 @@ indexeddb_test( ...@@ -54,6 +35,4 @@ indexeddb_test(
}); });
}, },
'Ensure that content type round trips when reading blob data' 'Ensure that content type round trips when reading blob data'
); );
\ No newline at end of file
</script>
// META: title=Blob Delete Object Store
// META: script=support.js
let key = "blob key";
indexeddb_test(
function upgrade(t, db) {
const store0 = db.createObjectStore('store0');
const store1 = db.createObjectStore('store1');
const blobAContent = "First blob content";
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
store0.put(blobA, key);
},
function success(t, db) {
db.close();
const request = indexedDB.open(db.name, 2);
request.onupgradeneeded = t.step_func(function(e) {
const db = e.target.result;
db.deleteObjectStore('store0');
request.onsuccess = t.step_func(function() {
const blobBContent = "Second blob content";
const trans = db.transaction('store1', 'readwrite');
const store1 = trans.objectStore('store1');
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
store1.put(blobB, key);
trans.oncomplete = t.step_func(function() {
db.close();
const delete_request = indexedDB.deleteDatabase(db.name);
// The test passes if it successfully completes.
delete_request.onsuccess = t.step_func_done();
delete_request.onerror = t.unreached_func("Request should not fail.");
});
trans.onabort = t.unreached_func("Transaction should not be aborted.");
});
});
request.onsuccess = t.unreached_func("Request should not succeed without an upgrade.");
request.onerror = t.unreached_func("Request should not fail.");
request.onblocked = t.unreached_func("Request should not be blocked.");
}, "Deleting an object store and a database containing blobs doesn't crash.");
// META: title=Blob Valid After Deletion
// META: script=support.js
let key = "key";
indexeddb_test(
function upgrade(t, db) {
db.createObjectStore('store');
},
function success(t, db) {
const blobAContent = "Blob A content";
const blobBContent = "Blob B content";
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
value = { a0: blobA, a1: blobA, b0: blobB };
const tx = db.transaction('store', 'readwrite');
var store = tx.objectStore('store');
store.put(value, key);
value = null;
const trans = db.transaction('store');
store = trans.objectStore('store');
const request = store.get(key);
request.onsuccess = t.step_func(function() {
const record = request.result;
trans.oncomplete = t.step_func(function() {
const trans = db.transaction('store', 'readwrite');
store = trans.objectStore('store');
const request = store.delete(key);
trans.oncomplete = t.step_func(function() {
const promise1 = record.a0.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
t.unreached_func()));
const promise2 = record.a1.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
t.unreached_func()));
const promise3 = record.b0.text().then(t.step_func(text => { assert_equals(text, blobBContent); },
t.unreached_func()));
Promise.all([promise1, promise2, promise3]).then(function() {
// The test passes if it successfully completes.
t.done();
});
});
});
});
},
"Blobs stay alive after their records are deleted.");
\ No newline at end of file
// META: title=Blob Valid Before Commit
// META: script=support.js
let key = "key";
indexeddb_test(
function upgrade(t, db) {
db.createObjectStore('store');
},
function success(t, db) {
const blobAContent = "Blob A content";
const blobBContent = "Blob B content";
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
const value = { a0: blobA, a1: blobA, b0: blobB };
const tx = db.transaction('store', 'readwrite');
const store = tx.objectStore('store');
store.put(value, key);
const request = store.get(key);
request.onsuccess = t.step_func(function() {
const record = request.result;
const promise1 = record.a0.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
t.unreached_func()));
const promise2 = record.a1.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
t.unreached_func()));
const promise3 = record.b0.text().then(t.step_func(text => { assert_equals(text, blobBContent); },
t.unreached_func()));
Promise.all([promise1, promise2, promise3]).then(function() {
// The test passes if it successfully completes.
t.done();
});
});
},
"Blobs can be read back before their records are committed.");
\ No newline at end of file
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<input type="file" id="fileInput" multiple></input> <input type="file" id="fileInput" multiple></input>
<script> <script>
// This test cannot be a WPT because it uses the Blink specific APIs to
// automate file drag/drop.
description("Confirm basic Blob/File/FileList functionality."); description("Confirm basic Blob/File/FileList functionality.");
fileInput = document.getElementById("fileInput"); fileInput = document.getElementById("fileInput");
......
Confirm that blobs stay alive after their records are deleted.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
dbname = "blob-valid-after-deletion.html"
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store')
store.put(value, key)
doRead():
trans = db.transaction('store')
store = trans.objectStore('store')
request = store.get(key)
trans = db.transaction('store', 'readwrite')
store = trans.objectStore('store')
request = store.delete(key)
PASS document.getElementById('frame0').contentDocument.body.innerText is blobAContent
PASS document.getElementById('frame1').contentDocument.body.innerText is blobAContent
PASS document.getElementById('frame2').contentDocument.body.innerText is blobBContent
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<iframe id="frame0"></iframe>
<iframe id="frame1"></iframe>
<iframe id="frame2"></iframe>
<script>
description("Confirm that blobs stay alive after their records are deleted.");
indexedDBTest(prepareDatabase, doRead);
function prepareDatabase()
{
db = event.target.result;
event.target.transaction.onabort = unexpectedAbortCallback;
evalAndLog("store = db.createObjectStore('store')");
blobAContent = "Blob A content";
blobBContent = "Blob B content";
var blobA = new Blob([blobAContent], {"type" : "text/plain"});
var blobB = new Blob([blobBContent], {"type" : "text/plain"});
key = "key"
value = { a0: blobA, a1: blobA, b0: blobB };
evalAndLog("store.put(value, key)");
value = null;
}
function doRead()
{
preamble();
evalAndLog("trans = db.transaction('store')");
evalAndLog("store = trans.objectStore('store')");
evalAndLog("request = store.get(key)");
request.onsuccess = didRead;
}
function didRead()
{
record = request.result;
trans.oncomplete = doDelete;
}
function doDelete()
{
evalAndLog("trans = db.transaction('store', 'readwrite')");
evalAndLog("store = trans.objectStore('store')");
evalAndLog("request = store.delete(key)");
trans.oncomplete = didDelete;
}
function didDelete()
{
urlA0 = URL.createObjectURL(record.a0);
urlA1 = URL.createObjectURL(record.a1);
urlB = URL.createObjectURL(record.b0);
document.getElementById('frame0').src = urlA0;
document.getElementById('frame0').onload = verification;
document.getElementById('frame1').src = urlA1;
document.getElementById('frame1').onload = verification;
document.getElementById('frame2').src = urlB;
document.getElementById('frame2').onload = verification;
}
var loadCount = 0;
function verification()
{
if (++loadCount < 3)
return;
URL.revokeObjectURL(urlA0);
URL.revokeObjectURL(urlA1);
URL.revokeObjectURL(urlB);
shouldBe("document.getElementById('frame0').contentDocument.body.innerText",
"blobAContent");
shouldBe("document.getElementById('frame1').contentDocument.body.innerText",
"blobAContent");
shouldBe("document.getElementById('frame2').contentDocument.body.innerText",
"blobBContent");
finishJSTest();
}
</script>
</body>
</html>
Confirm that blobs can be read back before their records are committed.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
dbname = "blob-valid-before-commit.html"
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('store')
store.put(value, key)
request = store.get(key)
PASS document.getElementById('frame0').contentDocument.body.innerText is blobAContent
PASS document.getElementById('frame1').contentDocument.body.innerText is blobAContent
PASS document.getElementById('frame2').contentDocument.body.innerText is blobBContent
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<iframe id="frame0"></iframe>
<iframe id="frame1"></iframe>
<iframe id="frame2"></iframe>
<script>
description("Confirm that blobs can be read back before their records are committed.");
indexedDBTest(prepareDatabase);
function prepareDatabase()
{
db = event.target.result;
event.target.transaction.onabort = unexpectedAbortCallback;
evalAndLog("store = db.createObjectStore('store')");
blobAContent = "Blob A content";
blobBContent = "Blob B content";
var blobA = new Blob([blobAContent], {"type" : "text/plain"});
var blobB = new Blob([blobBContent], {"type" : "text/plain"});
key = "key"
value = { a0: blobA, a1: blobA, b0: blobB };
evalAndLog("store.put(value, key)");
evalAndLog("request = store.get(key)");
request.onsuccess = didRead;
}
function didRead()
{
record = request.result;
urlA0 = URL.createObjectURL(record.a0);
urlA1 = URL.createObjectURL(record.a1);
urlB = URL.createObjectURL(record.b0);
document.getElementById('frame0').src = urlA0;
document.getElementById('frame0').onload = verification;
document.getElementById('frame1').src = urlA1;
document.getElementById('frame1').onload = verification;
document.getElementById('frame2').src = urlB;
document.getElementById('frame2').onload = verification;
}
var loadCount = 0;
function verification()
{
if (++loadCount < 3)
return;
URL.revokeObjectURL(urlA0);
URL.revokeObjectURL(urlA1);
URL.revokeObjectURL(urlB);
shouldBe("document.getElementById('frame0').contentDocument.body.innerText",
"blobAContent");
shouldBe("document.getElementById('frame1').contentDocument.body.innerText",
"blobAContent");
shouldBe("document.getElementById('frame2').contentDocument.body.innerText",
"blobBContent");
finishJSTest();
}
</script>
</body>
</html>
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
<input type="file" id="emptyFileListInput" multiple></input> <input type="file" id="emptyFileListInput" multiple></input>
<script> <script>
// This test cannot be a WPT because it uses the Blink specific APIs to
// automate file drag/drop.
description("Confirm that IndexedDB can store an empty Blob/File/FileList"); description("Confirm that IndexedDB can store an empty Blob/File/FileList");
var emptyFileInput = document.getElementById("emptyFileInput"); var emptyFileInput = document.getElementById("emptyFileInput");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment