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

Unified Diff: chrome/test/data/extensions/api_test/file_browser/retain_entry/background.js

Issue 656733002: Fix filesystem.retainEntry API to handle non-native directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/extensions/api_test/file_browser/retain_entry/background.js
diff --git a/chrome/test/data/extensions/api_test/file_browser/retain_entry/background.js b/chrome/test/data/extensions/api_test/file_browser/retain_entry/background.js
new file mode 100644
index 0000000000000000000000000000000000000000..baf26757965ce53ab6d504d036d7963c48e4a5ed
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_browser/retain_entry/background.js
@@ -0,0 +1,72 @@
+// Copyright 2014 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.
+
+/**
+ * Retains a test directory.
+ * @return {Promise} Promise fulflled/rejected depending on the test result.
+ */
+function retainDirectory() {
+ return new Promise(function(fulfill) {
+
mtomasz 2014/10/14 06:08:50 nit: This \n looks strange here.
hirono 2014/10/14 09:22:10 Yes, mixed it in unintentionally.
+ chrome.app.window.create('window.html', fulfill);
+ }).then(function(appWindow) {
+ return new Promise(function(fulfill) {
mtomasz 2014/10/14 06:08:50 nit: AFAIK we require two arguments here for the c
hirono 2014/10/14 09:22:10 Done.
+ appWindow.contentWindow.chrome.fileSystem.chooseEntry(
+ {type: "openDirectory"},
+ fulfill);
+ });
+ }).then(function(selected) {
+ chrome.test.assertTrue(selected.isDirectory);
+ var id = chrome.fileSystem.retainEntry(selected);
+ chrome.test.assertTrue(!!id);
+ return new Promise(function(fulfill) {
+ chrome.fileSystem.isRestorable(id, fulfill);
+ }).then(function(restorable) {
+ chrome.test.assertTrue(restorable);
+ return new Promise(function(fulfill) {
+ chrome.storage.local.set({id: id}, fulfill);
+ });
+ });
+ }).then(function() {
+ chrome.runtime.reload();
+ });
+}
+
+/**
+ * Restores a test directory.
+ * @param {string} id ID of the test directory.
+ * @return {Promise} Promise fulflled/rejected depending on the test result.
+ */
+function restoreDirectory(id) {
+ return new Promise(function(fulfill) {
+ chrome.fileSystem.isRestorable(id, fulfill);
+ }).then(function(restorable) {
+ chrome.test.assertTrue(restorable);
+ return new Promise(function(fulfill) {
+ chrome.fileSystem.restoreEntry(id, fulfill);
+ });
+ }).then(function(directory) {
+ chrome.test.assertTrue(!!directory);
+ chrome.test.assertTrue(!!directory.isDirectory);
+ });
+}
+
+/**
+ * Tests to retain and to restore directory on the drive.
+ */
+function testRetainEntry() {
+ new Promise(function(fulfill) {
+ chrome.storage.local.get('id', fulfill);
+ }).then(function(obj) {
mtomasz 2014/10/14 06:08:50 nit: obj -> values?
hirono 2014/10/14 09:22:10 Done.
+ if (!obj.id)
+ return retainDirectory();
+ else
+ return restoreDirectory(obj.id).then(chrome.test.callbackPass());
+ }).catch(function(error) {
+ chrome.test.fail(error.stack || error);
+ window.onerror();
mtomasz 2014/10/14 06:08:50 Is window.onerror() necessary?
hirono 2014/10/14 09:22:10 Removed.
+ });
+}
+
+chrome.test.runTests([testRetainEntry]);

Powered by Google App Engine
This is Rietveld 408576698