test: add e2e test to ensure we ship with non audio/video codecs (#2604)

This commit is contained in:
Karan 2020-05-01 14:00:29 -07:00 коммит произвёл GitHub
Родитель 32c4f0d9a2
Коммит d25ad5c731
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 99 добавлений и 11 удалений

1
.gitattributes поставляемый
Просмотреть файл

@ -1 +1,2 @@
* text=auto eol=lf
*.mp3 binary

Просмотреть файл

@ -24,6 +24,7 @@
"**/*.scss.d.ts",
"**/*.snap",
"**/*.svg",
"**/*.mp3",
"Dockerfile",
"yarn.lock"
],

Просмотреть файл

@ -16,6 +16,9 @@ strategy:
pool:
vmImage: $(vmImage)
variables:
RUN_RELEASE_TESTS: true
steps:
- template: ../install-node-prerequisites.yaml

Просмотреть файл

@ -18,16 +18,7 @@ export async function createApplication(options?: AppOptions): Promise<AppContro
(global as any).rootDir
}/drop/electron/unified-dev/product/bundle/main.bundle.js`;
const app = new Application({
path: Electron as any,
args: [targetApp],
connectionRetryCount: DEFAULT_APP_CONNECT_RETRIES,
connectionRetryTimeout: DEFAULT_APP_CONNECT_TIMEOUT_MS,
});
await app.start();
const appController = new AppController(app);
const appController = await createAppController(targetApp);
if (options?.suppressFirstTimeDialog === true) {
await appController.setTelemetryState(false);
@ -35,3 +26,14 @@ export async function createApplication(options?: AppOptions): Promise<AppContro
return appController;
}
export async function createAppController(targetApp: string): Promise<AppController> {
const app = new Application({
path: Electron as any,
args: [targetApp],
connectionRetryCount: DEFAULT_APP_CONNECT_RETRIES,
connectionRetryTimeout: DEFAULT_APP_CONNECT_TIMEOUT_MS,
});
await app.start();
return new AppController(app);
}

Просмотреть файл

@ -8,7 +8,7 @@ import { DEFAULT_WAIT_FOR_ELEMENT_TO_BE_VISIBLE_TIMEOUT_MS } from 'tests/electro
import { AutomatedChecksViewController } from './automated-checks-view-controller';
export class AppController {
private client: SpectronAsyncClient;
public client: SpectronAsyncClient;
constructor(public app: Application) {
this.client = app.client as any;

Просмотреть файл

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { SpectronAsyncClient } from 'tests/electron/common/view-controllers/spectron-async-client';
import { ViewController } from './view-controller';
export class CodecTestViewController extends ViewController {
constructor(client: SpectronAsyncClient) {
super(client);
}
public async waitForAudioVisible(): Promise<void> {
await this.waitForSelector('#audio');
}
}

Просмотреть файл

@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { createAppController } from 'tests/electron/common/create-application';
import { AppController } from 'tests/electron/common/view-controllers/app-controller';
import { CodecTestViewController } from 'tests/electron/common/view-controllers/codecs-test-view-controller';
/*
We bundle a mirrored version of electron with no
audio/video codecs to avoid shipping proprietary codecs
we don't need in the release build. This e2e test checks
to ensure we have the right codecs. If this test fails,
it's likely node_modules/electron/dist was not replaced
with the appropriate electron mirror.
*/
const releaseTests = process.env.RUN_RELEASE_TESTS === 'true';
(releaseTests ? describe : describe.skip)(
'electron bundled without proprietary audio-video codecs',
() => {
let appController: AppController;
let viewContoller: CodecTestViewController;
beforeEach(async () => {
appController = await createAppController(
path.resolve(__dirname, '..', '..', 'miscellaneous', 'codecs', 'codecs-test.js'),
);
viewContoller = new CodecTestViewController(appController.client);
await viewContoller.waitForAudioVisible();
});
afterEach(async () => await appController.stop());
// https://html.spec.whatwg.org/multipage/media.html#error-codes:dom-mediaerror-media_err_src_not_supported
it('has error when loading mp3 <audio> in renderer process', async () => {
expect(await viewContoller.client.getAttribute('#audio', 'data-err')).toEqual('4');
});
},
);

Просмотреть файл

@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { app, BrowserWindow } = require('electron');
app.whenReady().then(() => {
const win = new BrowserWindow();
win.loadFile('codecs.html');
});

Двоичные данные
src/tests/miscellaneous/codecs/codecs-test.mp3 Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,20 @@
<!--
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>electron audio test</title>
</head>
<body>
mp3 playback should fail:
<audio
controls
src="codecs-test.mp3"
id="audio"
onerror="this.setAttribute('data-err', event.target.error.code)"
></audio>
</body>
</html>