Browse Source

test: add test and `api_feature` definition for `chrome.scripting.globalParams` (#41685)

chore: add test and api_feature for chrome.scripting.globalParams
Shelley Vohr 1 year ago
parent
commit
7032c0d03c

+ 13 - 0
shell/common/extensions/api/_api_features.json

@@ -39,6 +39,14 @@
     "contexts": ["blessed_extension", "unblessed_extension", "content_script"],
     "max_manifest_version": 2
   },
+  "extension.lastError": {
+    "contexts": [
+      "blessed_extension",
+      "unblessed_extension",
+      "content_script"
+    ],
+    "max_manifest_version": 2
+  },
   "i18n": {
     "channel": "stable",
     "extension_types": ["extension"],
@@ -68,5 +76,10 @@
   "scripting": {
     "dependencies": ["permission:scripting"],
     "contexts": ["blessed_extension"]
+  },
+  "scripting.globalParams": {
+    "channel": "trunk",
+    "dependencies": ["permission:scripting"],
+    "contexts": ["content_script"]
   }
 }

+ 10 - 0
spec/extensions-spec.ts

@@ -1285,6 +1285,16 @@ describe('chrome extensions', () => {
         });
       });
 
+      it('globalParams', async () => {
+        await w.loadURL(url);
+
+        const message = { method: 'globalParams' };
+        w.webContents.executeJavaScript(`window.postMessage('${JSON.stringify(message)}', '*')`);
+        const [,, responseString] = await once(w.webContents, 'console-message');
+        const response = JSON.parse(responseString);
+        expect(response).to.deep.equal({ changed: true });
+      });
+
       it('insertCSS', async () => {
         await w.loadURL(url);
 

+ 21 - 0
spec/fixtures/extensions/chrome-scripting/background.js

@@ -20,6 +20,27 @@ const handleRequest = async (request, sender, sendResponse) => {
       break;
     }
 
+    case 'globalParams' : {
+      await chrome.scripting.executeScript({
+        target: { tabId },
+        func: () => {
+          chrome.scripting.globalParams.changed = true;
+        },
+        world: 'ISOLATED'
+      });
+
+      const results = await chrome.scripting.executeScript({
+        target: { tabId },
+        func: () => JSON.stringify(chrome.scripting.globalParams),
+        world: 'ISOLATED'
+      });
+
+      const result = JSON.parse(results[0].result);
+
+      sendResponse(result);
+      break;
+    }
+
     case 'registerContentScripts': {
       await chrome.scripting.registerContentScripts([{
         id: 'session-script',

+ 5 - 0
spec/fixtures/extensions/chrome-scripting/main.js

@@ -19,6 +19,11 @@ const map = {
     chrome.runtime.sendMessage({ method: 'insertCSS' }, response => {
       console.log(JSON.stringify(response));
     });
+  },
+  globalParams () {
+    chrome.runtime.sendMessage({ method: 'globalParams' }, response => {
+      console.log(JSON.stringify(response));
+    });
   }
 };