1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_changeBookmarkURI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 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 +var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.12 + getService(Ci.nsINavBookmarksService); 1.13 + 1.14 +/** 1.15 + * Ensures that the Places APIs recognize that aBookmarkedUri is bookmarked 1.16 + * via aBookmarkId and that aUnbookmarkedUri is not bookmarked at all. 1.17 + * 1.18 + * @param aBookmarkId 1.19 + * an item ID whose corresponding URI is aBookmarkedUri 1.20 + * @param aBookmarkedUri 1.21 + * a bookmarked URI that has a corresponding item ID aBookmarkId 1.22 + * @param aUnbookmarkedUri 1.23 + * a URI that is not currently bookmarked at all 1.24 + */ 1.25 +function checkUris(aBookmarkId, aBookmarkedUri, aUnbookmarkedUri) 1.26 +{ 1.27 + // Ensure that aBookmarkedUri equals some URI that is bookmarked 1.28 + var uri = bmsvc.getBookmarkedURIFor(aBookmarkedUri); 1.29 + do_check_neq(uri, null); 1.30 + do_check_true(uri.equals(aBookmarkedUri)); 1.31 + 1.32 + // Ensure that aBookmarkedUri is considered bookmarked 1.33 + do_check_true(bmsvc.isBookmarked(aBookmarkedUri)); 1.34 + 1.35 + // Ensure that the URI corresponding to aBookmarkId equals aBookmarkedUri 1.36 + do_check_true(bmsvc.getBookmarkURI(aBookmarkId).equals(aBookmarkedUri)); 1.37 + 1.38 + // Ensure that aUnbookmarkedUri does not equal any URI that is bookmarked 1.39 + uri = bmsvc.getBookmarkedURIFor(aUnbookmarkedUri); 1.40 + do_check_eq(uri, null); 1.41 + 1.42 + // Ensure that aUnbookmarkedUri is not considered bookmarked 1.43 + do_check_false(bmsvc.isBookmarked(aUnbookmarkedUri)); 1.44 +} 1.45 + 1.46 +// main 1.47 +function run_test() { 1.48 + // Create a folder 1.49 + var folderId = bmsvc.createFolder(bmsvc.toolbarFolder, 1.50 + "test", 1.51 + bmsvc.DEFAULT_INDEX); 1.52 + 1.53 + // Create 2 URIs 1.54 + var uri1 = uri("http://www.dogs.com"); 1.55 + var uri2 = uri("http://www.cats.com"); 1.56 + 1.57 + // Bookmark the first one 1.58 + var bookmarkId = bmsvc.insertBookmark(folderId, 1.59 + uri1, 1.60 + bmsvc.DEFAULT_INDEX, 1.61 + "Dogs"); 1.62 + 1.63 + // uri1 is bookmarked via bookmarkId, uri2 is not 1.64 + checkUris(bookmarkId, uri1, uri2); 1.65 + 1.66 + // Change the URI of the bookmark to uri2 1.67 + bmsvc.changeBookmarkURI(bookmarkId, uri2); 1.68 + 1.69 + // uri2 is now bookmarked via bookmarkId, uri1 is not 1.70 + checkUris(bookmarkId, uri2, uri1); 1.71 +}