1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_388695.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 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 +// Get bookmark service 1.11 +try { 1.12 + var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.13 + getService(Ci.nsINavBookmarksService); 1.14 +} catch(ex) { 1.15 + do_throw("Could not get nav-bookmarks-service\n"); 1.16 +} 1.17 + 1.18 +var gTestRoot; 1.19 +var gURI; 1.20 +var gItemId1; 1.21 +var gItemId2; 1.22 + 1.23 +// main 1.24 +function run_test() { 1.25 + gURI = uri("http://foo.tld.com/"); 1.26 + gTestRoot = bmsvc.createFolder(bmsvc.placesRoot, "test folder", 1.27 + bmsvc.DEFAULT_INDEX); 1.28 + 1.29 + // test getBookmarkIdsForURI 1.30 + // getBookmarkIdsForURI sorts by the most recently added/modified (descending) 1.31 + // 1.32 + // we cannot rely on dateAdded growing when doing so in a simple iteration, 1.33 + // see PR_Now() documentation 1.34 + do_test_pending(); 1.35 + 1.36 + gItemId1 = bmsvc.insertBookmark(gTestRoot, gURI, bmsvc.DEFAULT_INDEX, ""); 1.37 + do_timeout(100, phase2); 1.38 +} 1.39 + 1.40 +function phase2() { 1.41 + gItemId2 = bmsvc.insertBookmark(gTestRoot, gURI, bmsvc.DEFAULT_INDEX, ""); 1.42 + var b = bmsvc.getBookmarkIdsForURI(gURI); 1.43 + do_check_eq(b[0], gItemId2); 1.44 + do_check_eq(b[1], gItemId1); 1.45 + do_timeout(100, phase3); 1.46 +} 1.47 + 1.48 +function phase3() { 1.49 + // trigger last modified change 1.50 + bmsvc.setItemTitle(gItemId1, ""); 1.51 + var b = bmsvc.getBookmarkIdsForURI(gURI); 1.52 + do_check_eq(b[0], gItemId1); 1.53 + do_check_eq(b[1], gItemId2); 1.54 + do_test_finished(); 1.55 +}