Bug 1696043 convert schema format for MV3 content_security_policy r=robwu
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 30 Apr 2021 20:31:39 +0000
changeset 578239 e6750f6a366e740b068f9f8229d0ae9db5b0466c
parent 578238 a56202a0d7431986ab4cb066ac1540f06a1dada2
child 578240 b3a61c80f9f2374c2af1b37391b5185efa8f0fbb
push id142346
push userscaraveo@mozilla.com
push dateFri, 30 Apr 2021 20:34:14 +0000
treeherderautoland@4558336cea00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu
bugs1696043
milestone90.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 1696043 convert schema format for MV3 content_security_policy r=robwu Differential Revision: https://phabricator.services.mozilla.com/D105846
toolkit/components/extensions/schemas/manifest.json
toolkit/components/extensions/test/xpcshell/test_ext_content_security_policy.js
toolkit/components/extensions/test/xpcshell/test_ext_manifest_content_security_policy.js
--- a/toolkit/components/extensions/schemas/manifest.json
+++ b/toolkit/components/extensions/schemas/manifest.json
@@ -185,20 +185,22 @@
             "items": { "$ref": "ContentScript" }
           },
 
           "content_security_policy": {
             "optional": true,
             "onError": "warn",
             "choices": [
               {
+                "max_manifest_version": 2,
                 "type": "string",
                 "format": "contentSecurityPolicy"
               },
               {
+                "min_manifest_version": 3,
                 "type": "object",
                 "additionalProperties": {
                   "$ref": "UnrecognizedProperty"
                 },
                 "properties": {
                   "extension_pages": {
                     "type": "string",
                     "optional": true,
--- a/toolkit/components/extensions/test/xpcshell/test_ext_content_security_policy.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_content_security_policy.js
@@ -125,16 +125,23 @@ async function testPolicy(manifest_versi
         importScripts(`http://127.0.0.1:${port}/worker.js`);
         postMessage({ loaded: true });
       } catch (e) {
         postMessage({ loaded: false });
       }
     };
   }
 
+  if (manifest_version == 3) {
+    let extension_pages = content_security_policy;
+    content_security_policy = {
+      extension_pages,
+    };
+  }
+
   let extension = ExtensionTestUtils.loadExtension({
     background,
 
     files: {
       "tab.html": `<html><head><meta charset="utf-8">
                    <script src="tab.js"></${"script"}></head></html>`,
 
       "tab.js": tabScript,
--- a/toolkit/components/extensions/test/xpcshell/test_ext_manifest_content_security_policy.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_manifest_content_security_policy.js
@@ -33,21 +33,53 @@ add_task(async function test_manifest_cs
     "Should have the expected warning"
   );
 
   equal(
     normalized.value.content_security_policy,
     null,
     "Invalid policy string should be omitted"
   );
+
+  ExtensionTestUtils.failOnSchemaWarnings(false);
+  normalized = await ExtensionTestUtils.normalizeManifest({
+    manifest_version: 2,
+    content_security_policy: {
+      extension_pages: "script-src 'self'; object-src 'none'",
+    },
+  });
+  ExtensionTestUtils.failOnSchemaWarnings(true);
+
+  Assert.deepEqual(
+    normalized.errors,
+    [
+      `Error processing content_security_policy: Expected string instead of {"extension_pages":"script-src 'self'; object-src 'none'"}`,
+    ],
+    "Should have the expected warning"
+  );
 });
 
 add_task(async function test_manifest_csp_v3() {
+  ExtensionTestUtils.failOnSchemaWarnings(false);
   let normalized = await ExtensionTestUtils.normalizeManifest({
     manifest_version: 3,
+    content_security_policy: "script-src 'self'; object-src 'none'",
+  });
+  ExtensionTestUtils.failOnSchemaWarnings(true);
+
+  Assert.deepEqual(
+    normalized.errors,
+    [
+      `Error processing content_security_policy: Expected object instead of "script-src 'self'; object-src 'none'"`,
+    ],
+    "Should have the expected warning"
+  );
+
+  normalized = await ExtensionTestUtils.normalizeManifest({
+    manifest_version: 3,
     content_security_policy: {
       extension_pages: "script-src 'self' 'unsafe-eval'; object-src 'none'",
     },
   });
 
   Assert.deepEqual(
     normalized.errors,
     [