Bug 1375485 - Add test to verify that requesting an origin or permission in the wrong field throws an error. r?aswan draft
authorIan Moody <moz-ian@perix.co.uk>
Sat, 23 Sep 2017 17:43:43 +0100
changeset 671225 3be2e679b7f85ebffb416438663182413b205936
parent 671224 0d2f4b0e7736dbb41169c2690e716b5f48b43d92
child 733459 807d14f3cc2f744b72571ac99b6c64ac83624138
push id81875
push usermoz-ian@perix.co.uk
push dateWed, 27 Sep 2017 16:31:29 +0000
reviewersaswan
bugs1375485
milestone58.0a1
Bug 1375485 - Add test to verify that requesting an origin or permission in the wrong field throws an error. r?aswan MozReview-Commit-ID: HZwkeUoGDRW
toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
--- a/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_permissions.js
@@ -171,16 +171,34 @@ add_task(async function test_permissions
     acceptPrompt = true;
     let allOptional = {
       permissions: OPTIONAL_PERMISSIONS,
       origins: OPTIONAL_ORIGINS,
     };
     result = await call("request", allOptional);
     equal(result.status, "success", "request() returned cleanly");
     equal(result.result, true, "request() returned true for accepted permissions");
+
+    // Verify that requesting a permission/origin in the wrong field fails
+    let originsAsPerms = {
+      permissions: OPTIONAL_ORIGINS,
+    };
+    let permsAsOrigins = {
+      origins: OPTIONAL_PERMISSIONS,
+    };
+
+    result = await call("request", originsAsPerms);
+    equal(result.status, "error", "Requesting an origin as a permission should fail");
+    ok(/Type error for parameter permissions \(Error processing permissions/.test(result.message),
+       "Error message for origin as permission is reasonable");
+
+    result = await call("request", permsAsOrigins);
+    equal(result.status, "error", "Requesting a permission as an origin should fail");
+    ok(/Type error for parameter permissions \(Error processing origins/.test(result.message),
+       "Error message for permission as origin is reasonable");
   });
 
   let allPermissions = {
     permissions: [...REQUIRED_PERMISSIONS, ...OPTIONAL_PERMISSIONS],
     origins: [...REQUIRED_ORIGINS_NORMALIZED, ...OPTIONAL_ORIGINS_NORMALIZED],
   };
 
   result = await call("getAll");