michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-sync/keys.js"); michael@0: Cu.import("resource://services-sync/record.js"); michael@0: Cu.import("resource://services-sync/service.js"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: Cu.import("resource://testing-common/services/sync/utils.js"); michael@0: michael@0: function run_test() { michael@0: _("Set up test fixtures."); michael@0: michael@0: ensureLegacyIdentityManager(); michael@0: Service.identity.username = "john@example.com"; michael@0: Service.clusterURL = "http://fakebase/"; michael@0: let baseUri = "http://fakebase/1.1/foo/storage/"; michael@0: let pubUri = baseUri + "keys/pubkey"; michael@0: let privUri = baseUri + "keys/privkey"; michael@0: michael@0: Service.identity.syncKey = "abcdeabcdeabcdeabcdeabcdea"; michael@0: let keyBundle = Service.identity.syncKeyBundle; michael@0: michael@0: let engine = Service.clientsEngine; michael@0: michael@0: try { michael@0: _("Test that serializing client records results in uploadable ascii"); michael@0: engine.localID = "ascii"; michael@0: engine.localName = "wéävê"; michael@0: michael@0: _("Make sure we have the expected record"); michael@0: let record = engine._createRecord("ascii"); michael@0: do_check_eq(record.id, "ascii"); michael@0: do_check_eq(record.name, "wéävê"); michael@0: michael@0: _("Encrypting record..."); michael@0: record.encrypt(keyBundle); michael@0: _("Encrypted."); michael@0: michael@0: let serialized = JSON.stringify(record); michael@0: let checkCount = 0; michael@0: _("Checking for all ASCII:", serialized); michael@0: Array.forEach(serialized, function(ch) { michael@0: let code = ch.charCodeAt(0); michael@0: _("Checking asciiness of '", ch, "'=", code); michael@0: do_check_true(code < 128); michael@0: checkCount++; michael@0: }); michael@0: michael@0: _("Processed", checkCount, "characters out of", serialized.length); michael@0: do_check_eq(checkCount, serialized.length); michael@0: michael@0: _("Making sure the record still looks like it did before"); michael@0: record.decrypt(keyBundle); michael@0: do_check_eq(record.id, "ascii"); michael@0: do_check_eq(record.name, "wéävê"); michael@0: michael@0: _("Sanity check that creating the record also gives the same"); michael@0: record = engine._createRecord("ascii"); michael@0: do_check_eq(record.id, "ascii"); michael@0: do_check_eq(record.name, "wéävê"); michael@0: } finally { michael@0: Svc.Prefs.resetBranch(""); michael@0: } michael@0: }