Bug 964561 - Part 9: Add a new test for externally stored structured clone data; r=asuth

This commit is contained in:
Jan Varga 2016-10-25 21:18:33 +02:00
parent 37e3797013
commit d1f5aaafa4
6 changed files with 164 additions and 8 deletions

View File

@ -87,7 +87,7 @@ function getNullFile(name, size)
function verifyBuffers(buffer1, buffer2)
{
ok(compareBuffers(buffer1, buffer2), "Correct blob data");
ok(compareBuffers(buffer1, buffer2), "Correct buffer data");
}
function verifyBlob(blob1, blob2, fileId, blobReadHandler)
@ -177,9 +177,14 @@ function verifyMutableFile(mutableFile1, file2)
ok(mutableFile1 instanceof IDBMutableFile, "Instance of IDBMutableFile");
is(mutableFile1.name, file2.name, "Correct name");
is(mutableFile1.type, file2.type, "Correct type");
executeSoon(function() {
testGenerator.next();
});
continueToNextStep();
}
function verifyView(view1, view2)
{
is(view1.byteLength, view2.byteLength, "Correct byteLength");
verifyBuffers(view1, view2);
continueToNextStep();
}
function grabFileUsageAndContinueHandler(request)

View File

@ -112,6 +112,7 @@ support-files =
unit/test_transaction_lifetimes_nested.js
unit/test_transaction_ordering.js
unit/test_unique_index_update.js
unit/test_view_put_get_values.js
unit/test_writer_starvation.js
[test_abort_deleted_index.html]
@ -387,5 +388,7 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_unique_index_update.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_view_put_get_values.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') # Bug 931116
[test_serviceworker.html]
skip-if = buildapp == 'b2g'

View File

@ -0,0 +1,20 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7" src="unit/test_view_put_get_values.js"></script>
<script type="text/javascript;version=1.7" src="file.js"></script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,102 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var disableWorkerTest = "Need a way to set temporary prefs from a worker";
var testGenerator = testSteps();
function testSteps()
{
const name =
this.window ? window.location.pathname : "test_view_put_get_values.js";
const objectStoreName = "Views";
const viewData = { key: 1, view: getRandomView(100000) };
for (let external of [false, true]) {
if (external) {
info("Setting data threshold pref");
if (this.window) {
SpecialPowers.pushPrefEnv(
{ "set": [["dom.indexedDB.dataThreshold", 0]] }, continueToNextStep);
yield undefined;
} else {
setDataThreshold(0);
}
}
info("Opening database");
let request = indexedDB.open(name);
request.onerror = errorHandler;
request.onupgradeneeded = continueToNextStepSync;
request.onsuccess = unexpectedSuccessHandler;
yield undefined;
// upgradeneeded
request.onupgradeneeded = unexpectedSuccessHandler;
request.onsuccess = continueToNextStepSync;
info("Creating objectStore");
request.result.createObjectStore(objectStoreName);
yield undefined;
// success
let db = request.result;
db.onerror = errorHandler;
info("Storing view");
let objectStore = db.transaction([objectStoreName], "readwrite")
.objectStore(objectStoreName);
request = objectStore.add(viewData.view, viewData.key);
request.onsuccess = continueToNextStepSync;
yield undefined;
is(request.result, viewData.key, "Got correct key");
info("Getting view");
request = objectStore.get(viewData.key);
request.onsuccess = continueToNextStepSync;
yield undefined;
verifyView(request.result, viewData.view);
yield undefined;
info("Getting view in new transaction");
request = db.transaction([objectStoreName])
.objectStore(objectStoreName).get(viewData.key);
request.onsuccess = continueToNextStepSync;
yield undefined;
verifyView(request.result, viewData.view);
yield undefined;
getUsage(grabFileUsageAndContinueHandler);
let fileUsage = yield undefined;
if (external) {
ok(fileUsage > 0, "File usage is not zero");
} else {
ok(fileUsage == 0, "File usage is zero");
}
db.close();
request = indexedDB.deleteDatabase(name);
request.onerror = errorHandler;
request.onsuccess = continueToNextStepSync;
yield undefined;
}
finishTest();
yield undefined;
}

View File

@ -380,7 +380,7 @@ function compareBuffers(buffer1, buffer2)
function verifyBuffers(buffer1, buffer2)
{
ok(compareBuffers(buffer1, buffer2), "Correct blob data");
ok(compareBuffers(buffer1, buffer2), "Correct buffer data");
}
function verifyBlob(blob1, blob2)
@ -435,9 +435,28 @@ function verifyMutableFile(mutableFile1, file2)
"Instance of IDBMutableFile");
is(mutableFile1.name, file2.name, "Correct name");
is(mutableFile1.type, file2.type, "Correct type");
executeSoon(function() {
testGenerator.next();
});
continueToNextStep();
}
function verifyView(view1, view2)
{
is(view1.byteLength, view2.byteLength, "Correct byteLength");
verifyBuffers(view1, view2);
continueToNextStep();
}
function grabFileUsageAndContinueHandler(request)
{
testGenerator.send(request.fileUsage);
}
function getUsage(usageHandler)
{
let qms = Cc["@mozilla.org/dom/quota-manager-service;1"]
.getService(Ci.nsIQuotaManagerService);
let principal = Cc["@mozilla.org/systemprincipal;1"]
.createInstance(Ci.nsIPrincipal);
qms.getUsageForPrincipal(principal, usageHandler);
}
function setTemporaryStorageLimit(limit)
@ -452,6 +471,12 @@ function setTemporaryStorageLimit(limit)
}
}
function setDataThreshold(threshold)
{
info("Setting data threshold to " + threshold);
SpecialPowers.setIntPref("dom.indexedDB.dataThreshold", threshold);
}
function getPrincipal(url)
{
let uri = Cc["@mozilla.org/network/io-service;1"]

View File

@ -58,3 +58,4 @@ skip-if = true
[test_temporary_storage.js]
# bug 951017: intermittent failure on Android x86 emulator
skip-if = os == "android" && processor == "x86"
[test_view_put_get_values.js]