Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit cb93440

Browse files
Sertay Senerchromium-wpt-export-bot
authored andcommitted
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/+/1807963 Reviewed-by: Joshua Bell <[email protected]> Commit-Queue: Sertay Sener <[email protected]> Cr-Commit-Position: refs/heads/master@{#704755}
1 parent 47f50fd commit cb93440

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

IndexedDB/blob-contenttype.any.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// META: title=Blob Content Type
2+
// META: script=support.js
3+
4+
indexeddb_test(
5+
function upgrade(t, db) {
6+
db.createObjectStore('store');
7+
},
8+
function success(t, db) {
9+
var type = 'x-files/trust-no-one';
10+
11+
var blob = new Blob(['mulder', 'scully'], {type: type});
12+
assert_equals(blob.type, type, 'Blob type should match constructor option');
13+
14+
var tx = db.transaction('store', 'readwrite');
15+
tx.objectStore('store').put(blob, 'key');
16+
17+
tx.oncomplete = t.step_func(function() {
18+
var tx = db.transaction('store');
19+
tx.objectStore('store').get('key').onsuccess = t.step_func(function(e) {
20+
var result = e.target.result;
21+
assert_equals(result.type, type, 'Blob type should survive round-trip');
22+
23+
var url = URL.createObjectURL(result);
24+
var xhr = new XMLHttpRequest(), async = true;
25+
xhr.open('GET', url, async);
26+
xhr.send();
27+
xhr.onreadystatechange = t.step_func(function() {
28+
if (xhr.readyState !== XMLHttpRequest.DONE)
29+
return;
30+
assert_equals(xhr.getResponseHeader('Content-Type'), type,
31+
'Blob type should be preserved when fetched');
32+
t.done();
33+
});
34+
});
35+
});
36+
},
37+
'Ensure that content type round trips when reading blob data'
38+
);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// META: title=Blob Delete Object Store
2+
// META: script=support.js
3+
4+
let key = "blob key";
5+
6+
indexeddb_test(
7+
function upgrade(t, db) {
8+
const store0 = db.createObjectStore('store0');
9+
const store1 = db.createObjectStore('store1');
10+
11+
const blobAContent = "First blob content";
12+
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
13+
14+
store0.put(blobA, key);
15+
},
16+
function success(t, db) {
17+
db.close();
18+
const request = indexedDB.open(db.name, 2);
19+
20+
request.onupgradeneeded = t.step_func(function(e) {
21+
const db = e.target.result;
22+
db.deleteObjectStore('store0');
23+
24+
request.onsuccess = t.step_func(function() {
25+
const blobBContent = "Second blob content";
26+
const trans = db.transaction('store1', 'readwrite');
27+
const store1 = trans.objectStore('store1');
28+
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
29+
store1.put(blobB, key);
30+
31+
trans.oncomplete = t.step_func(function() {
32+
db.close();
33+
const delete_request = indexedDB.deleteDatabase(db.name);
34+
35+
// The test passes if it successfully completes.
36+
delete_request.onsuccess = t.step_func_done();
37+
38+
delete_request.onerror = t.unreached_func("Request should not fail.");
39+
});
40+
41+
trans.onabort = t.unreached_func("Transaction should not be aborted.");
42+
});
43+
});
44+
request.onsuccess = t.unreached_func("Request should not succeed without an upgrade.");
45+
request.onerror = t.unreached_func("Request should not fail.");
46+
request.onblocked = t.unreached_func("Request should not be blocked.");
47+
}, "Deleting an object store and a database containing blobs doesn't crash.");
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// META: title=Blob Valid After Deletion
2+
// META: script=support.js
3+
4+
let key = "key";
5+
6+
indexeddb_test(
7+
function upgrade(t, db) {
8+
db.createObjectStore('store');
9+
},
10+
function success(t, db) {
11+
const blobAContent = "Blob A content";
12+
const blobBContent = "Blob B content";
13+
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
14+
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
15+
value = { a0: blobA, a1: blobA, b0: blobB };
16+
17+
const tx = db.transaction('store', 'readwrite');
18+
var store = tx.objectStore('store');
19+
20+
store.put(value, key);
21+
value = null;
22+
23+
const trans = db.transaction('store');
24+
store = trans.objectStore('store');
25+
const request = store.get(key);
26+
27+
request.onsuccess = t.step_func(function() {
28+
const record = request.result;
29+
30+
trans.oncomplete = t.step_func(function() {
31+
const trans = db.transaction('store', 'readwrite');
32+
store = trans.objectStore('store');
33+
const request = store.delete(key);
34+
35+
trans.oncomplete = t.step_func(function() {
36+
const promise1 = record.a0.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
37+
t.unreached_func()));
38+
39+
const promise2 = record.a1.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
40+
t.unreached_func()));
41+
42+
const promise3 = record.b0.text().then(t.step_func(text => { assert_equals(text, blobBContent); },
43+
t.unreached_func()));
44+
45+
Promise.all([promise1, promise2, promise3]).then(function() {
46+
// The test passes if it successfully completes.
47+
t.done();
48+
});
49+
});
50+
});
51+
});
52+
},
53+
"Blobs stay alive after their records are deleted.");
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// META: title=Blob Valid Before Commit
2+
// META: script=support.js
3+
4+
let key = "key";
5+
6+
indexeddb_test(
7+
function upgrade(t, db) {
8+
db.createObjectStore('store');
9+
},
10+
function success(t, db) {
11+
const blobAContent = "Blob A content";
12+
const blobBContent = "Blob B content";
13+
const blobA = new Blob([blobAContent], {"type" : "text/plain"});
14+
const blobB = new Blob([blobBContent], {"type" : "text/plain"});
15+
const value = { a0: blobA, a1: blobA, b0: blobB };
16+
17+
const tx = db.transaction('store', 'readwrite');
18+
const store = tx.objectStore('store');
19+
20+
store.put(value, key);
21+
const request = store.get(key);
22+
23+
request.onsuccess = t.step_func(function() {
24+
const record = request.result;
25+
26+
const promise1 = record.a0.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
27+
t.unreached_func()));
28+
29+
const promise2 = record.a1.text().then(t.step_func(text => { assert_equals(text, blobAContent); },
30+
t.unreached_func()));
31+
32+
const promise3 = record.b0.text().then(t.step_func(text => { assert_equals(text, blobBContent); },
33+
t.unreached_func()));
34+
35+
Promise.all([promise1, promise2, promise3]).then(function() {
36+
// The test passes if it successfully completes.
37+
t.done();
38+
});
39+
});
40+
},
41+
"Blobs can be read back before their records are committed.");

0 commit comments

Comments
 (0)