PageRenderTime 19ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/services/sync/tests/unit/test_bookmark_record.js

http://github.com/zpao/v8monkey
JavaScript | 42 lines | 32 code | 10 blank | 0 comment | 1 complexity | 94bcfe0ce392dee59d5fd6f3b8dd23ab MD5 | raw file
 1Cu.import("resource://services-sync/record.js");
 2Cu.import("resource://services-sync/engines/bookmarks.js");
 3Cu.import("resource://services-sync/identity.js");
 4Cu.import("resource://services-sync/log4moz.js");
 5Cu.import("resource://services-sync/util.js");
 6  
 7function prepareBookmarkItem(collection, id) {
 8  let b = new Bookmark(collection, id);
 9  b.cleartext.stuff = "my payload here";
10  return b;
11}
12
13function run_test() {
14  let keyBundle = ID.set("WeaveCryptoID", new SyncKeyBundle(null, "john@example.com"));
15  keyBundle.keyStr = "abcdeabcdeabcdeabcdeabcdea";
16  
17  generateNewKeys();
18  
19  let log = Log4Moz.repository.getLogger("Test");
20  Log4Moz.repository.rootLogger.addAppender(new Log4Moz.DumpAppender());
21
22  log.info("Creating a record");
23
24  let u = "http://localhost:8080/storage/bookmarks/foo";
25  let placesItem = new PlacesItem("bookmarks", "foo", "bookmark");
26  let bookmarkItem = prepareBookmarkItem("bookmarks", "foo");
27  
28  log.info("Checking getTypeObject");
29  do_check_eq(placesItem.getTypeObject(placesItem.type), Bookmark);
30  do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
31  
32  bookmarkItem.encrypt(keyBundle);
33  log.info("Ciphertext is " + bookmarkItem.ciphertext);
34  do_check_true(bookmarkItem.ciphertext != null);
35  
36  log.info("Decrypting the record");
37
38  let payload = bookmarkItem.decrypt(keyBundle);
39  do_check_eq(payload.stuff, "my payload here");
40  do_check_eq(bookmarkItem.getTypeObject(bookmarkItem.type), Bookmark);
41  do_check_neq(payload, bookmarkItem.payload); // wrap.data.payload is the encrypted one
42}