[Chromium] IndexedDB: Assertion failure when storing File objects
[WebKit-https.git] / LayoutTests / storage / indexeddb / noblobs.html
1 <html>
2 <head>
3 <script src="../../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <input type="file" id="fileInput" multiple></input>
8 <p id="description"></p>
9 <div id="console"></div>
10 <script>
11
12 description("Confirm Blob/File/FileList limitations of WebKit's IndexedDB implementation.");
13 // FIXME: This verifies that blob-type data is rejected for now, rather than silently failing.
14 // Tracked for the Chromium port as: http://crbug.com/108012
15
16 fileInput = document.getElementById("fileInput");
17 if (window.eventSender) {
18     var fileRect = fileInput.getClientRects()[0];
19     var targetX = fileRect.left + fileRect.width / 2;
20     var targetY = fileRect.top + fileRect.height / 2;
21     eventSender.beginDragWithFiles(['resources/test-data.html', 'resources/test-data.txt']);
22     eventSender.mouseMoveTo(targetX, targetY);
23     eventSender.mouseUp();
24 }
25
26 function test()
27 {
28     removeVendorPrefixes();
29     prepareDatabase();
30 }
31
32 function prepareDatabase()
33 {
34     debug("");
35     debug("Prepare Database");
36     request = evalAndLog("indexedDB.deleteDatabase('noblobs')");
37     request.onerror = unexpectedErrorCallback;
38     request.onsuccess = function(e) {
39         request = evalAndLog("indexedDB.open('noblobs')");
40         request.onerror = unexpectedErrorCallback;
41         request.onsuccess = function(e) {
42             evalAndLog("db = request.result");
43             shouldBeEqualToString("db.version", "");
44             request = evalAndLog("db.setVersion('1')");
45             request.onerror = unexpectedErrorCallback;
46             request.onsuccess = function(e) {
47                 evalAndLog("store = db.createObjectStore('storeName')");
48                 evalAndLog("store.put('value', 'key')");
49                 var trans = request.result;
50                 trans.onerror = unexpectedErrorCallback;
51                 trans.onabort = unexpectedAbortCallback;
52                 trans.oncomplete = testBlob();
53             };
54         };
55     };
56 }
57
58 function testBlob()
59 {
60     debug("");
61     debug("testBlob():");
62
63     evalAndLog("BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder");
64     shouldBeTrue("BlobBuilder != null");
65     shouldBeTrue("FileReader != null");
66     evalAndLog("builder = new BlobBuilder()");
67     evalAndLog("test_content = 'This is a test. This is only a test.'");
68     evalAndLog("builder.append(test_content)");
69     evalAndLog("blob = builder.getBlob()");
70     validateExceptions("blob", testFile);
71 }
72
73 function testFile()
74 {
75     debug("");
76     debug("testFile():");
77     evalAndLog("file = fileInput.files[0]");
78     validateExceptions("file", testFileList);
79 }
80
81 function testFileList()
82 {
83     debug("");
84     debug("testFileList():");
85     evalAndLog("filelist = fileInput.files");
86     validateExceptions("filelist", finishJSTest);
87 }
88
89 function validateExceptions(variable, onComplete)
90 {
91     debug("");
92     debug("validateExceptions(" + variable + "):");
93     evalAndLog("transaction = db.transaction('storeName', IDBTransaction.READ_WRITE)");
94     evalAndLog("store = transaction.objectStore('storeName')");
95     evalAndExpectException("store.put(" + variable + ", 'key')", "DOMException.DATA_CLONE_ERR");
96     evalAndExpectException("store.add(" + variable + ", 'key')", "DOMException.DATA_CLONE_ERR");
97     evalAndLog("request = store.openCursor()");
98     request.onsuccess = function () {
99         evalAndLog("cursor = request.result");
100         evalAndExpectException("cursor.update(" + variable + ")", "DOMException.DATA_CLONE_ERR");
101     };
102     transaction.oncomplete = onComplete;
103 }
104
105 if (window.eventSender) {
106     test();
107 } else {
108     alert("Select file(s) using the input control above to initiate the test");
109     document.getElementById("fileInput").onchange = test;
110 }
111
112 </script>
113 <script src="../../fast/js/resources/js-test-post.js"></script>
114 </body>
115 </html>