Bug 1375485 - Add test to verify that requesting an origin or permission in the wrong field throws an error. r=aswan
authorIan Moody <moz-ian@perix.co.uk>
Sat, 23 Sep 2017 17:43:43 +0100
changeset 383500 4c664d3d37fa46fc4175e7eaa766302e0fd49896
parent 383499 d3efdc909cb923712a71d9edfceb40c4ea317df8
child 383501 8547b76f8dfef0e55d8c8c3690fca1cfb19a798c
push id32594
push userkwierso@gmail.com
push dateThu, 28 Sep 2017 22:49:33 +0000
treeherdermozilla-central@6dea0ee45b66 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1375485
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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");