Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
karanbirsingh marked this conversation as resolved.
Show resolved Hide resolved
}
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;
karanbirsingh marked this conversation as resolved.
Show resolved Hide resolved

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 () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the design of this test case; this is much cleaner than verifying file hashes like I how I'd imagined this test working initially.

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>