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: var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: michael@0: /** michael@0: * Ensures that the Places APIs recognize that aBookmarkedUri is bookmarked michael@0: * via aBookmarkId and that aUnbookmarkedUri is not bookmarked at all. michael@0: * michael@0: * @param aBookmarkId michael@0: * an item ID whose corresponding URI is aBookmarkedUri michael@0: * @param aBookmarkedUri michael@0: * a bookmarked URI that has a corresponding item ID aBookmarkId michael@0: * @param aUnbookmarkedUri michael@0: * a URI that is not currently bookmarked at all michael@0: */ michael@0: function checkUris(aBookmarkId, aBookmarkedUri, aUnbookmarkedUri) michael@0: { michael@0: // Ensure that aBookmarkedUri equals some URI that is bookmarked michael@0: var uri = bmsvc.getBookmarkedURIFor(aBookmarkedUri); michael@0: do_check_neq(uri, null); michael@0: do_check_true(uri.equals(aBookmarkedUri)); michael@0: michael@0: // Ensure that aBookmarkedUri is considered bookmarked michael@0: do_check_true(bmsvc.isBookmarked(aBookmarkedUri)); michael@0: michael@0: // Ensure that the URI corresponding to aBookmarkId equals aBookmarkedUri michael@0: do_check_true(bmsvc.getBookmarkURI(aBookmarkId).equals(aBookmarkedUri)); michael@0: michael@0: // Ensure that aUnbookmarkedUri does not equal any URI that is bookmarked michael@0: uri = bmsvc.getBookmarkedURIFor(aUnbookmarkedUri); michael@0: do_check_eq(uri, null); michael@0: michael@0: // Ensure that aUnbookmarkedUri is not considered bookmarked michael@0: do_check_false(bmsvc.isBookmarked(aUnbookmarkedUri)); michael@0: } michael@0: michael@0: // main michael@0: function run_test() { michael@0: // Create a folder michael@0: var folderId = bmsvc.createFolder(bmsvc.toolbarFolder, michael@0: "test", michael@0: bmsvc.DEFAULT_INDEX); michael@0: michael@0: // Create 2 URIs michael@0: var uri1 = uri("http://www.dogs.com"); michael@0: var uri2 = uri("http://www.cats.com"); michael@0: michael@0: // Bookmark the first one michael@0: var bookmarkId = bmsvc.insertBookmark(folderId, michael@0: uri1, michael@0: bmsvc.DEFAULT_INDEX, michael@0: "Dogs"); michael@0: michael@0: // uri1 is bookmarked via bookmarkId, uri2 is not michael@0: checkUris(bookmarkId, uri1, uri2); michael@0: michael@0: // Change the URI of the bookmark to uri2 michael@0: bmsvc.changeBookmarkURI(bookmarkId, uri2); michael@0: michael@0: // uri2 is now bookmarked via bookmarkId, uri1 is not michael@0: checkUris(bookmarkId, uri2, uri1); michael@0: }