1 // Copyright 2014 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.
6 * Retains a test directory.
7 * @return {Promise} Promise fulflled/rejected depending on the test result.
9 function retainDirectory() {
10 return new Promise(function(fulfill) {
11 chrome.app.window.create('window.html', fulfill);
12 }).then(function(appWindow) {
13 return new Promise(function(fulfill, rejected) {
14 appWindow.contentWindow.chrome.fileSystem.chooseEntry(
15 {type: "openDirectory"},
18 }).then(function(selected) {
19 chrome.test.assertTrue(selected.isDirectory);
20 var id = chrome.fileSystem.retainEntry(selected);
21 chrome.test.assertTrue(!!id);
22 return new Promise(function(fulfill, rejected) {
23 chrome.fileSystem.isRestorable(id, fulfill);
24 }).then(function(restorable) {
25 chrome.test.assertTrue(restorable);
26 return new Promise(function(fulfill, rejected) {
27 chrome.storage.local.set({id: id}, fulfill);
31 chrome.runtime.reload();
36 * Restores a test directory.
37 * @param {string} id ID of the test directory.
38 * @return {Promise} Promise fulflled/rejected depending on the test result.
40 function restoreDirectory(id) {
41 return new Promise(function(fulfill) {
42 chrome.fileSystem.isRestorable(id, fulfill);
43 }).then(function(restorable) {
44 chrome.test.assertTrue(restorable);
45 return new Promise(function(fulfill) {
46 chrome.fileSystem.restoreEntry(id, fulfill);
48 }).then(function(directory) {
49 chrome.test.assertTrue(!!directory);
50 chrome.test.assertTrue(!!directory.isDirectory);
55 * Tests to retain and to restore directory on the drive.
57 function testRetainEntry() {
58 new Promise(function(fulfill) {
59 chrome.storage.local.get('id', fulfill);
60 }).then(function(values) {
62 return retainDirectory();
64 return restoreDirectory(values.id).then(chrome.test.callbackPass());
65 }).catch(function(error) {
66 chrome.test.fail(error.stack || error);
70 chrome.test.runTests([testRetainEntry]);