summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/extensions/api_test
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/test/data/extensions/api_test')
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory/manifest.json15
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory/test.html4
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory/test.js98
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory/test_util.js62
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/manifest.json13
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.html3
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.js12
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_write/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_write/manifest.json15
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.html4
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.js99
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test_util.js75
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/manifest.json13
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.html3
-rw-r--r--chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.js12
-rw-r--r--chrome/test/data/extensions/api_test/file_system/restore_directory/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/restore_directory/manifest.json11
-rw-r--r--chrome/test/data/extensions/api_test/file_system/restore_directory/test.html4
-rw-r--r--chrome/test/data/extensions/api_test/file_system/restore_directory/test.js25
-rw-r--r--chrome/test/data/extensions/api_test/file_system/restore_directory/test_util.js62
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/background.js7
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/manifest.json11
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/test.html4
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/test.js36
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.html3
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.js18
-rw-r--r--chrome/test/data/extensions/api_test/file_system/retain_directory/test_util.js62
30 files changed, 706 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory/background.js b/chrome/test/data/extensions/api_test/file_system/open_directory/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory/manifest.json b/chrome/test/data/extensions/api_test/file_system/open_directory/manifest.json
new file mode 100644
index 0000000..00d7e5a
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory/manifest.json
@@ -0,0 +1,15 @@
+{
+ "name": "chrome.fileSystem open existing directory",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.chooseEntry opening existing directory.",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [
+ {
+ "fileSystem": ["directory"]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory/test.html b/chrome/test/data/extensions/api_test/file_system/open_directory/test.html
new file mode 100644
index 0000000..d89c528
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory/test.html
@@ -0,0 +1,4 @@
+<html>
+<script src="test_util.js"></script>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory/test.js b/chrome/test/data/extensions/api_test/file_system/open_directory/test.js
new file mode 100644
index 0000000..db4a01e
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory/test.js
@@ -0,0 +1,98 @@
+// Copyright 2013 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.
+
+// Testing with directory access, but no write permission.
+chrome.test.runTests([
+ function openFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {},
+ chrome.test.callback(function(entry) {
+ checkEntry(entry, 'open_existing.txt', false, false);
+ }));
+ }));
+ },
+ function readDirectory() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ var reader = directoryEntry.createReader();
+ reader.readEntries(chrome.test.callback(function(entries) {
+ chrome.test.assertEq(entries.length, 1);
+ var entry = entries[0];
+ checkEntry(entry, 'open_existing.txt', false, false);
+ }));
+ }));
+ },
+ function removeFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {}, chrome.test.callback(function(entry) {
+ entry.remove(chrome.test.callback(function() {
+ chrome.test.fail('Could delete a file without permission');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }));
+ }));
+ }));
+ },
+ function copyFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {}, chrome.test.callback(function(entry) {
+ entry.copyTo(
+ directoryEntry, 'copy.txt', chrome.test.callback(function() {
+ chrome.test.fail('Could copy a file without permission.');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }));
+ }));
+ }));
+ },
+ function moveFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {}, chrome.test.callback(function(entry) {
+ entry.moveTo(
+ directoryEntry, 'moved.txt', chrome.test.callback(function() {
+ chrome.test.fail('Could move a file without permission.');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }));
+ }));
+ }));
+ },
+ function createFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'new.txt', {create: true}, chrome.test.callback(function() {
+ chrome.test.fail('Could create a file without permission.');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }));
+ }));
+ },
+ function createDirectory() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getDirectory(
+ 'new', {create: true}, chrome.test.callback(function() {
+ chrome.test.fail('Could create a directory without permission.');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }));
+ }));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory/test_util.js b/chrome/test/data/extensions/api_test/file_system/open_directory/test_util.js
new file mode 100644
index 0000000..a31ee51
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory/test_util.js
@@ -0,0 +1,62 @@
+// Copyright 2013 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.
+
+// This is a duplicate of the file test_util in
+// chrome/test/data/extensions/api_test/file_system
+
+function checkEntry(entry, expectedName, isNew, shouldBeWritable) {
+ chrome.test.assertEq(expectedName, entry.name);
+ // Test that the file can be read.
+ entry.file(chrome.test.callback(function(file) {
+ var reader = new FileReader();
+ reader.onloadend = chrome.test.callbackPass(function(e) {
+ if (isNew)
+ chrome.test.assertEq(reader.result, "");
+ else
+ chrome.test.assertEq(reader.result.indexOf("Can you see me?"), 0);
+ // Test that we can write to the file, or not, depending on
+ // |shouldBeWritable|.
+ entry.createWriter(function(fileWriter) {
+ fileWriter.onwriteend = chrome.test.callback(function(e) {
+ if (fileWriter.error) {
+ if (shouldBeWritable) {
+ chrome.test.fail("Error writing to file: " +
+ fileWriter.error.toString());
+ } else {
+ chrome.test.succeed();
+ }
+ } else {
+ if (shouldBeWritable) {
+ // Get a new entry and check the data got to disk.
+ chrome.fileSystem.chooseEntry(chrome.test.callbackPass(
+ function(readEntry) {
+ readEntry.file(chrome.test.callback(function(readFile) {
+ var readReader = new FileReader();
+ readReader.onloadend = function(e) {
+ chrome.test.assertEq(readReader.result.indexOf("HoHoHo!"),
+ 0);
+ chrome.test.succeed();
+ };
+ readReader.onerror = function(e) {
+ chrome.test.fail("Failed to read file after write.");
+ };
+ readReader.readAsText(readFile);
+ }));
+ }));
+ } else {
+ chrome.test.fail(
+ "'Could write to file that should not be writable.");
+ }
+ }
+ });
+ var blob = new Blob(["HoHoHo!"], {type: "text/plain"});
+ fileWriter.write(blob);
+ });
+ });
+ reader.onerror = chrome.test.callback(function(e) {
+ chrome.test.fail("Error reading file contents.");
+ });
+ reader.readAsText(file);
+ }));
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/background.js b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/manifest.json b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/manifest.json
new file mode 100644
index 0000000..4fb4662
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/manifest.json
@@ -0,0 +1,13 @@
+{
+ "name": "chrome.fileSystem open directory",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.chooseFile opening a directory.",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [
+ {"fileSystem": ["write"]}
+ ]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.html b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.html
new file mode 100644
index 0000000..8d7d1db
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.html
@@ -0,0 +1,3 @@
+<html>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.js b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.js
new file mode 100644
index 0000000..d3982b3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_only_write/test.js
@@ -0,0 +1,12 @@
+// Copyright 2013 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.
+
+chrome.test.runTests([
+ function openFile() {
+ chrome.fileSystem.chooseEntry({type: 'openDirectory'},
+ chrome.test.callbackFail(
+ 'Operation requires fileSystem.directory permission',
+ function(entry) {}));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/background.js b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/manifest.json b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/manifest.json
new file mode 100644
index 0000000..f634f5e
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/manifest.json
@@ -0,0 +1,15 @@
+{
+ "name": "chrome.fileSystem open existing directory",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.chooseEntry opening existing directory.",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [
+ {
+ "fileSystem": ["directory", "write"]
+ }
+ ]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.html b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.html
new file mode 100644
index 0000000..d89c528
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.html
@@ -0,0 +1,4 @@
+<html>
+<script src="test_util.js"></script>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.js b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.js
new file mode 100644
index 0000000..5375a80
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test.js
@@ -0,0 +1,99 @@
+// Copyright 2013 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.
+
+// Testing with directory access and write permission.
+chrome.test.runTests([
+ function moveFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {}, chrome.test.callback(function(entry) {
+ entry.copyTo(
+ directoryEntry, 'to_move.txt', chrome.test.callback(function(copy) {
+ copy.moveTo(
+ directoryEntry, 'moved.txt', chrome.test.callback(function(move) {
+ directoryEntry.getFile(
+ 'to_move.txt', {}, chrome.test.callback(function(entry) {
+ chrome.test.fail('Could open move source');
+ }), chrome.test.callback(function() {
+ checkEntry(move, 'moved.txt', false, true);
+ }));
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to move file');
+ }));
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to copy file');
+ }));
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to open file');
+ }));
+ }))
+ },
+ function copyFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'open_existing.txt', {}, chrome.test.callback(function(entry) {
+ entry.copyTo(
+ directoryEntry, 'copy.txt', chrome.test.callback(function(copy) {
+ checkEntry(copy, 'copy.txt', false, true);
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to copy file');
+ }));
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to open file');
+ }));
+ }));
+ },
+ function createFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'new.txt', {create: true}, chrome.test.callback(function(entry) {
+ checkEntry(entry, 'new.txt', true, true);
+ }), chrome.test.callback(function(err) {
+ chrome.test.fail('Failed to create file');
+ }));
+ }));
+ },
+ function createDirectory() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getDirectory(
+ 'new', {create: true}, chrome.test.callback(function(entry) {
+ chrome.test.assertEq(entry.name, 'new');
+ chrome.test.succeed();
+ }), chrome.test.callback(function(err) {
+ chrome.test.fail('Failed to create directory');
+ }));
+ }));
+ },
+ function removeFile() {
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'},
+ chrome.test.callbackPass(function(directoryEntry) {
+ directoryEntry.getFile(
+ 'remove.txt', {create: true},
+ chrome.test.callback(function(entry) {
+ entry.remove(chrome.test.callback(function() {
+ directoryEntry.getFile(
+ 'remove.txt', {},
+ chrome.test.callback(function() {
+ chrome.test.fail('Could open deleted file');
+ }), chrome.test.callback(function() {
+ chrome.test.succeed();
+ }))
+ }), chrome.test.callback(function() {
+ chrome.test.fail('Failed to delete file');
+ }));
+ }), chrome.test.callback(function(err) {
+ chrome.test.fail('Failed to create file');
+ }));
+ }));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test_util.js b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test_util.js
new file mode 100644
index 0000000..b66226d
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_with_write/test_util.js
@@ -0,0 +1,75 @@
+// Copyright 2013 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.
+
+// This is a modified duplicate of the file test_util in
+// chrome/test/data/extensions/api_test/file_system
+
+// TODO(sammc): Merge the changes back to the original test_util.js. See
+// http://crbug.com/280942.
+function checkEntry(entry, expectedName, isNew, shouldBeWritable) {
+ chrome.test.assertEq(expectedName, entry.name);
+
+ // Test that we are writable (or not), as expected.
+ chrome.fileSystem.isWritableEntry(entry, chrome.test.callbackPass(
+ function(isWritable) {
+ chrome.test.assertEq(isWritable, shouldBeWritable);
+ }));
+
+ // Test that the file can be read.
+ entry.file(chrome.test.callback(function(file) {
+ var reader = new FileReader();
+ reader.onloadend = chrome.test.callbackPass(function(e) {
+ if (isNew)
+ chrome.test.assertEq(reader.result, "");
+ else
+ chrome.test.assertEq(reader.result.indexOf("Can you see me?"), 0);
+ // Test that we can write to the file, or not, depending on
+ // |shouldBeWritable|.
+ entry.createWriter(function(fileWriter) {
+ fileWriter.onwriteend = chrome.test.callback(function(e) {
+ if (fileWriter.error) {
+ if (shouldBeWritable) {
+ chrome.test.fail("Error writing to file: " +
+ fileWriter.error.toString());
+ } else {
+ chrome.test.succeed();
+ }
+ } else {
+ if (shouldBeWritable) {
+ // Get a new entry and check the data got to disk.
+ chrome.fileSystem.chooseEntry(
+ {type: 'openDirectory'}, chrome.test.callbackPass(
+ function(directoryEntry) {
+ directoryEntry.getFile(
+ entry.name, {}, chrome.test.callback(function(readEntry) {
+ readEntry.file(chrome.test.callback(function(readFile) {
+ var readReader = new FileReader();
+ readReader.onloadend = function(e) {
+ chrome.test.assertEq(readReader.result.indexOf("HoHoHo!"),
+ 0);
+ chrome.test.succeed();
+ };
+ readReader.onerror = function(e) {
+ chrome.test.fail("Failed to read file after write.");
+ };
+ readReader.readAsText(readFile);
+ }));
+ }));
+ }));
+ } else {
+ chrome.test.fail(
+ "'Could write to file that should not be writable.");
+ }
+ }
+ });
+ var blob = new Blob(["HoHoHo!"], {type: "text/plain"});
+ fileWriter.write(blob);
+ });
+ });
+ reader.onerror = chrome.test.callback(function(e) {
+ chrome.test.fail("Error reading file contents.");
+ });
+ reader.readAsText(file);
+ }));
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/background.js b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/manifest.json b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/manifest.json
new file mode 100644
index 0000000..b8758b5
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/manifest.json
@@ -0,0 +1,13 @@
+{
+ "name": "chrome.fileSystem open directory",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.chooseFile opening a directory.",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [
+ {"fileSystem": []}
+ ]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.html b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.html
new file mode 100644
index 0000000..8d7d1db
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.html
@@ -0,0 +1,3 @@
+<html>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.js b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.js
new file mode 100644
index 0000000..d3982b3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/open_directory_without_permission/test.js
@@ -0,0 +1,12 @@
+// Copyright 2013 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.
+
+chrome.test.runTests([
+ function openFile() {
+ chrome.fileSystem.chooseEntry({type: 'openDirectory'},
+ chrome.test.callbackFail(
+ 'Operation requires fileSystem.directory permission',
+ function(entry) {}));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/restore_directory/background.js b/chrome/test/data/extensions/api_test/file_system/restore_directory/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/restore_directory/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/restore_directory/manifest.json b/chrome/test/data/extensions/api_test/file_system/restore_directory/manifest.json
new file mode 100644
index 0000000..afa32cd
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/restore_directory/manifest.json
@@ -0,0 +1,11 @@
+{
+ "name": "chrome.fileSystem.restoreEntry test",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.restoreEntry",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [{"fileSystem": ["write", "directory"]}]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/restore_directory/test.html b/chrome/test/data/extensions/api_test/file_system/restore_directory/test.html
new file mode 100644
index 0000000..d89c528
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/restore_directory/test.html
@@ -0,0 +1,4 @@
+<html>
+<script src="test_util.js"></script>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/restore_directory/test.js b/chrome/test/data/extensions/api_test/file_system/restore_directory/test.js
new file mode 100644
index 0000000..4084332
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/restore_directory/test.js
@@ -0,0 +1,25 @@
+// Copyright 2013 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.
+
+chrome.test.runTests([
+ function restoreEntryWorks() {
+ var id = 'magic id';
+ chrome.fileSystem.isRestorable(id, chrome.test.callbackPass(
+ function(isRestorable) {
+ chrome.test.assertTrue(isRestorable);
+ }));
+ chrome.fileSystem.restoreEntry(id, chrome.test.callbackPass(
+ function(restoredEntry) {
+ chrome.test.assertTrue(restoredEntry != null);
+ chrome.test.assertTrue(restoredEntry.isDirectory);
+ chrome.test.assertEq(
+ chrome.fileSystem.retainEntry(restoredEntry), id);
+ restoredEntry.getFile(
+ 'writable.txt', {}, chrome.test.callback(function(entry) {
+ checkEntry(entry, 'writable.txt', false /* isNew */,
+ true /*shouldBeWritable */);
+ }));
+ }));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/restore_directory/test_util.js b/chrome/test/data/extensions/api_test/file_system/restore_directory/test_util.js
new file mode 100644
index 0000000..a31ee51
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/restore_directory/test_util.js
@@ -0,0 +1,62 @@
+// Copyright 2013 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.
+
+// This is a duplicate of the file test_util in
+// chrome/test/data/extensions/api_test/file_system
+
+function checkEntry(entry, expectedName, isNew, shouldBeWritable) {
+ chrome.test.assertEq(expectedName, entry.name);
+ // Test that the file can be read.
+ entry.file(chrome.test.callback(function(file) {
+ var reader = new FileReader();
+ reader.onloadend = chrome.test.callbackPass(function(e) {
+ if (isNew)
+ chrome.test.assertEq(reader.result, "");
+ else
+ chrome.test.assertEq(reader.result.indexOf("Can you see me?"), 0);
+ // Test that we can write to the file, or not, depending on
+ // |shouldBeWritable|.
+ entry.createWriter(function(fileWriter) {
+ fileWriter.onwriteend = chrome.test.callback(function(e) {
+ if (fileWriter.error) {
+ if (shouldBeWritable) {
+ chrome.test.fail("Error writing to file: " +
+ fileWriter.error.toString());
+ } else {
+ chrome.test.succeed();
+ }
+ } else {
+ if (shouldBeWritable) {
+ // Get a new entry and check the data got to disk.
+ chrome.fileSystem.chooseEntry(chrome.test.callbackPass(
+ function(readEntry) {
+ readEntry.file(chrome.test.callback(function(readFile) {
+ var readReader = new FileReader();
+ readReader.onloadend = function(e) {
+ chrome.test.assertEq(readReader.result.indexOf("HoHoHo!"),
+ 0);
+ chrome.test.succeed();
+ };
+ readReader.onerror = function(e) {
+ chrome.test.fail("Failed to read file after write.");
+ };
+ readReader.readAsText(readFile);
+ }));
+ }));
+ } else {
+ chrome.test.fail(
+ "'Could write to file that should not be writable.");
+ }
+ }
+ });
+ var blob = new Blob(["HoHoHo!"], {type: "text/plain"});
+ fileWriter.write(blob);
+ });
+ });
+ reader.onerror = chrome.test.callback(function(e) {
+ chrome.test.fail("Error reading file contents.");
+ });
+ reader.readAsText(file);
+ }));
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/background.js b/chrome/test/data/extensions/api_test/file_system/retain_directory/background.js
new file mode 100644
index 0000000..e63978c
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/background.js
@@ -0,0 +1,7 @@
+// Copyright 2013 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.
+
+chrome.app.runtime.onLaunched.addListener(function () {
+ chrome.app.window.create('test.html');
+});
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/manifest.json b/chrome/test/data/extensions/api_test/file_system/retain_directory/manifest.json
new file mode 100644
index 0000000..c424ddb
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/manifest.json
@@ -0,0 +1,11 @@
+{
+ "name": "chrome.fileSystem.retainEntry test",
+ "version": "0.1",
+ "description": "Test for chrome.fileSystem.retainEntry",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "permissions": [{"fileSystem": ["directory"]}]
+}
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/test.html b/chrome/test/data/extensions/api_test/file_system/retain_directory/test.html
new file mode 100644
index 0000000..d89c528
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/test.html
@@ -0,0 +1,4 @@
+<html>
+<script src="test_util.js"></script>
+<script src="test.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/test.js b/chrome/test/data/extensions/api_test/file_system/retain_directory/test.js
new file mode 100644
index 0000000..03f03ac
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/test.js
@@ -0,0 +1,36 @@
+// Copyright 2013 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.
+
+chrome.test.runTests([
+ function retainEntryWorks() {
+ chrome.app.window.create('test_other_window.html', chrome.test.callbackPass(
+ function(otherWindow) {
+ otherWindow.contentWindow.callback = chrome.test.callbackPass(
+ function(id, entry) {
+ otherWindow.close();
+ chrome.fileSystem.isRestorable(id, chrome.test.callbackPass(
+ function(isRestorable) {
+ chrome.test.assertTrue(isRestorable);
+ }));
+ chrome.test.assertEq(chrome.fileSystem.retainEntry(entry), id);
+ chrome.fileSystem.restoreEntry(id, chrome.test.callbackPass(
+ function(restoredEntry) {
+ chrome.test.assertEq(restoredEntry, entry);
+ chrome.test.assertEq(
+ chrome.fileSystem.retainEntry(restoredEntry), id);
+ var reader = entry.createReader();
+ reader.readEntries(chrome.test.callback(function(entries) {
+ chrome.test.assertEq(entries.length, 1);
+ checkEntry(entries[0], 'open_existing.txt', false, false);
+ }));
+ entry.getFile(
+ 'open_existing.txt', {},
+ chrome.test.callbackPass(function(entry) {
+ checkEntry(entry, 'open_existing.txt', false, false);
+ }));
+ }));
+ });
+ }));
+ }
+]);
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.html b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.html
new file mode 100644
index 0000000..a85a652
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.html
@@ -0,0 +1,3 @@
+<html>
+<script src="test_other_window.js"></script>
+</html>
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.js b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.js
new file mode 100644
index 0000000..8475c1e8
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_other_window.js
@@ -0,0 +1,18 @@
+// Copyright 2013 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.
+
+chrome.fileSystem.chooseEntry({type: 'openDirectory'},
+ chrome.test.callbackPass(function(entry) {
+ var id = chrome.fileSystem.retainEntry(entry);
+ chrome.test.assertTrue(id != null);
+ chrome.fileSystem.isRestorable(id, chrome.test.callbackPass(
+ function(isRestorable) {
+ chrome.test.assertTrue(isRestorable);
+ }));
+ chrome.fileSystem.restoreEntry(id, chrome.test.callbackPass(
+ function(restoredEntry) {
+ chrome.test.assertEq(restoredEntry, entry);
+ }));
+ callback(id, entry);
+}));
diff --git a/chrome/test/data/extensions/api_test/file_system/retain_directory/test_util.js b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_util.js
new file mode 100644
index 0000000..a31ee51
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_system/retain_directory/test_util.js
@@ -0,0 +1,62 @@
+// Copyright 2013 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.
+
+// This is a duplicate of the file test_util in
+// chrome/test/data/extensions/api_test/file_system
+
+function checkEntry(entry, expectedName, isNew, shouldBeWritable) {
+ chrome.test.assertEq(expectedName, entry.name);
+ // Test that the file can be read.
+ entry.file(chrome.test.callback(function(file) {
+ var reader = new FileReader();
+ reader.onloadend = chrome.test.callbackPass(function(e) {
+ if (isNew)
+ chrome.test.assertEq(reader.result, "");
+ else
+ chrome.test.assertEq(reader.result.indexOf("Can you see me?"), 0);
+ // Test that we can write to the file, or not, depending on
+ // |shouldBeWritable|.
+ entry.createWriter(function(fileWriter) {
+ fileWriter.onwriteend = chrome.test.callback(function(e) {
+ if (fileWriter.error) {
+ if (shouldBeWritable) {
+ chrome.test.fail("Error writing to file: " +
+ fileWriter.error.toString());
+ } else {
+ chrome.test.succeed();
+ }
+ } else {
+ if (shouldBeWritable) {
+ // Get a new entry and check the data got to disk.
+ chrome.fileSystem.chooseEntry(chrome.test.callbackPass(
+ function(readEntry) {
+ readEntry.file(chrome.test.callback(function(readFile) {
+ var readReader = new FileReader();
+ readReader.onloadend = function(e) {
+ chrome.test.assertEq(readReader.result.indexOf("HoHoHo!"),
+ 0);
+ chrome.test.succeed();
+ };
+ readReader.onerror = function(e) {
+ chrome.test.fail("Failed to read file after write.");
+ };
+ readReader.readAsText(readFile);
+ }));
+ }));
+ } else {
+ chrome.test.fail(
+ "'Could write to file that should not be writable.");
+ }
+ }
+ });
+ var blob = new Blob(["HoHoHo!"], {type: "text/plain"});
+ fileWriter.write(blob);
+ });
+ });
+ reader.onerror = chrome.test.callback(function(e) {
+ chrome.test.fail("Error reading file contents.");
+ });
+ reader.readAsText(file);
+ }));
+}