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

Side by Side 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: Fixed windows build. 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 /**
6 * Retains a test directory.
7 * @return {Promise} Promise fulflled/rejected depending on the test result.
8 */
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"},
16 fulfill);
17 });
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);
28 });
29 });
30 }).then(function() {
31 chrome.runtime.reload();
32 });
33 }
34
35 /**
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.
39 */
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);
47 });
48 }).then(function(directory) {
49 chrome.test.assertTrue(!!directory);
50 chrome.test.assertTrue(!!directory.isDirectory);
51 });
52 }
53
54 /**
55 * Tests to retain and to restore directory on the drive.
56 */
57 function testRetainEntry() {
58 new Promise(function(fulfill) {
59 chrome.storage.local.get('id', fulfill);
60 }).then(function(values) {
61 if (!values.id)
62 return retainDirectory();
63 else
64 return restoreDirectory(values.id).then(chrome.test.callbackPass());
65 }).catch(function(error) {
66 chrome.test.fail(error.stack || error);
67 });
68 }
69
70 chrome.test.runTests([testRetainEntry]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698