|
1 <!-- |
|
2 Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 --> |
|
5 <!DOCTYPE HTML> |
|
6 <html> <!-- |
|
7 https://bugzilla.mozilla.org/show_bug.cgi?id=910412 |
|
8 --> |
|
9 <head> |
|
10 <title>Test for the FileSystem API for device storage</title> |
|
11 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
12 <script type="text/javascript" src="devicestorage_common.js"></script> |
|
13 |
|
14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
15 </head> |
|
16 <body> |
|
17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=910412">Mozilla Bug 910412</a> |
|
18 <p id="display"></p> |
|
19 <div id="content" style="display: none"> |
|
20 </div> |
|
21 <pre id="test"> |
|
22 <script class="testbody" type="text/javascript"> |
|
23 |
|
24 devicestorage_setup(); |
|
25 |
|
26 var gFileName = randomFilename(12); |
|
27 |
|
28 // The root directory object. |
|
29 var gRoot; |
|
30 |
|
31 function getRootSuccess(r) { |
|
32 ok(r && r.name === storage.storageName, "Failed to get the root directory."); |
|
33 |
|
34 gRoot = r; |
|
35 |
|
36 // Create a new directory under the root. |
|
37 gRoot.createDirectory(gFileName).then(createDirectorySuccess, cbError); |
|
38 } |
|
39 |
|
40 function createDirectorySuccess(d) { |
|
41 ok(d.name === gFileName, "Failed to create directory: name mismatch."); |
|
42 |
|
43 // Get the new created directory from the root. |
|
44 gRoot.get(gFileName).then(getSuccess, cbError); |
|
45 } |
|
46 |
|
47 function getSuccess(d) { |
|
48 ok(d.name === gFileName, "Should get directory - " + gFileName + "."); |
|
49 devicestorage_cleanup(); |
|
50 } |
|
51 |
|
52 function cbError(e) { |
|
53 ok(false, "Should not arrive here! Error: " + e.name); |
|
54 devicestorage_cleanup(); |
|
55 } |
|
56 |
|
57 ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); |
|
58 |
|
59 var storage = navigator.getDeviceStorage("pictures"); |
|
60 ok(storage, "Should have gotten a storage"); |
|
61 |
|
62 var promise = storage.getRoot(); |
|
63 ok(promise, "Should have a non-null promise"); |
|
64 |
|
65 promise.then(getRootSuccess, cbError); |
|
66 </script> |
|
67 </pre> |
|
68 </body> |
|
69 </html> |
|
70 |