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 test_util.fileSystem.root.getFile(
54 TESTING_NEW_FILE.name, {create: true},
55 chrome.test.callbackPass(function(entry) {
56 chrome.test.assertEq(TESTING_NEW_FILE.name, entry.name);
57 chrome.test.assertFalse(entry.isDirectory);
59 chrome.test.fail(error.name);
63 // Create a file which exists, non-exclusively. Should succeed.
64 function createFileOrOpenSuccess() {
65 test_util.fileSystem.root.getFile(
66 TESTING_FILE.name, {create: true, exclusive: false},
67 chrome.test.callbackPass(function(entry) {
68 chrome.test.assertEq(TESTING_FILE.name, entry.name);
69 chrome.test.assertFalse(entry.isDirectory);
71 chrome.test.fail(error.name);
75 // Create a file which exists, exclusively. Should fail.
76 function createFileExistsError() {
77 test_util.fileSystem.root.getFile(
78 TESTING_FILE.name, {create: true, exclusive: true},
80 chrome.test.fail('Created a file, but should fail.');
81 }, chrome.test.callbackPass(function(error) {
82 chrome.test.assertEq('InvalidModificationError', error.name);
88 // Setup and run all of the test cases.