services/sync/tests/unit/test_bookmark_legacy_microsummaries_support.js

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Tests that Sync can correctly handle a legacy microsummary record
michael@0 5 Cu.import("resource://gre/modules/Services.jsm");
michael@0 6 Cu.import("resource://gre/modules/NetUtil.jsm");
michael@0 7 Cu.import("resource://gre/modules/PlacesUtils.jsm");
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/Log.jsm");
michael@0 10 Cu.import("resource://services-sync/engines.js");
michael@0 11 Cu.import("resource://services-sync/engines/bookmarks.js");
michael@0 12 Cu.import("resource://services-sync/record.js");
michael@0 13 Cu.import("resource://services-sync/service.js");
michael@0 14 Cu.import("resource://services-sync/util.js");
michael@0 15
michael@0 16 const GENERATORURI_ANNO = "microsummary/generatorURI";
michael@0 17 const STATICTITLE_ANNO = "bookmarks/staticTitle";
michael@0 18
michael@0 19 const TEST_URL = "http://micsum.mozilla.org/";
michael@0 20 const TEST_TITLE = "A microsummarized bookmark"
michael@0 21 const GENERATOR_URL = "http://generate.micsum/"
michael@0 22 const STATIC_TITLE = "Static title"
michael@0 23
michael@0 24 function newMicrosummary(url, title) {
michael@0 25 let id = PlacesUtils.bookmarks.insertBookmark(
michael@0 26 PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI(url),
michael@0 27 PlacesUtils.bookmarks.DEFAULT_INDEX, title
michael@0 28 );
michael@0 29 PlacesUtils.annotations.setItemAnnotation(id, GENERATORURI_ANNO,
michael@0 30 GENERATOR_URL, 0,
michael@0 31 PlacesUtils.annotations.EXPIRE_NEVER);
michael@0 32 PlacesUtils.annotations.setItemAnnotation(id, STATICTITLE_ANNO,
michael@0 33 "Static title", 0,
michael@0 34 PlacesUtils.annotations.EXPIRE_NEVER);
michael@0 35 return id;
michael@0 36 }
michael@0 37
michael@0 38 function run_test() {
michael@0 39
michael@0 40 Service.engineManager.register(BookmarksEngine);
michael@0 41 let engine = Service.engineManager.get("bookmarks");
michael@0 42 let store = engine._store;
michael@0 43
michael@0 44 // Clean up.
michael@0 45 store.wipe();
michael@0 46
michael@0 47 initTestLogging("Trace");
michael@0 48 Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace;
michael@0 49
michael@0 50 _("Create a microsummarized bookmark.");
michael@0 51 let id = newMicrosummary(TEST_URL, TEST_TITLE);
michael@0 52 let guid = store.GUIDForId(id);
michael@0 53 _("GUID: " + guid);
michael@0 54 do_check_true(!!guid);
michael@0 55
michael@0 56 _("Create record object and verify that it's sane.");
michael@0 57 let record = store.createRecord(guid);
michael@0 58 do_check_true(record instanceof Bookmark);
michael@0 59 do_check_eq(record.bmkUri, TEST_URL);
michael@0 60
michael@0 61 _("Make sure the new record does not carry the microsummaries annotations.");
michael@0 62 do_check_false("staticTitle" in record);
michael@0 63 do_check_false("generatorUri" in record);
michael@0 64
michael@0 65 _("Remove the bookmark from Places.");
michael@0 66 PlacesUtils.bookmarks.removeItem(id);
michael@0 67
michael@0 68 _("Convert record to the old microsummaries one.");
michael@0 69 record.staticTitle = STATIC_TITLE;
michael@0 70 record.generatorUri = GENERATOR_URL;
michael@0 71 record.type = "microsummary";
michael@0 72
michael@0 73 _("Apply the modified record as incoming data.");
michael@0 74 store.applyIncoming(record);
michael@0 75
michael@0 76 _("Verify it has been created correctly as a simple Bookmark.");
michael@0 77 id = store.idForGUID(record.id);
michael@0 78 do_check_eq(store.GUIDForId(id), record.id);
michael@0 79 do_check_eq(PlacesUtils.bookmarks.getItemType(id),
michael@0 80 PlacesUtils.bookmarks.TYPE_BOOKMARK);
michael@0 81 do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(id).spec, TEST_URL);
michael@0 82 do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), TEST_TITLE);
michael@0 83 do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
michael@0 84 PlacesUtils.unfiledBookmarksFolderId);
michael@0 85 do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null);
michael@0 86
michael@0 87 do_check_throws(
michael@0 88 function () PlacesUtils.annotations.getItemAnnotation(id, GENERATORURI_ANNO),
michael@0 89 Cr.NS_ERROR_NOT_AVAILABLE
michael@0 90 );
michael@0 91
michael@0 92 do_check_throws(
michael@0 93 function () PlacesUtils.annotations.getItemAnnotation(id, STATICTITLE_ANNO),
michael@0 94 Cr.NS_ERROR_NOT_AVAILABLE
michael@0 95 );
michael@0 96
michael@0 97 // Clean up.
michael@0 98 store.wipe();
michael@0 99 }

mercurial