fix: IncrementCapturerCount doesn't increase the capturer count (#32973)
This commit is contained in:
parent
59246a4c7c
commit
108ee7037f
3 changed files with 84 additions and 2 deletions
|
@ -3127,8 +3127,9 @@ void WebContents::IncrementCapturerCount(gin::Arguments* args) {
|
|||
// get stayAwake arguments if they exist
|
||||
args->GetNext(&stay_awake);
|
||||
|
||||
std::ignore =
|
||||
web_contents()->IncrementCapturerCount(size, stay_hidden, stay_awake);
|
||||
std::ignore = web_contents()
|
||||
->IncrementCapturerCount(size, stay_hidden, stay_awake)
|
||||
.Release();
|
||||
}
|
||||
|
||||
void WebContents::DecrementCapturerCount(gin::Arguments* args) {
|
||||
|
|
|
@ -302,4 +302,66 @@ describe('BrowserView module', () => {
|
|||
view.webContents.loadFile(path.join(fixtures, 'pages', 'window-open.html'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('BrowserView.capturePage(rect)', () => {
|
||||
it('returns a Promise with a Buffer', async () => {
|
||||
view = new BrowserView({
|
||||
webPreferences: {
|
||||
backgroundThrottling: false
|
||||
}
|
||||
});
|
||||
w.addBrowserView(view);
|
||||
view.setBounds({
|
||||
...w.getBounds(),
|
||||
x: 0,
|
||||
y: 0
|
||||
});
|
||||
const image = await view.webContents.capturePage({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100
|
||||
});
|
||||
|
||||
expect(image.isEmpty()).to.equal(true);
|
||||
});
|
||||
|
||||
xit('resolves after the window is hidden and capturer count is non-zero', async () => {
|
||||
view = new BrowserView({
|
||||
webPreferences: {
|
||||
backgroundThrottling: false
|
||||
}
|
||||
});
|
||||
w.setBrowserView(view);
|
||||
view.setBounds({
|
||||
...w.getBounds(),
|
||||
x: 0,
|
||||
y: 0
|
||||
});
|
||||
await view.webContents.loadFile(path.join(fixtures, 'pages', 'a.html'));
|
||||
|
||||
view.webContents.incrementCapturerCount();
|
||||
const image = await view.webContents.capturePage();
|
||||
expect(image.isEmpty()).to.equal(false);
|
||||
});
|
||||
|
||||
it('should increase the capturer count', () => {
|
||||
view = new BrowserView({
|
||||
webPreferences: {
|
||||
backgroundThrottling: false
|
||||
}
|
||||
});
|
||||
w.setBrowserView(view);
|
||||
view.setBounds({
|
||||
...w.getBounds(),
|
||||
x: 0,
|
||||
y: 0
|
||||
});
|
||||
|
||||
view.webContents.incrementCapturerCount();
|
||||
expect(view.webContents.isBeingCaptured()).to.be.true();
|
||||
view.webContents.decrementCapturerCount();
|
||||
expect(view.webContents.isBeingCaptured()).to.be.false();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1453,6 +1453,17 @@ describe('BrowserWindow module', () => {
|
|||
expect(hiddenImage.isEmpty()).to.equal(isEmpty);
|
||||
});
|
||||
|
||||
it('resolves after the window is hidden and capturer count is non-zero', async () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.webContents.setBackgroundThrottling(false);
|
||||
w.loadFile(path.join(fixtures, 'pages', 'a.html'));
|
||||
await emittedOnce(w, 'ready-to-show');
|
||||
|
||||
w.webContents.incrementCapturerCount();
|
||||
const image = await w.capturePage();
|
||||
expect(image.isEmpty()).to.equal(false);
|
||||
});
|
||||
|
||||
it('preserves transparency', async () => {
|
||||
const w = new BrowserWindow({ show: false, transparent: true });
|
||||
w.loadFile(path.join(fixtures, 'pages', 'theme-color.html'));
|
||||
|
@ -1466,6 +1477,14 @@ describe('BrowserWindow module', () => {
|
|||
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
|
||||
expect(imgBuffer[25]).to.equal(6);
|
||||
});
|
||||
|
||||
it('should increase the capturer count', () => {
|
||||
const w = new BrowserWindow({ show: false });
|
||||
w.webContents.incrementCapturerCount();
|
||||
expect(w.webContents.isBeingCaptured()).to.be.true();
|
||||
w.webContents.decrementCapturerCount();
|
||||
expect(w.webContents.isBeingCaptured()).to.be.false();
|
||||
});
|
||||
});
|
||||
|
||||
describe('BrowserWindow.setProgressBar(progress)', () => {
|
||||
|
|
Loading…
Reference in a new issue