Skip to content

Commit

Permalink
test: add test and api_feature definition for `chrome.scripting.glo…
Browse files Browse the repository at this point in the history
…balParams` (#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>
  • Loading branch information
trop[bot] and codebytere committed Mar 27, 2024
1 parent d2c14f1 commit 3b025ec
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions shell/common/extensions/api/_api_features.json
Expand Up @@ -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"],
Expand Down Expand Up @@ -68,5 +76,10 @@
"scripting": {
"dependencies": ["permission:scripting"],
"contexts": ["blessed_extension"]
},
"scripting.globalParams": {
"channel": "trunk",
"dependencies": ["permission:scripting"],
"contexts": ["content_script"]
}
}
10 changes: 10 additions & 0 deletions spec/extensions-spec.ts
Expand Up @@ -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);

Expand Down
21 changes: 21 additions & 0 deletions spec/fixtures/extensions/chrome-scripting/background.js
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/extensions/chrome-scripting/main.js
Expand Up @@ -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));
});
}
};

Expand Down

0 comments on commit 3b025ec

Please sign in to comment.