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

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 <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2024-03-27 10:20:29 +01:00
committed by GitHub
parent d2c14f1c6c
commit 3b025ec0c7
4 changed files with 49 additions and 0 deletions

View File

@@ -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"]
}
}

View File

@@ -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);

View File

@@ -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',

View File

@@ -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));
});
}
};