michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Get bookmark service michael@0: try { michael@0: var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: } catch(ex) { michael@0: do_throw("Could not get nav-bookmarks-service\n"); michael@0: } michael@0: michael@0: var gTestRoot; michael@0: var gURI; michael@0: var gItemId1; michael@0: var gItemId2; michael@0: michael@0: // main michael@0: function run_test() { michael@0: gURI = uri("http://foo.tld.com/"); michael@0: gTestRoot = bmsvc.createFolder(bmsvc.placesRoot, "test folder", michael@0: bmsvc.DEFAULT_INDEX); michael@0: michael@0: // test getBookmarkIdsForURI michael@0: // getBookmarkIdsForURI sorts by the most recently added/modified (descending) michael@0: // michael@0: // we cannot rely on dateAdded growing when doing so in a simple iteration, michael@0: // see PR_Now() documentation michael@0: do_test_pending(); michael@0: michael@0: gItemId1 = bmsvc.insertBookmark(gTestRoot, gURI, bmsvc.DEFAULT_INDEX, ""); michael@0: do_timeout(100, phase2); michael@0: } michael@0: michael@0: function phase2() { michael@0: gItemId2 = bmsvc.insertBookmark(gTestRoot, gURI, bmsvc.DEFAULT_INDEX, ""); michael@0: var b = bmsvc.getBookmarkIdsForURI(gURI); michael@0: do_check_eq(b[0], gItemId2); michael@0: do_check_eq(b[1], gItemId1); michael@0: do_timeout(100, phase3); michael@0: } michael@0: michael@0: function phase3() { michael@0: // trigger last modified change michael@0: bmsvc.setItemTitle(gItemId1, ""); michael@0: var b = bmsvc.getBookmarkIdsForURI(gURI); michael@0: do_check_eq(b[0], gItemId1); michael@0: do_check_eq(b[1], gItemId2); michael@0: do_test_finished(); michael@0: }