services/sync/tests/unit/test_bookmark_record.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/services/sync/tests/unit/test_bookmark_record.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +Cu.import("resource://gre/modules/Log.jsm");
     1.8 +Cu.import("resource://services-sync/engines/bookmarks.js");
     1.9 +Cu.import("resource://services-sync/keys.js");
    1.10 +Cu.import("resource://services-sync/record.js");
    1.11 +Cu.import("resource://services-sync/service.js");
    1.12 +Cu.import("resource://services-sync/util.js");
    1.13 +Cu.import("resource://testing-common/services/sync/utils.js");
    1.14 +
    1.15 +function prepareBookmarkItem(collection, id) {
    1.16 +  let b = new Bookmark(collection, id);
    1.17 +  b.cleartext.stuff = "my payload here";
    1.18 +  return b;
    1.19 +}
    1.20 +
    1.21 +function run_test() {
    1.22 +  ensureLegacyIdentityManager();
    1.23 +  Service.identity.username = "john@example.com";
    1.24 +  Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea";
    1.25 +  generateNewKeys(Service.collectionKeys);
    1.26 +  let keyBundle = Service.identity.syncKeyBundle;
    1.27 +
    1.28 +  let log = Log.repository.getLogger("Test");
    1.29 +  Log.repository.rootLogger.addAppender(new Log.DumpAppender());
    1.30 +
    1.31 +  log.info("Creating a record");
    1.32 +
    1.33 +  let u = "http://localhost:8080/storage/bookmarks/foo";
    1.34 +  let placesItem = new PlacesItem("bookmarks", "foo", "bookmark");
    1.35 +  let bookmarkItem = prepareBookmarkItem("bookmarks", "foo");
    1.36 +
    1.37 +  log.info("Checking getTypeObject");
    1.38 +  do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark);
    1.39 +  do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
    1.40 +
    1.41 +  bookmarkItem.encrypt(keyBundle);
    1.42 +  log.info("Ciphertext is " + bookmarkItem.ciphertext);
    1.43 +  do_check_true(bookmarkItem.ciphertext != null);
    1.44 +
    1.45 +  log.info("Decrypting the record");
    1.46 +
    1.47 +  let payload = bookmarkItem.decrypt(keyBundle);
    1.48 +  do_check_eq(payload.stuff, "my payload here");
    1.49 +  do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
    1.50 +  do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one
    1.51 +}

mercurial