1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/devicestorage/test/test_fs_createDirectory.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +<!-- 1.5 + Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ 1.7 +--> 1.8 +<!DOCTYPE HTML> 1.9 +<html> <!-- 1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=910412 1.11 +--> 1.12 +<head> 1.13 + <title>Test createDirectory of the FileSystem API for device storage</title> 1.14 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="text/javascript" src="devicestorage_common.js"></script> 1.16 + 1.17 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.18 +</head> 1.19 +<body> 1.20 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=910412">Mozilla Bug 910412</a> 1.21 +<p id="display"></p> 1.22 +<div id="content" style="display: none"> 1.23 +</div> 1.24 +<pre id="test"> 1.25 +<script class="testbody" type="text/javascript"> 1.26 + 1.27 +devicestorage_setup(); 1.28 + 1.29 +// The root directory object. 1.30 +var gRoot; 1.31 +var gTestCount = 0; 1.32 +var gPath = ''; 1.33 +var gName = ''; 1.34 + 1.35 +function testCreateDirectory(rootDir, path) { 1.36 + rootDir.createDirectory(path).then(createDirectorySuccess, cbError); 1.37 +} 1.38 + 1.39 +function createDirectorySuccess(d) { 1.40 + ok(d.name === gName, "Failed to create directory: name mismatch."); 1.41 + 1.42 + // Get the new created directory from the root. 1.43 + gRoot.get(gPath).then(getSuccess, cbError); 1.44 +} 1.45 + 1.46 +function getSuccess(d) { 1.47 + ok(d.name === gName, "Should get directory - " + (gPath || "[root]") + "."); 1.48 + switch (gTestCount) { 1.49 + case 0: 1.50 + gRoot = d; 1.51 + // Create a new directory under the root. 1.52 + gName = gPath = randomFilename(12); 1.53 + testCreateDirectory(gRoot, gName); 1.54 + break; 1.55 + case 1: 1.56 + // Create a sub-directory under current directory. 1.57 + gName = randomFilename(12); 1.58 + gPath = gPath + '/' + gName; 1.59 + testCreateDirectory(d, gName); 1.60 + break; 1.61 + case 2: 1.62 + // Create directory with an existing path. 1.63 + gRoot.createDirectory(gPath).then(function(what) { 1.64 + ok(false, "Should not overwrite an existing directory."); 1.65 + devicestorage_cleanup(); 1.66 + }, function(e) { 1.67 + ok(true, "Creating directory should fail if it already exists."); 1.68 + 1.69 + // Create a directory whose intermediate directory doesn't exit. 1.70 + gName = randomFilename(12); 1.71 + gPath = 'sub1/sub2/' + gName; 1.72 + testCreateDirectory(gRoot, gPath); 1.73 + }); 1.74 + break; 1.75 + default: 1.76 + // Create the parent directory. 1.77 + d.createDirectory('..').then(function(what) { 1.78 + ok(false, "Should not overwrite an existing directory."); 1.79 + devicestorage_cleanup(); 1.80 + }, function(e) { 1.81 + ok(true, "Accessing parent directory with '..' is not allowed."); 1.82 + devicestorage_cleanup(); 1.83 + }); 1.84 + break; 1.85 + } 1.86 + gTestCount++; 1.87 +} 1.88 + 1.89 +function cbError(e) { 1.90 + ok(false, e.name + " error should not arrive here!"); 1.91 + devicestorage_cleanup(); 1.92 +} 1.93 + 1.94 +ok(navigator.getDeviceStorage, "Should have getDeviceStorage."); 1.95 + 1.96 +var storage = navigator.getDeviceStorage("pictures"); 1.97 +ok(storage, "Should have gotten a storage."); 1.98 + 1.99 +var promise = storage.getRoot(); 1.100 +ok(promise, "Should have a non-null promise for getRoot."); 1.101 + 1.102 +gName = storage.storageName; 1.103 +promise.then(getSuccess, cbError); 1.104 +</script> 1.105 +</pre> 1.106 +</body> 1.107 +</html> 1.108 +