dom/tests/mochitest/localstorage/test_lowDeviceStorage.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 <html xmlns="http://www.w3.org/1999/xhtml">
     2 <head>
     3 <title>Test localStorage usage while in a low device storage situation</title>
     5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6 <script type="text/javascript" src="localStorageCommon.js"></script>
     7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     9 <script type="text/javascript">
    11 /*
    12 This test does the following:
    13 - Stores an item in localStorage.
    14 - Checks the stored value.
    15 - Emulates a low device storage situation.
    16 - Gets the stored item again.
    17 - Removes the stored item.
    18 - Fails storing a new value.
    19 - Emulates recovering from a low device storage situation.
    20 - Stores a new value.
    21 - Checks the stored value.
    22 */
    24 function lowDeviceStorage(lowStorage) {
    25   var data = lowStorage ? "full" : "free";
    26   os().notifyObservers(null, "disk-space-watcher", data);
    27 }
    29 function startTest() {
    30   // Add a test item.
    31   localStorage.setItem("item", "value");
    32   is(localStorage.getItem("item"), "value", "getItem()");
    34   // Emulates a low device storage situation.
    35   lowDeviceStorage(true);
    37   // Checks that we can still access to the stored item.
    38   is(localStorage.getItem("item"), "value",
    39      "getItem() during a device storage situation");
    41   // Removes the stored item.
    42   localStorage.removeItem("item");
    43   is(localStorage.getItem("item"), undefined,
    44      "getItem() after removing the item");
    46   // Fails storing a new item.
    47   try {
    48     localStorage.setItem("newItem", "value");
    49     ok(false, "Storing a new item is expected to fail");
    50   } catch(e) {
    51     ok(true, "Got an expected exception " + e);
    52   } finally {
    53     is(localStorage.getItem("newItem"), undefined,
    54        "setItem while device storage is low");
    55   }
    57   // Emulates recovering from a low device storage situation.
    58   lowDeviceStorage(false);
    60   // Add a test item after recovering from the low device storage situation.
    61   localStorage.setItem("newItem", "value");
    62   is(localStorage.getItem("newItem"), "value",
    63      "getItem() with available storage");
    65   SimpleTest.finish();
    66 }
    68 SimpleTest.waitForExplicitFinish();
    70 </script>
    72 </head>
    74 <body onload="startTest();">
    75 </body>
    76 </html>

mercurial