diff --git a/src/main/ipc.js b/src/main/ipc.js index a8fdf4f1..436082ed 100644 --- a/src/main/ipc.js +++ b/src/main/ipc.js @@ -145,26 +145,6 @@ function init () { ipc.on('quitExternalPlayer', () => externalPlayer.kill()) - /** - * Test - */ - - ipc.on('testOffline', function (e, isOffline) { - log('Testing, network ' + (isOffline ? 'OFFLINE' : 'ONLINE')) - windows.webtorrent.send('wt-test-offline') - - // TODO: this easy way to disable networking doesn't work due to a Chrome bug. - // WebRTC is unaffected by DevTools throttling: - // https://bugs.chromium.org/p/chromium/issues/detail?id=490143 - // Also doesn't work due to an Electron bug. Node networking APIs are unaffected, only - // Chrome networking (external resources, XHRs, etc) are affected. - // const wins = [windows.main.win, windows.webtorrent.win] - // wins.forEach(function (win) { - // if (isOffline) win.webContents.session.enableNetworkEmulation({ offline: true }) - // else win.webContents.session.disableNetworkEmulation() - // !}) - }) - /** * Message passing */ diff --git a/src/renderer/webtorrent.js b/src/renderer/webtorrent.js index 6af26c15..bbfd7ad6 100644 --- a/src/renderer/webtorrent.js +++ b/src/renderer/webtorrent.js @@ -95,20 +95,6 @@ function init () { ipc.on('wt-select-files', (e, infoHash, selections) => selectFiles(infoHash, selections)) - // TODO: remove this once the following bugs are fixed: - // https://bugs.chromium.org/p/chromium/issues/detail?id=490143 - // https://github.com/electron/electron/issues/7212 - ipc.on('wt-test-offline', () => { - console.log('Test, going OFFLINE') - client = window.client = new WebTorrent({ - peerId: PEER_ID, - tracker: false, - dht: false, - webSeeds: false - }) - listenToClientEvents() - }) - ipc.send('ipcReadyWebTorrent') window.addEventListener('error', (e) => @@ -418,3 +404,17 @@ function getTorrent (torrentKey) { function onError (err) { console.log(err) } + +// TODO: remove this once the following bugs are fixed: +// https://bugs.chromium.org/p/chromium/issues/detail?id=490143 +// https://github.com/electron/electron/issues/7212 +window.testOfflineMode = function () { + console.log('Test, going OFFLINE') + client = window.client = new WebTorrent({ + peerId: PEER_ID, + tracker: false, + dht: false, + webSeeds: false + }) + listenToClientEvents() +} diff --git a/test/screenshots/darwin/torrent-list-cosmos-delete-data.png b/test/screenshots/darwin/torrent-list-cosmos-delete-data.png index 7f74ef84..8e2455be 100644 Binary files a/test/screenshots/darwin/torrent-list-cosmos-delete-data.png and b/test/screenshots/darwin/torrent-list-cosmos-delete-data.png differ diff --git a/test/screenshots/darwin/torrent-list-cosmos-expand-start.png b/test/screenshots/darwin/torrent-list-cosmos-expand-start.png index 6f1f37aa..87f8884d 100644 Binary files a/test/screenshots/darwin/torrent-list-cosmos-expand-start.png and b/test/screenshots/darwin/torrent-list-cosmos-expand-start.png differ diff --git a/test/screenshots/darwin/torrent-list-start-download.png b/test/screenshots/darwin/torrent-list-start-download.png index b402a584..15b36049 100644 Binary files a/test/screenshots/darwin/torrent-list-start-download.png and b/test/screenshots/darwin/torrent-list-start-download.png differ diff --git a/test/setup.js b/test/setup.js index 9e6edf4c..c9d31758 100644 --- a/test/setup.js +++ b/test/setup.js @@ -35,17 +35,13 @@ function waitForLoad (app, t, opts) { return app.start().then(function () { return app.client.waitUntilWindowLoaded() }).then(function () { - // Offline mode? Disable internet in the webtorrent window - // TODO. For now, just run integration tests with internet turned off. - // Spectron is poorly documented, and contrary to the docs, webContents.session is missing - // That is the correct API (in theory) to put the app in offline mode + // Offline mode + if (opts.offline) app.webContents.executeJavaScript('testOfflineMode()') }).then(function () { // Switch to the main window. Index 0 is apparently the hidden webtorrent window... 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 8516e1f0..7052734c 100644 --- a/test/test-torrent-list.js +++ b/test/test-torrent-list.js @@ -36,8 +36,7 @@ test('torrent-list: start, stop, and delete torrents', function (t) { .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-hover')) // 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(() => app.client.waitUntilTextExists('.torrent-list', '0%')) .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-start-download')) // Click download on the first torrent again, stop downloading .then(() => app.client.click('.icon.download'))