diff --git a/src/main/ipc.js b/src/main/ipc.js index 11484e3e..3b989e7a 100644 --- a/src/main/ipc.js +++ b/src/main/ipc.js @@ -98,14 +98,16 @@ function init () { /** * File handlers */ + ipc.on('setDefaultFileHandler', (e, flag) => { if (flag) handlers.install() else handlers.uninstall() }) /** - * Startup + * Auto start on login */ + ipc.on('setStartup', (e, flag) => { if (flag) startup.install() else startup.uninstall() @@ -143,7 +145,25 @@ function init () { ipc.on('quitExternalPlayer', () => externalPlayer.kill()) - // Capture all events + /** + * Test + */ + + ipc.on('testOffline', function (e, isOffline) { + log('Testing, network ' + (isOffline ? 'OFFLINE' : 'ONLINE')) + // Get the two Electron BrowserWindows (main UI window, hidden webtorrent window) + const wins = [windows.main.win, windows.webtorrent.win] + wins.forEach(function (win) { + if (isOffline) win.webContents.session.enableNetworkEmulation({ latency: 10e3 }) + else win.webContents.session.disableNetworkEmulation() + log('WTF') + }) + }) + + /** + * Message passing + */ + const oldEmit = ipc.emit ipc.emit = function (name, e, ...args) { // Relay messages between the main window and the WebTorrent hidden window diff --git a/test/index.js b/test/index.js index 34362b5d..b3fed4b3 100644 --- a/test/index.js +++ b/test/index.js @@ -15,10 +15,9 @@ test('app runs', function (t) { }) require('./test-torrent-list') -require('./test-add-torrent') - -// TODO: +// require('./test-add-torrent') // require('./test-video') + // require('./test-audio') // require('./test-cast') // require('./test-prefs') diff --git a/test/resources/monitor-test.mp4 b/test/resources/monitor-test.mp4 new file mode 100644 index 00000000..b3709c5b Binary files /dev/null and b/test/resources/monitor-test.mp4 differ diff --git a/test/screenshots/darwin/play-torrent-bbb.png b/test/screenshots/darwin/play-torrent-bbb.png new file mode 100644 index 00000000..07908278 Binary files /dev/null and b/test/screenshots/darwin/play-torrent-bbb.png differ diff --git a/test/setup.js b/test/setup.js index 5f36d6a1..9e6edf4c 100644 --- a/test/setup.js +++ b/test/setup.js @@ -44,6 +44,8 @@ function waitForLoad (app, t, opts) { return app.client.windowByIndex(1) }).then(function () { return app.client.waitUntilWindowLoaded() + }).then(function () { + if (!opts.online) app.electron.ipcRenderer.send('testOffline', true) }).then(function () { return app.webContents.getTitle() }).then(function (title) { diff --git a/test/test-torrent-list.js b/test/test-torrent-list.js index e68e5e98..8516e1f0 100644 --- a/test/test-torrent-list.js +++ b/test/test-torrent-list.js @@ -3,7 +3,7 @@ const fs = require('fs-extra') const setup = require('./setup') const config = require('./config') -test('torrent-list: show download path missing', function (t) { +test.skip('torrent-list: show download path missing', function (t) { setup.resetTestDataDir() fs.removeSync(config.TEST_DIR_DOWNLOAD) @@ -37,6 +37,7 @@ test('torrent-list: start, stop, and delete torrents', function (t) { // Click download on the first torrent, start downloading .then(() => app.client.click('.icon.download')) .then(() => app.client.waitUntilTextExists('.torrent-list', 'peer')) + .then(() => setup.wait(100e3)) .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-start-download')) // Click download on the first torrent again, stop downloading .then(() => app.client.click('.icon.download')) diff --git a/test/test-video.js b/test/test-video.js new file mode 100644 index 00000000..1954d5e8 --- /dev/null +++ b/test/test-video.js @@ -0,0 +1,34 @@ +const test = require('tape') +const setup = require('./setup') + +test('basic-streaming', function (t) { + setup.resetTestDataDir() + + t.timeoutAfter(30e3) + const app = setup.createApp() + setup.waitForLoad(app, t, {online: true}) + .then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny')) + // Play Big Buck Bunny. Wait for it to start streaming. + .then(() => app.client.moveToObject('.torrent.bbb')) + .then(() => setup.wait()) + .then(() => app.client.click('.icon.play')) + .then(() => setup.wait(10e3)) + // Pause. Skip to two seconds in. Wait another two seconds for it to load. + .then(() => app.webContents.executeJavaScript('dispatch("playPause")')) + .then(() => app.webContents.executeJavaScript('dispatch("skipTo", 2)')) + .then(() => setup.wait(5e3)) + // Take a screenshot to verify video playback + .then(() => setup.screenshotCreateOrCompare(app, t, 'play-torrent-bbb')) + // Hit escape + .then(() => app.webContents.executeJavaScript('dispatch("escapeBack")')) + .then(() => setup.wait()) + // Delete Big Buck Bunny + .then(() => app.client.click('.icon.delete')) + .then(() => setup.wait()) + .then(() => app.client.click('.control.ok')) + .then(() => setup.wait()) + // Take another screenshot to verify that the window resized correctly + .then(() => setup.screenshotCreateOrCompare(app, t, 'play-torrent-return')) + .then(() => setup.endTest(app, t), + (err) => setup.endTest(app, t, err || 'error')) +})