Skip to content

Commit

Permalink
test: add e2e test to ensure we ship with non audio/video codecs (#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
karanbirsingh authored May 1, 2020
1 parent 32c4f0d commit d25ad5c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
*.mp3 binary
1 change: 1 addition & 0 deletions copyright-header.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"**/*.scss.d.ts",
"**/*.snap",
"**/*.svg",
"**/*.mp3",
"Dockerfile",
"yarn.lock"
],
Expand Down
3 changes: 3 additions & 0 deletions pipeline/unified/build-unsigned-release-packages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ strategy:
pool:
vmImage: $(vmImage)

variables:
RUN_RELEASE_TESTS: true

steps:
- template: ../install-node-prerequisites.yaml

Expand Down
20 changes: 11 additions & 9 deletions src/tests/electron/common/create-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ export async function createApplication(options?: AppOptions): Promise<AppContro
(global as any).rootDir
}/drop/electron/unified-dev/product/bundle/main.bundle.js`;

const appController = await createAppController(targetApp);

if (options?.suppressFirstTimeDialog === true) {
await appController.setTelemetryState(false);
}

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();

const appController = new AppController(app);

if (options?.suppressFirstTimeDialog === true) {
await appController.setTelemetryState(false);
}

return appController;
return new AppController(app);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
}
39 changes: 39 additions & 0 deletions src/tests/electron/tests/framework-no-codecs.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
},
);
8 changes: 8 additions & 0 deletions src/tests/miscellaneous/codecs/codecs-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
Binary file added src/tests/miscellaneous/codecs/codecs-test.mp3
Binary file not shown.
20 changes: 20 additions & 0 deletions src/tests/miscellaneous/codecs/codecs.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit d25ad5c

Please sign in to comment.