From ba1e7fcaa718b233c45aef1233a34d1c50e28896 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:21:04 +0100 Subject: [PATCH] test: add test and `api_feature` definition for `chrome.scripting.globalParams` (#41700) chore: add test and api_feature for chrome.scripting.globalParams Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- .../common/extensions/api/_api_features.json | 13 ++++++++++++ spec/extensions-spec.ts | 10 +++++++++ .../extensions/chrome-scripting/background.js | 21 +++++++++++++++++++ .../extensions/chrome-scripting/main.js | 5 +++++ 4 files changed, 49 insertions(+) diff --git a/shell/common/extensions/api/_api_features.json b/shell/common/extensions/api/_api_features.json index 1358a507e1b0..a04c487c90dd 100644 --- a/shell/common/extensions/api/_api_features.json +++ b/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"] } } diff --git a/spec/extensions-spec.ts b/spec/extensions-spec.ts index 97605c62fe79..d6fe871447d8 100644 --- a/spec/extensions-spec.ts +++ b/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); diff --git a/spec/fixtures/extensions/chrome-scripting/background.js b/spec/fixtures/extensions/chrome-scripting/background.js index 9c080286c06b..53a02b1065d0 100644 --- a/spec/fixtures/extensions/chrome-scripting/background.js +++ b/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', diff --git a/spec/fixtures/extensions/chrome-scripting/main.js b/spec/fixtures/extensions/chrome-scripting/main.js index 07aa7d800759..9528d572976f 100644 --- a/spec/fixtures/extensions/chrome-scripting/main.js +++ b/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)); + }); } };