Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add chrome.runtime.getManifest (#16891)
* feat: add chrome.runtime.getManifest * Add test for chrome.runtime.getManifest * Use IPC utils for getManifest internals
- Loading branch information
1 parent
46f818b
commit 8f6a543
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const { expect } = require('chai') | ||
const { remote } = require('electron') | ||
|
||
const { closeWindow } = require('./window-helpers') | ||
const { emittedOnce } = require('./events-helpers') | ||
|
||
const { BrowserWindow } = remote | ||
|
||
describe('chrome api', () => { | ||
const fixtures = path.resolve(__dirname, 'fixtures') | ||
let w | ||
|
||
before(() => { | ||
BrowserWindow.addExtension(path.join(fixtures, 'extensions/chrome-api')) | ||
}) | ||
|
||
after(() => { | ||
BrowserWindow.removeExtension('chrome-api') | ||
}) | ||
|
||
beforeEach(() => { | ||
w = new BrowserWindow({ | ||
show: false | ||
}) | ||
}) | ||
|
||
afterEach(() => closeWindow(w).then(() => { w = null })) | ||
|
||
it('runtime.getManifest returns extension manifest', async () => { | ||
const actualManifest = (() => { | ||
const data = fs.readFileSync(path.join(fixtures, 'extensions/chrome-api/manifest.json'), 'utf-8') | ||
return JSON.parse(data) | ||
})() | ||
|
||
w.loadURL('about:blank') | ||
|
||
const p = emittedOnce(w.webContents, 'console-message') | ||
w.webContents.executeJavaScript(`window.postMessage('getManifest', '*')`) | ||
const [,, manifestString] = await p | ||
const manifest = JSON.parse(manifestString) | ||
|
||
expect(manifest.name).to.equal(actualManifest.name) | ||
expect(manifest.content_scripts.length).to.equal(actualManifest.content_scripts.length) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global chrome */ | ||
|
||
const testMap = { | ||
getManifest () { | ||
const manifest = chrome.runtime.getManifest() | ||
console.log(JSON.stringify(manifest)) | ||
} | ||
} | ||
|
||
const dispatchTest = (event) => { | ||
const testName = event.data | ||
const test = testMap[testName] | ||
test() | ||
} | ||
window.addEventListener('message', dispatchTest, false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "chrome-api", | ||
"version": "1.0", | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["main.js"], | ||
"run_at": "document_start" | ||
} | ||
], | ||
"manifest_version": 2 | ||
} |