toolkit/components/places/tests/unit/test_lastModified.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_lastModified.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,34 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 + /**
    1.11 +  * Test that inserting a new bookmark will set lastModified to the same
    1.12 +  * values as dateAdded.
    1.13 +  */
    1.14 +// main
    1.15 +function run_test() {
    1.16 +  var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.17 +           getService(Ci.nsINavBookmarksService);
    1.18 +  var itemId = bs.insertBookmark(bs.bookmarksMenuFolder,
    1.19 +                                 uri("http://www.mozilla.org/"),
    1.20 +                                 bs.DEFAULT_INDEX,
    1.21 +                                 "itemTitle");
    1.22 +  var dateAdded = bs.getItemDateAdded(itemId);
    1.23 +  do_check_eq(dateAdded, bs.getItemLastModified(itemId));
    1.24 +
    1.25 +  // Change lastModified, then change dateAdded.  LastModified should be set
    1.26 +  // to the new dateAdded.
    1.27 +  // This could randomly fail on virtual machines due to timing issues, so
    1.28 +  // we manually increase the time value.  See bug 500640 for details.
    1.29 +  bs.setItemLastModified(itemId, dateAdded + 1);
    1.30 +  do_check_true(bs.getItemLastModified(itemId) === dateAdded + 1);
    1.31 +  do_check_true(bs.getItemDateAdded(itemId) < bs.getItemLastModified(itemId));
    1.32 +  bs.setItemDateAdded(itemId, dateAdded + 2);
    1.33 +  do_check_true(bs.getItemDateAdded(itemId) === dateAdded + 2);
    1.34 +  do_check_eq(bs.getItemDateAdded(itemId), bs.getItemLastModified(itemId));
    1.35 +
    1.36 +  bs.removeItem(itemId);
    1.37 +}

mercurial