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_FILE = Object.freeze({
15 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
22 var TESTING_NEW_FILE = Object.freeze({
26 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
30 * Sets up the tests. Called once per all test cases. In case of a failure,
31 * the callback is not called.
33 * @param {function()} callback Success callback.
35 function setUp(callback) {
36 chrome.fileSystemProvider.onGetMetadataRequested.addListener(
37 test_util.onGetMetadataRequestedDefault);
38 chrome.fileSystemProvider.onCreateFileRequested.addListener(
39 test_util.onCreateFileRequested);
41 test_util.defaultMetadata['/' + TESTING_FILE.name] = TESTING_FILE;
43 test_util.mountFileSystem(callback);
47 * Runs all of the test cases, one by one.
50 chrome.test.runTests([
51 // Create a file which doesn't exist. Should succeed.
52 function createFileSuccessSimple() {
53 var onSuccess = chrome.test.callbackPass();
54 test_util.fileSystem.root.getFile(
55 TESTING_NEW_FILE.name, {create: true},
57 chrome.test.assertEq(TESTING_NEW_FILE.name, entry.name);
58 chrome.test.assertFalse(entry.isDirectory);
61 chrome.test.fail(error.name);
65 // Create a file which exists, non-exclusively. Should succeed.
66 function createFileOrOpenSuccess() {
67 var onSuccess = chrome.test.callbackPass();
68 test_util.fileSystem.root.getFile(
69 TESTING_FILE.name, {create: true, exclusive: false},
71 chrome.test.assertEq(TESTING_FILE.name, entry.name);
72 chrome.test.assertFalse(entry.isDirectory);
75 chrome.test.fail(error.name);
79 // Create a file which exists, exclusively. Should fail.
80 function createFileExistsError() {
81 var onSuccess = chrome.test.callbackPass();
82 test_util.fileSystem.root.getFile(
83 TESTING_FILE.name, {create: true, exclusive: true},
85 chrome.test.fail('Created a file, but should fail.');
87 chrome.test.assertEq('InvalidModificationError', error.name);
94 // Setup and run all of the test cases.