dom/devicestorage/test/test_diskSpace.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

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=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 devicestorage_setup();
michael@0 26
michael@0 27
michael@0 28 var freeBytes = -1;
michael@0 29 var stats = 0;
michael@0 30
michael@0 31 function stat(s, file_list_length) {
michael@0 32 if (freeBytes == -1) {
michael@0 33 freeBytes = s.target.result.freeBytes;
michael@0 34 }
michael@0 35
michael@0 36 ok(freeBytes == s.target.result.freeBytes, "Free bytes should be the same");
michael@0 37 ok(file_list_length * 1024 == s.target.result.totalBytes, "space taken up by files should match")
michael@0 38
michael@0 39 stats = stats + 1;
michael@0 40
michael@0 41 if (stats == 2) {
michael@0 42 devicestorage_cleanup();
michael@0 43 }
michael@0 44 }
michael@0 45
michael@0 46 function addSuccess(e) {
michael@0 47 added = added - 1;
michael@0 48
michael@0 49 if (added == 0) {
michael@0 50 request = pictures.stat();
michael@0 51 request.onsuccess = function(s) {stat(s, picture_files.length)};
michael@0 52
michael@0 53 request = videos.stat();
michael@0 54 request.onsuccess = function(s) {stat(s, video_files.length)};
michael@0 55
michael@0 56 request = music.stat();
michael@0 57 request.onsuccess = function(s) {stat(s, music_files.length)};
michael@0 58 }
michael@0 59 }
michael@0 60
michael@0 61 function addError(e) {
michael@0 62 ok(false, "addError was called : " + e.target.error.name);
michael@0 63 devicestorage_cleanup();
michael@0 64 }
michael@0 65
michael@0 66 ok(true, "hi");
michael@0 67
michael@0 68 var pictures = navigator.getDeviceStorage("pictures");
michael@0 69 var picture_files = [ "a.png", "b.png", "c.png", "d.png", "e.png" ];
michael@0 70
michael@0 71 var videos = navigator.getDeviceStorage("videos");
michael@0 72 var video_files = [ "a.ogv", "b.ogv" ];
michael@0 73
michael@0 74 var music = navigator.getDeviceStorage("music");
michael@0 75 var music_files = [ "a.mp3", "b.mp3", "c.mp3" ];
michael@0 76
michael@0 77 var added = picture_files.length + video_files.length + music_files.length;
michael@0 78
michael@0 79 for (var i=0; i < picture_files.length; i++) {
michael@0 80 request = pictures.addNamed(createRandomBlob('image/png'), picture_files[i]);
michael@0 81 request.onsuccess = addSuccess;
michael@0 82 request.onerror = addError;
michael@0 83 }
michael@0 84
michael@0 85 for (var i=0; i < video_files.length; i++) {
michael@0 86 request = videos.addNamed(createRandomBlob('video/ogv'), video_files[i]);
michael@0 87 request.onsuccess = addSuccess;
michael@0 88 request.onerror = addError;
michael@0 89 }
michael@0 90
michael@0 91 for (var i=0; i < music_files.length; i++) {
michael@0 92 request = music.addNamed(createRandomBlob('audio/mp3'), music_files[i]);
michael@0 93 request.onsuccess = addSuccess;
michael@0 94 request.onerror = addError;
michael@0 95 }
michael@0 96
michael@0 97 </script>
michael@0 98 </pre>
michael@0 99 </body>
michael@0 100 </html>
michael@0 101

mercurial