2012-03-22 15:49:50 -07:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
Cu.import("resource://services-sync/keys.js");
|
2011-01-18 16:23:30 -08:00
|
|
|
Cu.import("resource://services-sync/record.js");
|
2012-08-29 14:43:41 -07:00
|
|
|
Cu.import("resource://services-sync/service.js");
|
2010-06-16 14:30:08 -07:00
|
|
|
Cu.import("resource://services-sync/util.js");
|
2009-08-06 11:28:33 -07:00
|
|
|
|
|
|
|
function run_test() {
|
2010-08-12 13:19:41 -07:00
|
|
|
_("Set up test fixtures.");
|
2012-03-22 15:49:50 -07:00
|
|
|
|
2012-09-14 16:02:33 -07:00
|
|
|
Service.identity.username = "john@example.com";
|
2012-08-29 14:43:41 -07:00
|
|
|
Service.clusterURL = "http://fakebase/";
|
2011-04-08 14:52:08 -07:00
|
|
|
let baseUri = "http://fakebase/1.1/foo/storage/";
|
2010-08-12 13:19:41 -07:00
|
|
|
let pubUri = baseUri + "keys/pubkey";
|
|
|
|
let privUri = baseUri + "keys/privkey";
|
2010-03-16 16:39:08 -07:00
|
|
|
|
2012-09-14 16:02:33 -07:00
|
|
|
Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea";
|
|
|
|
let keyBundle = Service.identity.syncKeyBundle;
|
2010-08-12 13:19:41 -07:00
|
|
|
|
2012-08-29 14:43:41 -07:00
|
|
|
let engine = Service.clientsEngine;
|
|
|
|
|
2010-08-12 13:19:41 -07:00
|
|
|
try {
|
|
|
|
_("Test that serializing client records results in uploadable ascii");
|
2012-08-29 14:43:41 -07:00
|
|
|
engine.localID = "ascii";
|
|
|
|
engine.localName = "wéävê";
|
2010-08-12 13:19:41 -07:00
|
|
|
|
|
|
|
_("Make sure we have the expected record");
|
2012-08-29 14:43:41 -07:00
|
|
|
let record = engine._createRecord("ascii");
|
2010-08-12 13:19:41 -07:00
|
|
|
do_check_eq(record.id, "ascii");
|
|
|
|
do_check_eq(record.name, "wéävê");
|
|
|
|
|
2010-11-29 16:41:17 -08:00
|
|
|
_("Encrypting record...");
|
|
|
|
record.encrypt(keyBundle);
|
|
|
|
_("Encrypted.");
|
2012-08-29 14:43:41 -07:00
|
|
|
|
2010-08-12 13:19:41 -07:00
|
|
|
let serialized = JSON.stringify(record);
|
|
|
|
let checkCount = 0;
|
|
|
|
_("Checking for all ASCII:", serialized);
|
|
|
|
Array.forEach(serialized, function(ch) {
|
|
|
|
let code = ch.charCodeAt(0);
|
|
|
|
_("Checking asciiness of '", ch, "'=", code);
|
|
|
|
do_check_true(code < 128);
|
|
|
|
checkCount++;
|
|
|
|
});
|
|
|
|
|
|
|
|
_("Processed", checkCount, "characters out of", serialized.length);
|
|
|
|
do_check_eq(checkCount, serialized.length);
|
|
|
|
|
|
|
|
_("Making sure the record still looks like it did before");
|
2010-11-29 16:41:17 -08:00
|
|
|
record.decrypt(keyBundle);
|
2010-08-12 13:19:41 -07:00
|
|
|
do_check_eq(record.id, "ascii");
|
|
|
|
do_check_eq(record.name, "wéävê");
|
|
|
|
|
|
|
|
_("Sanity check that creating the record also gives the same");
|
2012-08-29 14:43:41 -07:00
|
|
|
record = engine._createRecord("ascii");
|
2010-08-12 13:19:41 -07:00
|
|
|
do_check_eq(record.id, "ascii");
|
|
|
|
do_check_eq(record.name, "wéävê");
|
|
|
|
} finally {
|
|
|
|
Svc.Prefs.resetBranch("");
|
|
|
|
}
|
2009-08-06 11:28:33 -07:00
|
|
|
}
|