test_macosparser_unflatten.js (3172B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 let { macOSPoliciesParser } = ChromeUtils.importESModule( 7 "resource://gre/modules/policies/macOSPoliciesParser.sys.mjs" 8 ); 9 10 add_task(async function test_object_unflatten() { 11 // Note: these policies are just examples and they won't actually 12 // run through the policy engine on this test. We're just testing 13 // that the unflattening algorithm produces the correct output. 14 let input = { 15 DisplayBookmarksToolbar: true, 16 17 Homepage__URL: "https://www.mozilla.org", 18 Homepage__Locked: "true", 19 Homepage__Additional__0: "https://extra-homepage-1.example.com", 20 Homepage__Additional__1: "https://extra-homepage-2.example.com", 21 22 WebsiteFilter__Block__0: "*://*.example.org/*", 23 WebsiteFilter__Block__1: "*://*.example.net/*", 24 WebsiteFilter__Exceptions__0: "*://*.example.org/*exception*", 25 26 Permissions__Camera__Allow__0: "https://www.example.com", 27 28 Permissions__Notifications__Allow__0: "https://www.example.com", 29 Permissions__Notifications__Allow__1: "https://www.example.org", 30 Permissions__Notifications__Block__0: "https://www.example.net", 31 32 Permissions__Notifications__BlockNewRequests: true, 33 Permissions__Notifications__Locked: true, 34 35 Bookmarks__0__Title: "Bookmark 1", 36 Bookmarks__0__URL: "https://bookmark1.example.com", 37 38 Bookmarks__1__Title: "Bookmark 2", 39 Bookmarks__1__URL: "https://bookmark2.example.com", 40 Bookmarks__1__Folder: "Folder", 41 }; 42 43 let expected = { 44 DisplayBookmarksToolbar: true, 45 46 Homepage: { 47 URL: "https://www.mozilla.org", 48 Locked: "true", 49 Additional: [ 50 "https://extra-homepage-1.example.com", 51 "https://extra-homepage-2.example.com", 52 ], 53 }, 54 55 WebsiteFilter: { 56 Block: ["*://*.example.org/*", "*://*.example.net/*"], 57 Exceptions: ["*://*.example.org/*exception*"], 58 }, 59 60 Permissions: { 61 Camera: { 62 Allow: ["https://www.example.com"], 63 }, 64 65 Notifications: { 66 Allow: ["https://www.example.com", "https://www.example.org"], 67 Block: ["https://www.example.net"], 68 BlockNewRequests: true, 69 Locked: true, 70 }, 71 }, 72 73 Bookmarks: [ 74 { 75 Title: "Bookmark 1", 76 URL: "https://bookmark1.example.com", 77 }, 78 { 79 Title: "Bookmark 2", 80 URL: "https://bookmark2.example.com", 81 Folder: "Folder", 82 }, 83 ], 84 }; 85 86 let unflattened = macOSPoliciesParser.unflatten(input); 87 88 deepEqual(unflattened, expected, "Input was unflattened correctly."); 89 }); 90 91 add_task(async function test_array_unflatten() { 92 let input = { 93 Foo__1: 1, 94 Foo__5: 5, 95 Foo__10: 10, 96 Foo__30: 30, 97 Foo__51: 51, // This one should not be included as the limit is 50 98 }; 99 100 let unflattened = macOSPoliciesParser.unflatten(input); 101 equal(unflattened.Foo.length, 31, "Array size is correct"); 102 103 let expected = { 104 Foo: [, 1, , , , 5], // eslint-disable-line no-sparse-arrays 105 }; 106 expected.Foo[10] = 10; 107 expected.Foo[30] = 30; 108 109 deepEqual(unflattened, expected, "Array was unflattened correctly."); 110 });