dom/devicestorage/test/test_overwrite.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.

     1 <!--
     2   Any copyright is dedicated to the Public Domain.
     3   http://creativecommons.org/publicdomain/zero/1.0/
     4 -->
     5 <!DOCTYPE HTML>
     6 <html>
     7 <!--
     8 https://bugzilla.mozilla.org/show_bug.cgi?id=717103
     9 -->
    10 <head>
    11   <title>Test for basic sanity of the device storage API </title>
    12   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    13   <script type="text/javascript" src="devicestorage_common.js"></script>
    15 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    16 </head>
    17 <body>
    18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
    19 <p id="display"></p>
    20 <div id="content" style="display: none">
    22 </div>
    23 <pre id="test">
    24 <script class="testbody" type="text/javascript">
    26 var filename = "devicestorage/aaaa.png"
    28 devicestorage_setup();
    31 function deleteSuccess(e) {
    32   devicestorage_cleanup();
    33 }
    35 function deleteError(e) {
    36   ok(false, "deleteError was called : " + e.target.error.name);
    37   devicestorage_cleanup();
    38 }
    40 function addOverwritingSuccess(e) {
    41   ok(false, "addOverwritingSuccess was called.");
    42   devicestorage_cleanup();
    43 }
    45 function addOverwritingError(e) {
    46   ok(true, "Adding to the same location should fail");
    47   ok(e.target.error.name == "NoModificationAllowedError", "Error must be NoModificationAllowedError");
    49   var storage = navigator.getDeviceStorage("pictures");
    50   request = storage.delete(filename)
    51   request.onsuccess = deleteSuccess;
    52   request.onerror = deleteError;
    53 }
    55 function addSuccess(e) {
    56   ok(true, "addSuccess was called");
    58   var storage = navigator.getDeviceStorage("pictures");
    59   ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
    61   request = storage.addNamed(createRandomBlob('image/png'), filename);
    62   ok(request, "Should have a non-null request");
    64   request.onsuccess = addOverwritingSuccess;
    65   request.onerror = addOverwritingError;
    66 }
    68 function addError(e) {
    69   // test file is already exists.  clean it up and try again..
    70   var storage = navigator.getDeviceStorage("pictures");
    71   request = storage.delete(filename)
    72   request.onsuccess = runtest;
    73 }
    75 function runtest() {
    76   var storage = navigator.getDeviceStorage("pictures");
    77   ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
    79   request = storage.addNamed(createRandomBlob('image/png'), filename);
    80   ok(request, "Should have a non-null request");
    82   request.onsuccess = addSuccess;
    83   request.onerror = addError;
    84 }
    86 runtest();
    88 </script>
    89 </pre>
    90 </body>
    91 </html>

mercurial