OLD | NEW |
| (Empty) |
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. | |
4 | |
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; | |
11 }; | |
12 fileWriter.onwriteend = function(e) { | |
13 if (failedInTruncate) { | |
14 fail(e.currentTarget.error); | |
15 } else { | |
16 done(); | |
17 } | |
18 }; | |
19 fileWriter.truncate(2500 * 1024); | |
20 }, unexpectedErrorCallback) | |
21 }, function(e) { fail('Open for 2nd truncate:' + fileErrorToString(e)); } ); | |
22 } | |
23 | |
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; | |
31 }; | |
32 fileWriter.onwriteend = function() { | |
33 if (failedInTruncate) { | |
34 truncateFailByQuota(fs); | |
35 } else { | |
36 fail('Unexpectedly succeeded to truncate. It should fail by quota.'); | |
37 } | |
38 }; | |
39 fileWriter.truncate(10000 * 1024); | |
40 }, unexpectedErrorCallback) | |
41 }, function(e) { fail('Open for 1st truncate:' + fileErrorToString(e)); } ); | |
42 } | |
43 | |
44 function quotaSuccess(usage, quota) { | |
45 if (usage != 0) | |
46 fail('Usage is not zero: ' + usage); | |
47 if (quota != 5000 * 1024) | |
48 fail('Quota is not 5000KiB: ' + quota); | |
49 | |
50 window.webkitRequestFileSystem( | |
51 window.TEMPORARY, | |
52 1024 * 1024, | |
53 requestFileSystemSuccess, | |
54 unexpectedErrorCallback); | |
55 } | |
56 | |
57 function test() { | |
58 if (window.webkitStorageInfo) { | |
59 debug('Querying usage and quota.'); | |
60 webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY, | |
61 quotaSuccess, | |
62 unexpectedErrorCallback); | |
63 } else { | |
64 debug('This test requires window.webkitStorageInfo.'); | |
65 } | |
66 } | |
OLD | NEW |