|
1 Cu.import("resource://services-sync/util.js"); |
|
2 |
|
3 const base64url = |
|
4 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"; |
|
5 |
|
6 function run_test() { |
|
7 _("Make sure makeGUID makes guids of the right length/characters"); |
|
8 _("Create a bunch of guids to make sure they don't conflict"); |
|
9 let guids = []; |
|
10 for (let i = 0; i < 1000; i++) { |
|
11 let newGuid = Utils.makeGUID(); |
|
12 _("Generated " + newGuid); |
|
13 |
|
14 // Verify that the GUID's length is correct, even when it's URL encoded. |
|
15 do_check_eq(newGuid.length, 12); |
|
16 do_check_eq(encodeURIComponent(newGuid).length, 12); |
|
17 |
|
18 // Verify that the GUID only contains base64url characters |
|
19 do_check_true(Array.every(newGuid, function(chr) { |
|
20 return base64url.indexOf(chr) != -1; |
|
21 })); |
|
22 |
|
23 // Verify that Utils.checkGUID() correctly identifies them as valid. |
|
24 do_check_true(Utils.checkGUID(newGuid)); |
|
25 |
|
26 // Verify uniqueness within our sample of 1000. This could cause random |
|
27 // failures, but they should be extremely rare. Otherwise we'd have a |
|
28 // problem with GUID collisions. |
|
29 do_check_true(guids.every(function(g) { return g != newGuid; })); |
|
30 guids.push(newGuid); |
|
31 } |
|
32 |
|
33 _("Make sure checkGUID fails for invalid GUIDs"); |
|
34 do_check_false(Utils.checkGUID(undefined)); |
|
35 do_check_false(Utils.checkGUID(null)); |
|
36 do_check_false(Utils.checkGUID("")); |
|
37 do_check_false(Utils.checkGUID("blergh")); |
|
38 do_check_false(Utils.checkGUID("ThisGUIDisWayTooLong")); |
|
39 do_check_false(Utils.checkGUID("Invalid!!!!!")); |
|
40 } |