test_bug808734.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. var Cu = Components.utils;
  2. const READWRITE = "readwrite";
  3. const UNKNOWN = "foobar";
  4. var gData = [
  5. // test normal expansion
  6. {
  7. permission: "contacts",
  8. access: READWRITE,
  9. expected: ["contacts-read", "contacts-create",
  10. "contacts-write"]
  11. },
  12. // test additional expansion and access not having read+create+write
  13. {
  14. permission: "settings",
  15. access: READWRITE,
  16. expected: ["settings-read", "settings-write",
  17. "settings-api-read", "settings-api-write",
  18. "indexedDB-chrome-settings-read",
  19. "indexedDB-chrome-settings-write"]
  20. },
  21. // test unknown access
  22. {
  23. permission: "contacts",
  24. access: UNKNOWN,
  25. expected: []
  26. },
  27. // test unknown permission
  28. {
  29. permission: UNKNOWN,
  30. access: READWRITE,
  31. expected: []
  32. }
  33. ];
  34. // check if 2 arrays contain the same elements
  35. function do_check_set_eq(a1, a2) {
  36. do_check_eq(a1.length, a2.length)
  37. Array.sort(a1);
  38. Array.sort(a2);
  39. for (let i = 0; i < a1.length; ++i) {
  40. do_check_eq(a1[i], a2[i])
  41. }
  42. }
  43. function test_substitute_does_not_break_substituted(scope) {
  44. const Ci = Components.interfaces;
  45. // geolocation-noprompt substitutes for geolocation ...
  46. do_check_eq(scope.PermissionsTable["geolocation-noprompt"].substitute[0],
  47. "geolocation");
  48. // ... and sets silent allow ...
  49. do_check_eq(scope.PermissionsTable["geolocation-noprompt"].certified,
  50. Ci.nsIPermissionManager.ALLOW_ACTION)
  51. // ... which works ...
  52. do_check_false(scope.isExplicitInPermissionsTable("geolocation-noprompt", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
  53. // ... but does not interfere with geolocation's PROMPT value
  54. do_check_true(scope.isExplicitInPermissionsTable("geolocation", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
  55. }
  56. function run_test() {
  57. var scope = {};
  58. Cu.import("resource://gre/modules/PermissionsTable.jsm", scope);
  59. for (var i = 0; i < gData.length; i++) {
  60. var perms = scope.expandPermissions(gData[i].permission,
  61. gData[i].access);
  62. do_check_set_eq(perms, gData[i].expected);
  63. }
  64. test_substitute_does_not_break_substituted(scope);
  65. }