- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / sync_file_system / delete_file_system / test.js
1 // Copyright (c) 2012 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 var fileSystem;
6
7 var testStep = [
8   // First get the file system.
9   function () {
10     chrome.syncFileSystem.requestFileSystem(testStep.shift());
11   },
12   // Add a couple of test files.
13   function(fs) {
14     fileSystem = fs;
15     fileSystem.root.getFile('Test1.txt', {create: true}, testStep.shift(),
16         errorHandler);
17   },
18   function(fileEntry) {
19     fileSystem.root.getFile('Test2.txt', {create: true}, testStep.shift(),
20         errorHandler);
21   },
22   // Check the directory for contents.
23   function(dirEntry) {
24     var dirReader = fileSystem.root.createReader();
25     dirReader.readEntries(testStep.shift(), errorHandler);
26   },
27   function(entries) {
28     chrome.test.assertEq(2, entries.length);
29     var fileList = [];
30     fileList.push(entries[0].fullPath);
31     fileList.push(entries[1].fullPath);
32     fileList.sort();
33
34     chrome.test.assertEq("/Test1.txt", fileList[0]);
35     chrome.test.assertEq("/Test2.txt", fileList[1]);
36     testStep.shift()();
37   },
38   // Then try to delete the file system.
39   function() {
40     chrome.syncFileSystem.deleteFileSystem(fileSystem, testStep.shift());
41   },
42   function(result) {
43     chrome.test.assertTrue(result);
44     testStep.shift()();
45   },
46   // Assert that the file system no longer exists.
47   function(fileEntry) {
48     fileSystem.root.getDirectory('/', {}, testFail, testStep.shift());
49   },
50   function(e) {
51     chrome.test.assertEq(FileError.NOT_FOUND_ERR, e.code);
52     chrome.test.succeed();
53   }
54 ];
55
56 function testFail() {
57   chrome.test.fail("Failure callback should have been called instead as " +
58       "file system should no longer exist.");
59 }
60
61 function errorHandler(e) {
62   chrome.test.fail("e=" + e.code);
63 }
64
65 chrome.test.runTests([
66   testStep[0]
67 ]);