michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that Sync can correctly handle a legacy microsummary record michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/NetUtil.jsm"); michael@0: Cu.import("resource://gre/modules/PlacesUtils.jsm"); michael@0: michael@0: Cu.import("resource://gre/modules/Log.jsm"); michael@0: Cu.import("resource://services-sync/engines.js"); michael@0: Cu.import("resource://services-sync/engines/bookmarks.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: const GENERATORURI_ANNO = "microsummary/generatorURI"; michael@0: const STATICTITLE_ANNO = "bookmarks/staticTitle"; michael@0: michael@0: const TEST_URL = "http://micsum.mozilla.org/"; michael@0: const TEST_TITLE = "A microsummarized bookmark" michael@0: const GENERATOR_URL = "http://generate.micsum/" michael@0: const STATIC_TITLE = "Static title" michael@0: michael@0: function newMicrosummary(url, title) { michael@0: let id = PlacesUtils.bookmarks.insertBookmark( michael@0: PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI(url), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, title michael@0: ); michael@0: PlacesUtils.annotations.setItemAnnotation(id, GENERATORURI_ANNO, michael@0: GENERATOR_URL, 0, michael@0: PlacesUtils.annotations.EXPIRE_NEVER); michael@0: PlacesUtils.annotations.setItemAnnotation(id, STATICTITLE_ANNO, michael@0: "Static title", 0, michael@0: PlacesUtils.annotations.EXPIRE_NEVER); michael@0: return id; michael@0: } michael@0: michael@0: function run_test() { michael@0: michael@0: Service.engineManager.register(BookmarksEngine); michael@0: let engine = Service.engineManager.get("bookmarks"); michael@0: let store = engine._store; michael@0: michael@0: // Clean up. michael@0: store.wipe(); michael@0: michael@0: initTestLogging("Trace"); michael@0: Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace; michael@0: michael@0: _("Create a microsummarized bookmark."); michael@0: let id = newMicrosummary(TEST_URL, TEST_TITLE); michael@0: let guid = store.GUIDForId(id); michael@0: _("GUID: " + guid); michael@0: do_check_true(!!guid); michael@0: michael@0: _("Create record object and verify that it's sane."); michael@0: let record = store.createRecord(guid); michael@0: do_check_true(record instanceof Bookmark); michael@0: do_check_eq(record.bmkUri, TEST_URL); michael@0: michael@0: _("Make sure the new record does not carry the microsummaries annotations."); michael@0: do_check_false("staticTitle" in record); michael@0: do_check_false("generatorUri" in record); michael@0: michael@0: _("Remove the bookmark from Places."); michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: michael@0: _("Convert record to the old microsummaries one."); michael@0: record.staticTitle = STATIC_TITLE; michael@0: record.generatorUri = GENERATOR_URL; michael@0: record.type = "microsummary"; michael@0: michael@0: _("Apply the modified record as incoming data."); michael@0: store.applyIncoming(record); michael@0: michael@0: _("Verify it has been created correctly as a simple Bookmark."); michael@0: id = store.idForGUID(record.id); michael@0: do_check_eq(store.GUIDForId(id), record.id); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemType(id), michael@0: PlacesUtils.bookmarks.TYPE_BOOKMARK); michael@0: do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(id).spec, TEST_URL); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), TEST_TITLE); michael@0: do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id), michael@0: PlacesUtils.unfiledBookmarksFolderId); michael@0: do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null); michael@0: michael@0: do_check_throws( michael@0: function () PlacesUtils.annotations.getItemAnnotation(id, GENERATORURI_ANNO), michael@0: Cr.NS_ERROR_NOT_AVAILABLE michael@0: ); michael@0: michael@0: do_check_throws( michael@0: function () PlacesUtils.annotations.getItemAnnotation(id, STATICTITLE_ANNO), michael@0: Cr.NS_ERROR_NOT_AVAILABLE michael@0: ); michael@0: michael@0: // Clean up. michael@0: store.wipe(); michael@0: }