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.

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

mercurial