Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / file_browser / retain_entry / background.js
blob4b38baa01fb84f5b24f350f3f86bbfac4127b784
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.
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   });
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   });
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   });
70 chrome.test.runTests([testRetainEntry]);