blob: 6d47657be7f35e9d431c531b68388c7ee153377e [file] [log] [blame]
if (this.importScripts) {
importScripts('../../../resources/js-test.js');
importScripts('shared.js');
}
description("Confirm Blob/File/FileList limitations of WebKit's IndexedDB implementation.");
// FIXME: This verifies that blob-type data is rejected for now, rather than silently failing.
// Tracked for the Chromium port as: http://crbug.com/108012
fileInput = document.getElementById("fileInput");
if (window.eventSender) {
var fileRect = fileInput.getClientRects()[0];
var targetX = fileRect.left + fileRect.width / 2;
var targetY = fileRect.top + fileRect.height / 2;
eventSender.beginDragWithFiles(['resources/test-data.html', 'resources/test-data.txt']);
eventSender.mouseMoveTo(targetX, targetY);
eventSender.mouseUp();
}
function prepareDatabase()
{
db = event.target.result;
var trans = event.target.transaction;
evalAndLog("store = db.createObjectStore('storeName')");
evalAndLog("store.put('value', 'key')");
trans.onerror = unexpectedErrorCallback;
trans.onabort = unexpectedAbortCallback;
}
function testBlob()
{
debug("");
debug("testBlob():");
shouldBeTrue("FileReader != null");
evalAndLog("test_content = 'This is a test. This is only a test.'");
evalAndLog("blob = new Blob([test_content])");
validateExceptions("blob", testFile);
}
function testFile()
{
debug("");
debug("testFile():");
evalAndLog("file = fileInput.files[0]");
validateExceptions("file", testFileList);
}
function testFileList()
{
debug("");
debug("testFileList():");
evalAndLog("filelist = fileInput.files");
validateExceptions("filelist", finishJSTest);
}
function validateExceptions(variable, onComplete)
{
debug("");
debug("validateExceptions(" + variable + "):");
evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
evalAndLog("store = transaction.objectStore('storeName')");
evalAndExpectException("store.put(" + variable + ", 'key')", "DOMException.DATA_CLONE_ERR");
evalAndExpectException("store.add(" + variable + ", 'key')", "DOMException.DATA_CLONE_ERR");
evalAndLog("request = store.openCursor()");
request.onsuccess = function () {
evalAndLog("cursor = request.result");
evalAndExpectException("cursor.update(" + variable + ")", "DOMException.DATA_CLONE_ERR");
};
transaction.oncomplete = onComplete;
}
if (window.eventSender) {
indexedDBTest(prepareDatabase, testBlob);
} else {
alert("Select file(s) using the input control above to initiate the test");
document.getElementById("fileInput").onchange = function() { indexedDBTest(prepareDatabase, testBlob); };
}