1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function truncateFailByQuota(fs) {
6 fs.root.getFile('fd', {create: false, exclusive: false}, function(fileEntry) {
7 fileEntry.createWriter(function(fileWriter) {
8 var failedInTruncate = false;
9 fileWriter.onerror = function(e) {
10 failedInTruncate = true;
12 fileWriter.onwriteend = function(e) {
13 if (failedInTruncate) {
14 fail(e.currentTarget.error);
19 fileWriter.truncate(2500 * 1024);
20 }, unexpectedErrorCallback)
21 }, function(e) { fail('Open for 2nd truncate:' + fileErrorToString(e)); } );
24 function requestFileSystemSuccess(fs) {
25 fs.root.getFile('fd', {create: true, exclusive: false}, function(fileEntry) {
26 fileEntry.createWriter(function(fileWriter) {
27 var failedInTruncate = false;
28 fileWriter.onerror = function(e) {
29 debug(e.currentTarget.error);
30 failedInTruncate = true;
32 fileWriter.onwriteend = function() {
33 if (failedInTruncate) {
34 truncateFailByQuota(fs);
36 fail('Unexpectedly succeeded to truncate. It should fail by quota.');
39 fileWriter.truncate(10000 * 1024);
40 }, unexpectedErrorCallback)
41 }, function(e) { fail('Open for 1st truncate:' + fileErrorToString(e)); } );
44 function quotaSuccess(usage, quota) {
46 fail('Usage is not zero: ' + usage);
47 if (quota != 5000 * 1024)
48 fail('Quota is not 5000KiB: ' + quota);
50 window.webkitRequestFileSystem(
53 requestFileSystemSuccess,
54 unexpectedErrorCallback);
58 if (window.webkitStorageInfo) {
59 debug('Querying usage and quota.');
60 webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
62 unexpectedErrorCallback);
64 debug('This test requires window.webkitStorageInfo.');