dom/alarm/test/test_alarm_add_date.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test date Paramter for Alarm API</title>
     6   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     7   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     8 </head>
     9 <body>
    10 <p id="display"></p>
    11 <div id="content" style="display: none"></div>
    12 <pre id="test">
    13   <script type="application/javascript">
    15   "use strict";
    17   // Verify passing a Date in the future doesn't fail
    18   function testFutureDate() {
    19     var tomorrow = new Date();
    20     tomorrow.setDate(tomorrow.getDate() + 1);
    22     var domRequest;
    23     try {
    24       domRequest = navigator.mozAlarms.add(tomorrow, "honorTimezone", {});
    25     } catch (e) {
    26       ok(false,
    27          "Unexpected exception trying to add alarm for tomorrow.");
    29       // Proceed to next test.
    30       return testPastDate();
    31     }
    32     domRequest.onsuccess = function(e) {
    33       navigator.mozAlarms.remove(e.target.result);
    34       ok(true, "Add alarm for future date.");
    36       // Awesome, no error so proceed to next test.
    37       testPastDate();
    38     };
    39     domRequest.onerror = function(e) {
    40       ok(false, "Unable to add alarm for tomorrow`.");
    42       // Proceed to next test.
    43       testPastDate();
    44     };
    45   }
    47   // Verify passing a Date that's already past doesn't fail (it should fire immediately).
    48   function testPastDate() {
    49     var yesterday = new Date();
    50     yesterday.setDate(yesterday.getDate() - 1);
    52     var domRequest;
    53     try {
    54       domRequest = navigator.mozAlarms.add(yesterday, "honorTimezone", {});
    55     } catch (e) {
    56       ok(false,
    57          "Unexpected exception trying to add alarm for yesterday.");
    59       // Move on to the next test.
    60       testNullDate();
    61     }
    62     domRequest.onsuccess = function(e) {
    63       navigator.mozAlarms.remove(e.target.result);
    65       ok(true, "Should be able to add alarm for already past date, which should fire immediately.");
    67       // Move on to the next test.
    68       testNullDate();
    69     };
    70     domRequest.onerror = function(e) {
    71       ok(false, "Unable to add alarm for yesterday.");
    73       // Move on to the next test.
    74       testNullDate();
    75     }
    76   }
    78   // Verify passing null does indeed fail
    79   function testNullDate() {
    80     try {
    81       navigator.mozAlarms.add(null, "honorTimezone", {});
    82       ok(false, "Expected an exception to be thrown for alarm with null date.");
    83     } catch(e) {
    84       ok(true, "Exception thrown for alarm with null date.");
    85     }
    87     // Move on to the next test.
    88     testInvalidTimeZone()
    89   }
    91   function testInvalidTimeZone() {
    92     try {
    93       navigator.mozAlarms.add(new Date(), "badTimeZoneArg", {});
    94       ok(false, "Expected an exception to be thrown while testing bad time zone arg.");
    95     } catch(e) {
    96       ok(true, "Exception thrown while testing bad time zone arg.");
    97     }
    98     SimpleTest.finish();
    99   }
   101   function startTests() {
   103     SpecialPowers.pushPrefEnv({"set": [["dom.mozAlarms.enabled", true]]}, function() {
   104       // Currently applicable only on FxOS
   105       if (navigator.userAgent.indexOf("Mobile") != -1 &&
   106           navigator.appVersion.indexOf("Android") == -1)
   107       {
   108         testFutureDate();
   109       } else {
   110         ok(true, "mozAlarms on Firefox OS only.");
   111         SimpleTest.finish();
   112       }
   113     });
   114   }
   116   SimpleTest.expectAssertions(0, 9);
   117   SimpleTest.waitForExplicitFinish();
   118   if (SpecialPowers.hasPermission("alarms", document)) {
   119     startTests();
   120   } else {
   121     // Add the permissions and reload so they propogate
   122     SpecialPowers.addPermission("alarms", true, document);
   123     window.location.reload();
   124   }
   126   </script>
   127 </pre>
   128 </body>
   129 </html>

mercurial