Upstream version 7.36.153.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / data / native_file_system.html
1 <html>
2   <head>
3     <title></title>
4   </head>
5   <body>
6     <script>
7       var current_test = 0;
8       var test_list = [
9         writeFile,
10         readFile,
11         removeFile,
12         createDirectory,
13         readDirectoryEntries,
14         removeDirectory,
15         endTest
16       ];
17
18       function runNextTest() {
19         if (current_test < test_list.length) {
20           test_list[current_test++]();
21         }
22       };
23
24       function reportFail(message) {
25         console.log(message);
26         document.title = "Fail";
27         document.body.innerText = "Fail";
28       };
29
30       function endTest() {
31         document.title = "Pass";
32         document.body.innerText = "Pass";
33       };
34       
35       function writeFile() {
36         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
37           function(fs) {
38             fs.root.getFile("/cachedir/1.txt", {create: true}, function (entry) {
39               entry.createWriter(function (writer) {
40                 var blob = new Blob(["1234567890"], {type: "text/plain"});
41                 writer.write(blob);
42                 runNextTest();
43               },
44               function(e) {reportFail(JSON.stringify(e))});
45             },
46           function(e) {reportFail(JSON.stringify(e))});
47         });
48       }
49
50       function readFile() {
51         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
52           function(fs) {
53             fs.root.getFile("/cachedir/1.txt", {create: false}, function (entry) {
54                 entry.file(function(file) {
55                   reader = new FileReader();
56                   reader.onloadend = function(e) {
57                     if ("1234567890" == this.result) {
58                       runNextTest();
59                     } else {
60                       reportFail();
61                     }
62                   };
63                   reader.readAsText(file);
64                 },
65                 function(e) {reportFail(JSON.stringify(e))});
66             },
67             function(e) {reportFail(JSON.stringify(e))});
68         },
69         function(e) {reportFail(JSON.stringify(e))});
70       };
71
72
73       function removeFile() {
74         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
75             function(fs) {
76               fs.root.getFile("/cachedir/1.txt", {create: false}, function (entry) {
77                 entry.remove(function () {
78                       runNextTest();
79                     },
80                     function(e) {reportFail(JSON.stringify(e))});
81               },
82               function(e) {reportFail(JSON.stringify(e))});
83             }
84         );
85       }
86
87       function createDirectory() {
88         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
89             function(fs) {
90               fs.root.getDirectory("/cachedir/justfortest", {create: true}, function (entry) {
91                 runNextTest();
92               },
93               function(e) {reportFail(JSON.stringify(e))});
94             }
95         );
96       }
97
98       function readDirectoryEntries() {
99         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
100             function(fs) {
101               fs.root.getDirectory("/cachedir/", {create: false}, function (entry) {
102                 var dirReader = entry.createReader();
103                 var entries = [];
104                 dirReader.readEntries(function(results) {
105                     if (0 < results.length) {
106                       runNextTest();
107                     } else {
108                       reportFail("You app home directory is empty!");
109                     }
110                   },
111                   function(e) {reportFail(JSON.stringify(e))}
112                 );
113                 runNextTest();
114               },
115               function(e) {reportFail(JSON.stringify(e))});
116             }
117         );
118       }
119
120       function removeDirectory() {
121         xwalk.experimental.native_file_system.requestNativeFileSystem("cachedir",
122             function(fs) {
123               fs.root.getDirectory("/cachedir/justfortest", {create: false}, function (entry) {
124                 entry.remove(function () {runNextTest();},
125                     function(e) {reportFail(JSON.stringify(e))});
126               },
127               function(e) {reportFail(JSON.stringify(e))});
128             }
129         );
130       }
131
132       runNextTest();
133     </script>
134   </body>
135 </html>