1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const { Service } = ChromeUtils.import("resource://services-sync/service.js");
add_task(async function test_clients_escape() {
_("Set up test fixtures.");
await configureIdentity();
let keyBundle = Service.identity.syncKeyBundle;
let engine = Service.clientsEngine;
try {
_("Test that serializing client records results in uploadable ascii");
engine.localID = "ascii";
engine.localName = "wéävê";
_("Make sure we have the expected record");
let record = await engine._createRecord("ascii");
Assert.equal(record.id, "ascii");
Assert.equal(record.name, "wéävê");
_("Encrypting record...");
await record.encrypt(keyBundle);
_("Encrypted.");
let serialized = JSON.stringify(record);
let checkCount = 0;
_("Checking for all ASCII:", serialized);
for (let ch of serialized) {
let code = ch.charCodeAt(0);
_("Checking asciiness of '", ch, "'=", code);
Assert.ok(code < 128);
checkCount++;
}
_("Processed", checkCount, "characters out of", serialized.length);
Assert.equal(checkCount, serialized.length);
_("Making sure the record still looks like it did before");
await record.decrypt(keyBundle);
Assert.equal(record.id, "ascii");
Assert.equal(record.name, "wéävê");
_("Sanity check that creating the record also gives the same");
record = await engine._createRecord("ascii");
Assert.equal(record.id, "ascii");
Assert.equal(record.name, "wéävê");
} finally {
Svc.Prefs.resetBranch("");
}
});
|