1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/sync/tests/unit/test_bookmark_legacy_microsummaries_support.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that Sync can correctly handle a legacy microsummary record 1.8 +Cu.import("resource://gre/modules/Services.jsm"); 1.9 +Cu.import("resource://gre/modules/NetUtil.jsm"); 1.10 +Cu.import("resource://gre/modules/PlacesUtils.jsm"); 1.11 + 1.12 +Cu.import("resource://gre/modules/Log.jsm"); 1.13 +Cu.import("resource://services-sync/engines.js"); 1.14 +Cu.import("resource://services-sync/engines/bookmarks.js"); 1.15 +Cu.import("resource://services-sync/record.js"); 1.16 +Cu.import("resource://services-sync/service.js"); 1.17 +Cu.import("resource://services-sync/util.js"); 1.18 + 1.19 +const GENERATORURI_ANNO = "microsummary/generatorURI"; 1.20 +const STATICTITLE_ANNO = "bookmarks/staticTitle"; 1.21 + 1.22 +const TEST_URL = "http://micsum.mozilla.org/"; 1.23 +const TEST_TITLE = "A microsummarized bookmark" 1.24 +const GENERATOR_URL = "http://generate.micsum/" 1.25 +const STATIC_TITLE = "Static title" 1.26 + 1.27 +function newMicrosummary(url, title) { 1.28 + let id = PlacesUtils.bookmarks.insertBookmark( 1.29 + PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI(url), 1.30 + PlacesUtils.bookmarks.DEFAULT_INDEX, title 1.31 + ); 1.32 + PlacesUtils.annotations.setItemAnnotation(id, GENERATORURI_ANNO, 1.33 + GENERATOR_URL, 0, 1.34 + PlacesUtils.annotations.EXPIRE_NEVER); 1.35 + PlacesUtils.annotations.setItemAnnotation(id, STATICTITLE_ANNO, 1.36 + "Static title", 0, 1.37 + PlacesUtils.annotations.EXPIRE_NEVER); 1.38 + return id; 1.39 +} 1.40 + 1.41 +function run_test() { 1.42 + 1.43 + Service.engineManager.register(BookmarksEngine); 1.44 + let engine = Service.engineManager.get("bookmarks"); 1.45 + let store = engine._store; 1.46 + 1.47 + // Clean up. 1.48 + store.wipe(); 1.49 + 1.50 + initTestLogging("Trace"); 1.51 + Log.repository.getLogger("Sync.Engine.Bookmarks").level = Log.Level.Trace; 1.52 + 1.53 + _("Create a microsummarized bookmark."); 1.54 + let id = newMicrosummary(TEST_URL, TEST_TITLE); 1.55 + let guid = store.GUIDForId(id); 1.56 + _("GUID: " + guid); 1.57 + do_check_true(!!guid); 1.58 + 1.59 + _("Create record object and verify that it's sane."); 1.60 + let record = store.createRecord(guid); 1.61 + do_check_true(record instanceof Bookmark); 1.62 + do_check_eq(record.bmkUri, TEST_URL); 1.63 + 1.64 + _("Make sure the new record does not carry the microsummaries annotations."); 1.65 + do_check_false("staticTitle" in record); 1.66 + do_check_false("generatorUri" in record); 1.67 + 1.68 + _("Remove the bookmark from Places."); 1.69 + PlacesUtils.bookmarks.removeItem(id); 1.70 + 1.71 + _("Convert record to the old microsummaries one."); 1.72 + record.staticTitle = STATIC_TITLE; 1.73 + record.generatorUri = GENERATOR_URL; 1.74 + record.type = "microsummary"; 1.75 + 1.76 + _("Apply the modified record as incoming data."); 1.77 + store.applyIncoming(record); 1.78 + 1.79 + _("Verify it has been created correctly as a simple Bookmark."); 1.80 + id = store.idForGUID(record.id); 1.81 + do_check_eq(store.GUIDForId(id), record.id); 1.82 + do_check_eq(PlacesUtils.bookmarks.getItemType(id), 1.83 + PlacesUtils.bookmarks.TYPE_BOOKMARK); 1.84 + do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(id).spec, TEST_URL); 1.85 + do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), TEST_TITLE); 1.86 + do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id), 1.87 + PlacesUtils.unfiledBookmarksFolderId); 1.88 + do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null); 1.89 + 1.90 + do_check_throws( 1.91 + function () PlacesUtils.annotations.getItemAnnotation(id, GENERATORURI_ANNO), 1.92 + Cr.NS_ERROR_NOT_AVAILABLE 1.93 + ); 1.94 + 1.95 + do_check_throws( 1.96 + function () PlacesUtils.annotations.getItemAnnotation(id, STATICTITLE_ANNO), 1.97 + Cr.NS_ERROR_NOT_AVAILABLE 1.98 + ); 1.99 + 1.100 + // Clean up. 1.101 + store.wipe(); 1.102 +}