Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
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=823965 |
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=823965">Mozilla Bug 823965</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 | devicestorage_setup(); |
michael@0 | 26 | |
michael@0 | 27 | var gFileName = "devicestorage/" + randomFilename(12) + "/hi.png"; |
michael@0 | 28 | var gData = "My name is Doug Turner (?!?). My IRC nick is DougT. I like Maple cookies." |
michael@0 | 29 | var gDataBlob = new Blob([gData], {type: 'image/png'}); |
michael@0 | 30 | |
michael@0 | 31 | function getSuccess(e) { |
michael@0 | 32 | var storage = navigator.getDeviceStorage("pictures"); |
michael@0 | 33 | ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); |
michael@0 | 34 | |
michael@0 | 35 | ok(e.target.result.name == gFileName, "File name should match"); |
michael@0 | 36 | ok(e.target.result.size > 0, "File size be greater than zero"); |
michael@0 | 37 | ok(e.target.result.type, "File should have a mime type"); |
michael@0 | 38 | ok(e.target.result.lastModifiedDate, "File should have a last modified date"); |
michael@0 | 39 | |
michael@0 | 40 | var mreq = storage.enumerate(); |
michael@0 | 41 | mreq.onsuccess = function() { |
michael@0 | 42 | var storage2 = navigator.getDeviceStorage('music'); |
michael@0 | 43 | var dreq = storage2.delete(mreq.result.name); |
michael@0 | 44 | dreq.onerror = function () { |
michael@0 | 45 | ok(true, "The bug has been fixed"); |
michael@0 | 46 | devicestorage_cleanup(); |
michael@0 | 47 | }; |
michael@0 | 48 | dreq.onsuccess = function () { |
michael@0 | 49 | ok(false, "The bug has been fixed"); |
michael@0 | 50 | devicestorage_cleanup(); |
michael@0 | 51 | }; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | mreq.onerror = getError; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function getError(e) { |
michael@0 | 58 | ok(false, "getError was called : " + e.target.error.name); |
michael@0 | 59 | devicestorage_cleanup(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function addSuccess(e) { |
michael@0 | 63 | |
michael@0 | 64 | var filename = e.target.result; |
michael@0 | 65 | if (filename[0] == "/") { |
michael@0 | 66 | // We got /storageName/prefix/filename |
michael@0 | 67 | // Remove the storageName (this shows up on FirefoxOS) |
michael@0 | 68 | filename = filename.substring(1); // Remove leading slash |
michael@0 | 69 | var slashIndex = filename.indexOf("/"); |
michael@0 | 70 | if (slashIndex >= 0) { |
michael@0 | 71 | filename = filename.substring(slashIndex + 1); // Remove storageName |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | ok(filename == gFileName, "File name should match"); |
michael@0 | 75 | // Since we now have the fully qualified name, change gFileName to that. |
michael@0 | 76 | gFileName = e.target.result; |
michael@0 | 77 | |
michael@0 | 78 | var storage = navigator.getDeviceStorage("pictures"); |
michael@0 | 79 | request = storage.get(gFileName); |
michael@0 | 80 | request.onsuccess = getSuccess; |
michael@0 | 81 | request.onerror = getError; |
michael@0 | 82 | |
michael@0 | 83 | ok(true, "addSuccess was called"); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function addError(e) { |
michael@0 | 87 | ok(false, "addError was called : " + e.target.error.name); |
michael@0 | 88 | devicestorage_cleanup(); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | ok(navigator.getDeviceStorage, "Should have getDeviceStorage"); |
michael@0 | 92 | |
michael@0 | 93 | var storage = navigator.getDeviceStorage("pictures"); |
michael@0 | 94 | ok(storage, "Should have gotten a storage"); |
michael@0 | 95 | |
michael@0 | 96 | request = storage.addNamed(gDataBlob, gFileName); |
michael@0 | 97 | ok(request, "Should have a non-null request"); |
michael@0 | 98 | |
michael@0 | 99 | request.onsuccess = addSuccess; |
michael@0 | 100 | request.onerror = addError; |
michael@0 | 101 | |
michael@0 | 102 | </script> |
michael@0 | 103 | </pre> |
michael@0 | 104 | </body> |
michael@0 | 105 | </html> |
michael@0 | 106 |