test: BrowserWindow backgroundColor and transparency (#31017)

* test: BrowserWindow backgroundColor

* test: allow similar colors

* test: disable linux capturing

* refactor: split screen capture from reading pixel color
This commit is contained in:
Samuel Maddock 2022-03-01 14:14:11 -08:00 committed by GitHub
parent 283fa2b79d
commit 7cb62bfc22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 172 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import { app, BrowserWindow, BrowserView, dialog, ipcMain, OnBeforeSendHeadersLi
import { emittedOnce, emittedUntil, emittedNTimes } from './events-helpers';
import { ifit, ifdescribe, defer, delay } from './spec-helpers';
import { closeWindow, closeAllWindows } from './window-helpers';
import { areColorsSimilar, captureScreen, CHROMA_COLOR_HEX, getPixelColor } from './screen-helpers';
const features = process._linkedBinding('electron_common_features');
const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures');
@ -4872,5 +4873,69 @@ describe('BrowserWindow module', () => {
w.setBounds(newBounds);
expect(w.getBounds()).to.deep.equal(newBounds);
});
// Linux doesn't return any capture sources.
ifit(process.platform !== 'linux')('should not display a visible background', async () => {
const display = screen.getPrimaryDisplay();
const backgroundWindow = new BrowserWindow({
...display.bounds,
frame: false,
backgroundColor: CHROMA_COLOR_HEX,
hasShadow: false
});
await backgroundWindow.loadURL('about:blank');
const foregroundWindow = new BrowserWindow({
...display.bounds,
show: true,
transparent: true,
frame: false,
hasShadow: false
});
foregroundWindow.loadFile(path.join(__dirname, 'fixtures', 'pages', 'half-background-color.html'));
await emittedOnce(foregroundWindow, 'ready-to-show');
const screenCapture = await captureScreen();
const leftHalfColor = getPixelColor(screenCapture, {
x: display.size.width / 4,
y: display.size.height / 2
});
const rightHalfColor = getPixelColor(screenCapture, {
x: display.size.width - (display.size.width / 4),
y: display.size.height / 2
});
expect(areColorsSimilar(leftHalfColor, CHROMA_COLOR_HEX)).to.be.true();
expect(areColorsSimilar(rightHalfColor, '#ff0000')).to.be.true();
});
});
describe('"backgroundColor" option', () => {
afterEach(closeAllWindows);
// Linux doesn't return any capture sources.
ifit(process.platform !== 'linux')('should display the set color', async () => {
const display = screen.getPrimaryDisplay();
const w = new BrowserWindow({
...display.bounds,
show: true,
backgroundColor: CHROMA_COLOR_HEX
});
w.loadURL('about:blank');
await emittedOnce(w, 'ready-to-show');
const screenCapture = await captureScreen();
const centerColor = getPixelColor(screenCapture, {
x: display.size.width / 2,
y: display.size.height / 2
});
expect(areColorsSimilar(centerColor, CHROMA_COLOR_HEX)).to.be.true();
});
});
});