Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
|
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.
| |
| 12 chrome.app.window.create('window.html', fulfill); | |
| 13 }).then(function(appWindow) { | |
| 14 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.
| |
| 15 appWindow.contentWindow.chrome.fileSystem.chooseEntry( | |
| 16 {type: "openDirectory"}, | |
| 17 fulfill); | |
| 18 }); | |
| 19 }).then(function(selected) { | |
| 20 chrome.test.assertTrue(selected.isDirectory); | |
| 21 var id = chrome.fileSystem.retainEntry(selected); | |
| 22 chrome.test.assertTrue(!!id); | |
| 23 return new Promise(function(fulfill) { | |
| 24 chrome.fileSystem.isRestorable(id, fulfill); | |
| 25 }).then(function(restorable) { | |
| 26 chrome.test.assertTrue(restorable); | |
| 27 return new Promise(function(fulfill) { | |
| 28 chrome.storage.local.set({id: id}, fulfill); | |
| 29 }); | |
| 30 }); | |
| 31 }).then(function() { | |
| 32 chrome.runtime.reload(); | |
| 33 }); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Restores a test directory. | |
| 38 * @param {string} id ID of the test directory. | |
| 39 * @return {Promise} Promise fulflled/rejected depending on the test result. | |
| 40 */ | |
| 41 function restoreDirectory(id) { | |
| 42 return new Promise(function(fulfill) { | |
| 43 chrome.fileSystem.isRestorable(id, fulfill); | |
| 44 }).then(function(restorable) { | |
| 45 chrome.test.assertTrue(restorable); | |
| 46 return new Promise(function(fulfill) { | |
| 47 chrome.fileSystem.restoreEntry(id, fulfill); | |
| 48 }); | |
| 49 }).then(function(directory) { | |
| 50 chrome.test.assertTrue(!!directory); | |
| 51 chrome.test.assertTrue(!!directory.isDirectory); | |
| 52 }); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Tests to retain and to restore directory on the drive. | |
| 57 */ | |
| 58 function testRetainEntry() { | |
| 59 new Promise(function(fulfill) { | |
| 60 chrome.storage.local.get('id', fulfill); | |
| 61 }).then(function(obj) { | |
|
mtomasz
2014/10/14 06:08:50
nit: obj -> values?
hirono
2014/10/14 09:22:10
Done.
| |
| 62 if (!obj.id) | |
| 63 return retainDirectory(); | |
| 64 else | |
| 65 return restoreDirectory(obj.id).then(chrome.test.callbackPass()); | |
| 66 }).catch(function(error) { | |
| 67 chrome.test.fail(error.stack || error); | |
| 68 window.onerror(); | |
|
mtomasz
2014/10/14 06:08:50
Is window.onerror() necessary?
hirono
2014/10/14 09:22:10
Removed.
| |
| 69 }); | |
| 70 } | |
| 71 | |
| 72 chrome.test.runTests([testRetainEntry]); | |
| OLD | NEW |