dom/devicestorage/test/test_enumerateNoParam.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=717103
michael@0 8 -->
michael@0 9 <head>
michael@0 10 <title>Test for the device storage API </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=717103">Mozilla Bug 717103</a>
michael@0 18 <p id="display"></p>
michael@0 19 <div id="content" style="display: none">
michael@0 20
michael@0 21 </div>
michael@0 22 <pre id="test">
michael@0 23 <script class="testbody" type="text/javascript">
michael@0 24
michael@0 25 // Array Remove - By John Resig (MIT Licensed)
michael@0 26 Array.prototype.remove = function(from, to) {
michael@0 27 var rest = this.slice((to || from) + 1 || this.length);
michael@0 28 this.length = from < 0 ? this.length + from : from;
michael@0 29 return this.push.apply(this, rest);
michael@0 30 };
michael@0 31
michael@0 32 devicestorage_setup();
michael@0 33
michael@0 34 function enumerateSuccess(e) {
michael@0 35
michael@0 36 if (e.target.result == null) {
michael@0 37 ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
michael@0 38 devicestorage_cleanup();
michael@0 39 return;
michael@0 40 }
michael@0 41
michael@0 42 var filename = e.target.result.name;
michael@0 43 if (filename[0] == "/") {
michael@0 44 // We got /storageName/prefix/filename
michael@0 45 // Remove the storageName (this shows up on FirefoxOS)
michael@0 46 filename = filename.substring(1); // Remove leading slash
michael@0 47 var slashIndex = filename.indexOf("/");
michael@0 48 if (slashIndex >= 0) {
michael@0 49 filename = filename.substring(slashIndex + 1); // Remove storageName
michael@0 50 }
michael@0 51 }
michael@0 52 if (filename.startsWith(prefix)) {
michael@0 53 filename = filename.substring(prefix.length + 1); // Remove prefix
michael@0 54 }
michael@0 55
michael@0 56 var index = files.indexOf(enumFilename);
michael@0 57 files.remove(index);
michael@0 58
michael@0 59 ok(index > -1, "filename should be in the enumeration : " + e.target.result.name);
michael@0 60
michael@0 61 // clean up
michael@0 62 var cleanup = storage.delete(e.target.result.name);
michael@0 63 cleanup.onsuccess = function(e) {} // todo - can i remove this?
michael@0 64
michael@0 65 e.target.continue();
michael@0 66 }
michael@0 67
michael@0 68 function handleError(e) {
michael@0 69 ok(false, "handleError was called : " + e.target.error.name);
michael@0 70 devicestorage_cleanup();
michael@0 71 }
michael@0 72
michael@0 73 function addSuccess(e) {
michael@0 74 addedSoFar = addedSoFar + 1;
michael@0 75 if (addedSoFar == files.length) {
michael@0 76
michael@0 77 var cursor = storage.enumerate();
michael@0 78 cursor.onsuccess = enumerateSuccess;
michael@0 79 cursor.onerror = handleError;
michael@0 80 }
michael@0 81 }
michael@0 82
michael@0 83 function addError(e) {
michael@0 84 ok(false, "addError was called : " + e.target.error.name);
michael@0 85 devicestorage_cleanup();
michael@0 86 }
michael@0 87
michael@0 88 var storage = navigator.getDeviceStorage("pictures");
michael@0 89 ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
michael@0 90 var prefix = "devicestorage/" + randomFilename(12)
michael@0 91
michael@0 92 var files = [ "a.png", "b.png", "c.png" ]
michael@0 93 var addedSoFar = 0;
michael@0 94
michael@0 95
michael@0 96 for (var i=0; i<files.length; i++) {
michael@0 97
michael@0 98 request = storage.addNamed(createRandomBlob('image/png'), prefix + '/' + files[i]);
michael@0 99
michael@0 100 ok(request, "Should have a non-null request");
michael@0 101 request.onsuccess = addSuccess;
michael@0 102 request.onerror = addError;
michael@0 103 }
michael@0 104
michael@0 105 </script>
michael@0 106 </pre>
michael@0 107 </body>
michael@0 108 </html>
michael@0 109

mercurial