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.
11 var TESTING_HELLO_DIR = Object.freeze({
15 modificationTime: new Date(2014, 3, 27, 9, 38, 14)
22 var TESTING_CANDIES_DIR = Object.freeze({
26 modificationTime: new Date(2014, 2, 26, 8, 37, 13)
33 var TESTING_TIRAMISU_FILE = Object.freeze({
37 modificationTime: new Date(2014, 1, 25, 7, 36, 12)
41 * Returns entries in the requested directory.
43 * @param {ReadDirectoryRequestedOptions} options Options.
44 * @param {function(Array.<Object>, boolean)} onSuccess Success callback with
45 * a list of entries. May be called multiple times.
46 * @param {function(string)} onError Error callback with an error code.
48 function onReadDirectoryRequested(options, onSuccess, onError) {
49 if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
50 onError('SECURITY'); // enum ProviderError.
54 if (options.directoryPath != '/' + TESTING_HELLO_DIR.name) {
55 onError('NOT_FOUND'); // enum ProviderError.
59 onSuccess([TESTING_TIRAMISU_FILE], true /* hasMore */);
60 onSuccess([TESTING_CANDIES_DIR], false /* hasMore */);
64 * Sets up the tests. Called once per all test cases. In case of a failure,
65 * the callback is not called.
67 * @param {function()} callback Success callback.
69 function setUp(callback) {
70 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
71 test_util.onGetMetadataRequestedDefault);
73 test_util.defaultMetadata['/' + TESTING_HELLO_DIR.name] =
75 test_util.defaultMetadata['/' + TESTING_HELLO_DIR.name + '/' +
76 TESTING_TIRAMISU_FILE.name] = TESTING_TIRAMISU_FILE;
77 test_util.defaultMetadata['/' + TESTING_HELLO_DIR.name + '/' +
78 TESTING_CANDIES_DIR.name] = TESTING_CANDIES_DIR;
80 chrome.fileSystemProvider.onReadDirectoryRequested.addListener(
81 onReadDirectoryRequested);
83 test_util.mountFileSystem(callback);
87 * Runs all of the test cases, one by one.
90 chrome.test.runTests([
91 // Read contents of the /hello directory. This directory exists, so it
93 function readEntriesSuccess() {
94 var onTestSuccess = chrome.test.callbackPass();
95 test_util.fileSystem.root.getDirectory(
99 var dirReader = dirEntry.createReader();
101 var readEntriesNext = function() {
102 dirReader.readEntries(function(inEntries) {
103 Array.prototype.push.apply(entries, inEntries);
104 if (!inEntries.length) {
105 // No more entries, so verify.
106 chrome.test.assertEq(2, entries.length);
107 chrome.test.assertTrue(entries[0].isFile);
108 chrome.test.assertEq('tiramisu.txt', entries[0].name);
109 chrome.test.assertEq(
110 '/hello/tiramisu.txt', entries[0].fullPath);
111 chrome.test.assertTrue(entries[1].isDirectory);
112 chrome.test.assertEq('candies', entries[1].name);
113 chrome.test.assertEq('/hello/candies', entries[1].fullPath);
128 // Read contents of a directory which does not exist, what should return an
130 function readEntriesError() {
131 var onTestSuccess = chrome.test.callbackPass();
132 test_util.fileSystem.root.getDirectory(
139 chrome.test.assertEq('NotFoundError', error.name);
146 // Setup and run all of the test cases.