dom/devicestorage/test/test_fs_remove.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <!DOCTYPE HTML>
michael@0 6 <html> <!--
michael@0 7 https://bugzilla.mozilla.org/show_bug.cgi?id=934368
michael@0 8 -->
michael@0 9 <head>
michael@0 10 <title>Test Directory#remove and #removeDeep of the FileSystem API for device storage</title>
michael@0 11 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 12 <script type="text/javascript" src="devicestorage_common.js"></script>
michael@0 13
michael@0 14 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=934368">Mozilla Bug 934368</a>
michael@0 18 <p id="display"></p>
michael@0 19 <div id="content" style="display: none">
michael@0 20 </div>
michael@0 21 <pre id="test">
michael@0 22 <script class="testbody" type="application/javascript;version=1.7">
michael@0 23
michael@0 24 devicestorage_setup();
michael@0 25
michael@0 26 let gStorage = null;
michael@0 27 let gTestCount = 0;
michael@0 28 let gFileMap = {};
michael@0 29 let gRemoveDeep = true;
michael@0 30
michael@0 31 let gTestCases = [
michael@0 32 // Remove a non-existent file should return false.
michael@0 33 {
michael@0 34 dir: "/",
michael@0 35 path: "non-existent.png",
michael@0 36 ret: false,
michael@0 37 shouldPass: true
michael@0 38 },
michael@0 39
michael@0 40 // Remove parent directory should fail.
michael@0 41 {
michael@0 42 dir: "sub1/sub2",
michael@0 43 target: "sub1",
michael@0 44 ret: true,
michael@0 45 shouldPass: false
michael@0 46 },
michael@0 47
michael@0 48 // Remove root directory should fail.
michael@0 49 {
michael@0 50 dir: "/",
michael@0 51 target: "/",
michael@0 52 ret: true,
michael@0 53 shouldPass: false
michael@0 54 },
michael@0 55
michael@0 56 // Remove non-descendant file should fail.
michael@0 57 {
michael@0 58 dir: "sub1",
michael@0 59 target: "sub/b.png",
michael@0 60 ret: true,
michael@0 61 shouldPass: false
michael@0 62 },
michael@0 63
michael@0 64 // Remove descendant file should return true.
michael@0 65 {
michael@0 66 dir: "sub1",
michael@0 67 target: "sub1/sub2/a.png",
michael@0 68 ret: true,
michael@0 69 shouldPass: true
michael@0 70 },
michael@0 71
michael@0 72 // Remove empty directory should return true.
michael@0 73 {
michael@0 74 dir: "sub1",
michael@0 75 path: "sub2",
michael@0 76 ret: true,
michael@0 77 shouldPass: true
michael@0 78 },
michael@0 79
michael@0 80
michael@0 81 // Remove non-empty directory should return true for "removeDeep" and fail
michael@0 82 // for "remove".
michael@0 83 {
michael@0 84 dir: "/",
michael@0 85 path: "sub",
michael@0 86 ret: true,
michael@0 87 get shouldPass() { return gRemoveDeep; }
michael@0 88 }
michael@0 89 ];
michael@0 90
michael@0 91 function createTestFiles(storage, callback) {
michael@0 92 function createTestFile(path) {
michael@0 93 return new Promise(function(resolve, reject) {
michael@0 94 function addNamed() {
michael@0 95 var req = storage.addNamed(createRandomBlob("image/png"), path);
michael@0 96
michael@0 97 req.onsuccess = function() {
michael@0 98 ok(true, path + " was created.");
michael@0 99 resolve();
michael@0 100 };
michael@0 101
michael@0 102 req.onerror = function(e) {
michael@0 103 ok(false, "Failed to create " + path + ': ' + e.target.error.name);
michael@0 104 reject();
michael@0 105 };
michael@0 106 }
michael@0 107
michael@0 108 // Bug 980136. Check if the file exists before we create.
michael@0 109 var req = storage.get(path);
michael@0 110
michael@0 111 req.onsuccess = function() {
michael@0 112 ok(true, path + " exists. Do not need to create.");
michael@0 113 resolve();
michael@0 114 };
michael@0 115
michael@0 116 req.onerror = function(e) {
michael@0 117 ok(true, path + " does not exists: " + e.target.error.name);
michael@0 118 addNamed();
michael@0 119 };
michael@0 120 });
michael@0 121 }
michael@0 122
michael@0 123 let arr = [];
michael@0 124
michael@0 125 ["sub1/sub2/a.png", "sub/b.png"].forEach(function(path) {
michael@0 126 arr.push(createTestFile(path));
michael@0 127 });
michael@0 128
michael@0 129 Promise.all(arr).then(function() {
michael@0 130 callback();
michael@0 131 }, function() {
michael@0 132 ok(false, "Failed to created test files.");
michael@0 133 devicestorage_cleanup();
michael@0 134 });
michael@0 135 }
michael@0 136
michael@0 137 function runTest() {
michael@0 138 gTestCount = 0;
michael@0 139 createTestFiles(gStorage, function() {
michael@0 140 function cbError(e) {
michael@0 141 ok(false, "Should not arrive at cbError! Error: " + e.name);
michael@0 142 devicestorage_cleanup();
michael@0 143 }
michael@0 144
michael@0 145 function cbSuccess(r) {
michael@0 146 ok(r, "Should get the file - " + this);
michael@0 147 gFileMap[this] = r;
michael@0 148 }
michael@0 149
michael@0 150 // Get directory and file objects.
michael@0 151 gStorage.getRoot().then(function(root) {
michael@0 152 ok(root, "Should get root directory.");
michael@0 153 gFileMap["/"] = root;
michael@0 154
michael@0 155 let arr = [];
michael@0 156
michael@0 157 ["sub1", "sub1/sub2", "sub1/sub2/a.png", "sub/b.png"].forEach(function(path) {
michael@0 158 arr.push(root.get(path).then(cbSuccess.bind(path), cbError));
michael@0 159 });
michael@0 160
michael@0 161 Promise.all(arr).then(function() {
michael@0 162 testNextRemove();
michael@0 163 }, function() {
michael@0 164 ok(false, "Failed to get test files.");
michael@0 165 devicestorage_cleanup();
michael@0 166 });
michael@0 167 }, cbError);
michael@0 168 });
michael@0 169 }
michael@0 170
michael@0 171 function testNextRemove() {
michael@0 172 if (gTestCount < gTestCases.length) {
michael@0 173 let data = gTestCases[gTestCount++];
michael@0 174 let dir = gFileMap[data.dir];
michael@0 175 let path = data.path || gFileMap[data.target];
michael@0 176 let targetPath = data.path || data.target;
michael@0 177 let promise = gRemoveDeep ? dir.removeDeep(path) : dir.remove(path);
michael@0 178 promise.then(function(result) {
michael@0 179 ok(data.shouldPass, "Success callback was called to remove " +
michael@0 180 targetPath + " from " + data.dir);
michael@0 181 is(result, data.ret, "Return value should match to remove " +
michael@0 182 targetPath + " from " + data.dir);
michael@0 183 SimpleTest.executeSoon(testNextRemove);
michael@0 184 }, function(err) {
michael@0 185 ok(!data.shouldPass, "Error callback was called to remove " +
michael@0 186 targetPath + " from " + data.dir + '. Error: ' + err.name);
michael@0 187 SimpleTest.executeSoon(testNextRemove);
michael@0 188 });
michael@0 189 return;
michael@0 190 }
michael@0 191
michael@0 192 if (gRemoveDeep) {
michael@0 193 // Test "remove" after "removeDeep".
michael@0 194 gRemoveDeep = false;
michael@0 195 runTest();
michael@0 196 return;
michael@0 197 }
michael@0 198
michael@0 199 devicestorage_cleanup();
michael@0 200 }
michael@0 201
michael@0 202 ok(navigator.getDeviceStorage, "Should have getDeviceStorage.");
michael@0 203
michael@0 204 let gStorage = navigator.getDeviceStorage("pictures");
michael@0 205 ok(gStorage, "Should have gotten a storage.");
michael@0 206
michael@0 207 // Test "removeDeep" first.
michael@0 208 gRemoveDeep = true;
michael@0 209 runTest();
michael@0 210
michael@0 211 </script>
michael@0 212 </pre>
michael@0 213 </body>
michael@0 214 </html>
michael@0 215

mercurial