Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1455)

Unified Diff: chrome/test/data/fileapi/quota_test.js

Issue 7715024: Add browser_tests for FileAPI with Quota. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/fileapi/quota_test.js
diff --git a/chrome/test/data/fileapi/quota_test.js b/chrome/test/data/fileapi/quota_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..30a1f12bf2a44caab6c3f2f6d497c879063e02f9
--- /dev/null
+++ b/chrome/test/data/fileapi/quota_test.js
@@ -0,0 +1,69 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function truncateFailByQuota(fs) {
+ fs.root.getFile('fd', {create: false, exclusive: false}, function(fileEntry) {
+ fileEntry.createWriter(function(fileWriter) {
+ var failedInTruncate = false;
+ fileWriter.onerror = function(e) {
+ failedInTruncate = true;
+ };
+ fileWriter.onwriteend = function(e) {
+ if (failedInTruncate) {
+ fail(e.currentTarget.error);
+ } else {
+ done();
+ }
+ };
+ fileWriter.truncate(2500 * 1024);
+ }, unexpectedErrorCallback)
+ }, function(e) { fail("Open"); } );
+}
+
+function requestSuccess(fs) {
+ fs.root.getFile('fd', {create: true, exclusive: false}, function(fileEntry) {
+ fileEntry.createWriter(function(fileWriter) {
+ var failedInTruncate = false;
+ fileWriter.onerror = function(e) {
+ debug(e.currentTarget.error);
+ failedInTruncate = true;
+ };
+ fileWriter.onwriteend = function() {
+ if (failedInTruncate) {
+ truncateFailByQuota(fs);
+ } else {
+ fail("No error by quota");
+ }
+ }
+ fileWriter.truncate(10000 * 1024);
+ }, unexpectedErrorCallback)
+ }, function(e) { fail("Open"); } );
+}
+
+function quotaSuccess(usage, quota) {
+ origReturnedUsage = returnedUsage = usage;
+ origReturnedQuota = returnedQuota = quota;
+ if (origReturnedUsage != 0)
+ fail("Usage is not zero: " + origReturnedUsage);
+ if (origReturnedQuota != 5000 * 1024)
+ fail("Quota is not 5000KiB: " + origReturnedQuota);
+
+ window.webkitRequestFileSystem(
+ window.TEMPORARY,
+ 1024 * 1024,
+ requestSuccess,
+ unexpectedErrorCallback);
+}
+
+function test() {
+ if (window.webkitStorageInfo) {
+ window.jsTestIsAsync = true;
+ debug('Querying usage and quota.');
+ webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
+ quotaSuccess,
+ unexpectedErrorCallback);
+ } else {
+ debug("This test requires window.webkitStorageInfo.");
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698