Compare commits

...

5 Commits

Author SHA1 Message Date
Jeremy Rose
20ebebfc6a fix test 2022-04-06 10:29:53 -07:00
Jeremy Rose
790142aada Update chromium-spec.ts 2022-04-05 09:54:15 -07:00
Jeremy Rose
027da79a42 force-color-profile=srgb 2022-04-04 16:08:55 -07:00
Jeremy Rose
af9168f6b2 Merge branch 'main' into pdf-tests 2022-04-04 15:43:07 -07:00
Jeremy Rose
b9549ef52d test: improve test coverage of pdf viewer 2022-03-25 14:04:46 -07:00
3 changed files with 58 additions and 9 deletions

View File

@@ -1155,7 +1155,7 @@ steps-tests: &steps-tests
export LLVM_SYMBOLIZER_PATH=$PWD/third_party/llvm-build/Release+Asserts/bin/llvm-symbolizer
export MOCHA_TIMEOUT=180000
echo "Piping output to ASAN_SYMBOLIZE ($ASAN_SYMBOLIZE)"
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --force-color-profile=srgb --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE
(cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split --split-by=timings)) 2>&1 | $ASAN_SYMBOLIZE
else
if [ "$TARGET_ARCH" == "arm" ] || [ "$TARGET_ARCH" == "arm64" ]; then
@@ -1166,7 +1166,7 @@ steps-tests: &steps-tests
if [ "$TARGET_ARCH" == "ia32" ]; then
npm_config_arch=x64 node electron/node_modules/dugite/script/download-git.js
fi
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings))
(cd electron && node script/yarn test --runners=main --trace-uncaught --enable-logging --force-color-profile=srgb --files $(circleci tests glob spec-main/*-spec.ts | circleci tests split --split-by=timings))
(cd electron && node script/yarn test --runners=remote --trace-uncaught --enable-logging --files $(circleci tests glob spec/*-spec.js | circleci tests split --split-by=timings))
fi
fi

View File

@@ -1421,20 +1421,67 @@ describe('chromium features', () => {
protocol: 'file',
slashes: true
});
const redPdfSource = url.format({
pathname: path.join(__dirname, 'fixtures', 'red.pdf').replace(/\\/g, '/'),
protocol: 'file',
slashes: true
});
async function ensurePdfLoaded (webContents: WebContents) {
const result = await webContents.executeJavaScript(`new Promise(resolve => {
window.addEventListener('message', event => {
if (event.origin !==
'chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai') {
return;
}
if (event.data.type === 'documentLoaded') {
resolve(event.data.load_state === 'success');
}
});
document.getElementsByTagName('embed')[0].postMessage({type: 'initialize'});
})`);
expect(result).to.be.true();
}
it('successfully loads a PDF file', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(pdfSource);
await emittedOnce(w.webContents, 'did-finish-load');
await ensurePdfLoaded(w.webContents);
});
it('opens when loading a pdf resource as top level navigation', async () => {
const w = new BrowserWindow({ show: false });
w.loadURL(pdfSource);
const [, contents] = await emittedOnce(app, 'web-contents-created');
await emittedOnce(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
it('renders a PDF', async () => {
const w = new BrowserWindow({ show: true, width: 600, height: 600 });
w.loadURL(redPdfSource);
await ensurePdfLoaded(w.webContents);
// Try a few times to allow rendering to settle.
const numRetries = 100;
for (let i = 1; i <= numRetries; i++) {
const image = await w.webContents.capturePage();
const bitmap = image.getBitmap();
// Compensate for high-dpi displays.
const { width, height } = image.getSize();
const [windowWidth, windowHeight] = w.getContentSize();
const x = (445 * width / windowWidth) | 0;
const y = (145 * height / windowHeight) | 0;
const color = {
b: bitmap[(y * 1000 + x) * 4],
g: bitmap[(y * 1000 + x) * 4 + 1],
r: bitmap[(y * 1000 + x) * 4 + 2]
};
try {
expect(color).to.deep.equal({ r: 255, g: 0, b: 0 });
} catch (e) {
if (i < numRetries) {
await delay(100);
continue;
}
throw e;
}
break;
}
});
it('opens when loading a pdf resource in a iframe', async () => {
@@ -1443,6 +1490,8 @@ describe('chromium features', () => {
const [, contents] = await emittedOnce(app, 'web-contents-created');
await emittedOnce(contents, 'did-navigate');
expect(contents.getURL()).to.equal('chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html');
// TODO(nornagon): this doesn't actually check that the pdf in the iframe
// loaded.
});
});

BIN
spec-main/fixtures/red.pdf Normal file

Binary file not shown.