summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 12:47:47 +0000
committerdmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-06 12:47:47 +0000
commitb4449206da3e3272bb7d91b16c484fc4c2f2a7d3 (patch)
tree3cc527b910e09ab8debc6154dfaa73124194aebf /chrome
parentfc0de26745758c5d90b6f386567fa6b761026421 (diff)
downloadchromium_src-b4449206da3e3272bb7d91b16c484fc4c2f2a7d3.zip
chromium_src-b4449206da3e3272bb7d91b16c484fc4c2f2a7d3.tar.gz
chromium_src-b4449206da3e3272bb7d91b16c484fc4c2f2a7d3.tar.bz2
Add browser_tests for FileAPI with Quota, and remove unlimited access for file:/// when allow_file_access_from_files.
BUG=95120 TEST=browser_tests:FileSystemBrowserTest* Review URL: http://codereview.chromium.org/7715024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/fileapi/common.js53
-rw-r--r--chrome/test/data/fileapi/create_test.html10
-rw-r--r--chrome/test/data/fileapi/create_test.js19
-rw-r--r--chrome/test/data/fileapi/quota_test.html10
-rw-r--r--chrome/test/data/fileapi/quota_test.js66
-rw-r--r--chrome/test/data/fileapi/request_test.html10
-rw-r--r--chrome/test/data/fileapi/request_test.js19
8 files changed, 188 insertions, 0 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index fc277b4..392fe3c 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2619,6 +2619,7 @@
'../content/browser/child_process_security_policy_browsertest.cc',
'../content/browser/device_orientation/device_orientation_browsertest.cc',
'../content/browser/download/mhtml_generation_browsertest.cc',
+ '../content/browser/file_system/file_system_browsertest.cc',
'../content/browser/in_process_webkit/dom_storage_browsertest.cc',
'../content/browser/in_process_webkit/indexed_db_browsertest.cc',
'../content/browser/plugin_service_browsertest.cc',
diff --git a/chrome/test/data/fileapi/common.js b/chrome/test/data/fileapi/common.js
new file mode 100644
index 0000000..3fc52df
--- /dev/null
+++ b/chrome/test/data/fileapi/common.js
@@ -0,0 +1,53 @@
+// 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 debug(message)
+{
+ document.getElementById('status').innerHTML += '<br/>' + message;
+}
+
+function done(message)
+{
+ if (document.location.hash == '#fail')
+ return;
+ if (message)
+ debug('PASS: ' + message);
+ else
+ debug('PASS');
+ document.location.hash = '#pass';
+}
+
+function fail(message)
+{
+ debug('FAILED: ' + message);
+ document.location.hash = '#fail';
+}
+
+function getLog()
+{
+ return '' + document.getElementById('status').innerHTML;
+}
+
+function fileErrorToString(e)
+{
+ switch (e.code) {
+ case FileError.QUOTA_EXCEEDED_ERR:
+ return 'QUOTA_EXCEEDED_ERR';
+ case FileError.NOT_FOUND_ERR:
+ return 'NOT_FOUND_ERR';
+ case FileError.SECURITY_ERR:
+ return 'SECURITY_ERR';
+ case FileError.INVALID_MODIFICATION_ERR:
+ return 'INVALID_MODIFICATION_ERR';
+ case FileError.INVALID_STATE_ERR:
+ return 'INVALID_STATE_ERR';
+ default:
+ return 'Unknown Error';
+ }
+}
+
+function unexpectedErrorCallback(e)
+{
+ fail('unexpectedErrorCallback:' + fileErrorToString(e));
+}
diff --git a/chrome/test/data/fileapi/create_test.html b/chrome/test/data/fileapi/create_test.html
new file mode 100644
index 0000000..5d6f1be
--- /dev/null
+++ b/chrome/test/data/fileapi/create_test.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>FileAPI create test</title>
+ <script type="text/javascript" src="common.js"></script>
+ <script type="text/javascript" src="create_test.js"></script>
+ </head>
+ <body onLoad="test()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
diff --git a/chrome/test/data/fileapi/create_test.js b/chrome/test/data/fileapi/create_test.js
new file mode 100644
index 0000000..5026bb0
--- /dev/null
+++ b/chrome/test/data/fileapi/create_test.js
@@ -0,0 +1,19 @@
+// 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 requestFileSystemSuccess(fs)
+{
+ fs.root.getFile('foo', {create: true, exclusive: false}, done,
+ function(e) { fail('Open:' + fileErrorToString(e)); } );
+}
+
+function test()
+{
+ debug('Requesting FileSystem');
+ window.webkitRequestFileSystem(
+ window.TEMPORARY,
+ 1024 * 1024,
+ requestFileSystemSuccess,
+ unexpectedErrorCallback);
+}
diff --git a/chrome/test/data/fileapi/quota_test.html b/chrome/test/data/fileapi/quota_test.html
new file mode 100644
index 0000000..8612f0ca
--- /dev/null
+++ b/chrome/test/data/fileapi/quota_test.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>FileAPI quota test</title>
+ <script type="text/javascript" src="common.js"></script>
+ <script type="text/javascript" src="quota_test.js"></script>
+ </head>
+ <body onLoad="test()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
diff --git a/chrome/test/data/fileapi/quota_test.js b/chrome/test/data/fileapi/quota_test.js
new file mode 100644
index 0000000..382d623
--- /dev/null
+++ b/chrome/test/data/fileapi/quota_test.js
@@ -0,0 +1,66 @@
+// 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 for 2nd truncate:' + fileErrorToString(e)); } );
+}
+
+function requestFileSystemSuccess(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('Unexpectedly succeeded to truncate. It should fail by quota.');
+ }
+ };
+ fileWriter.truncate(10000 * 1024);
+ }, unexpectedErrorCallback)
+ }, function(e) { fail('Open for 1st truncate:' + fileErrorToString(e)); } );
+}
+
+function quotaSuccess(usage, quota) {
+ if (usage != 0)
+ fail('Usage is not zero: ' + usage);
+ if (quota != 5000 * 1024)
+ fail('Quota is not 5000KiB: ' + quota);
+
+ window.webkitRequestFileSystem(
+ window.TEMPORARY,
+ 1024 * 1024,
+ requestFileSystemSuccess,
+ unexpectedErrorCallback);
+}
+
+function test() {
+ if (window.webkitStorageInfo) {
+ debug('Querying usage and quota.');
+ webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
+ quotaSuccess,
+ unexpectedErrorCallback);
+ } else {
+ debug('This test requires window.webkitStorageInfo.');
+ }
+}
diff --git a/chrome/test/data/fileapi/request_test.html b/chrome/test/data/fileapi/request_test.html
new file mode 100644
index 0000000..b59f704
--- /dev/null
+++ b/chrome/test/data/fileapi/request_test.html
@@ -0,0 +1,10 @@
+<html>
+ <head>
+ <title>FileAPI request test</title>
+ <script type="text/javascript" src="common.js"></script>
+ <script type="text/javascript" src="request_test.js"></script>
+ </head>
+ <body onLoad="test()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
diff --git a/chrome/test/data/fileapi/request_test.js b/chrome/test/data/fileapi/request_test.js
new file mode 100644
index 0000000..c9c26a2
--- /dev/null
+++ b/chrome/test/data/fileapi/request_test.js
@@ -0,0 +1,19 @@
+// 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 requestFileSystemSuccess(fs)
+{
+ debug('Requested successfully.');
+ done();
+}
+
+function test()
+{
+ debug('Requesting FileSystem');
+ window.webkitRequestFileSystem(
+ window.TEMPORARY,
+ 1024 * 1024,
+ requestFileSystemSuccess,
+ unexpectedErrorCallback);
+}