diff --git a/app/dataFile.js b/app/dataFile.js index 124f3a0efc8..068bdb3b471 100644 --- a/app/dataFile.js +++ b/app/dataFile.js @@ -18,10 +18,12 @@ const storagePath = (url) => const downloadPath = (url) => `${storagePath(url)}.temp` function downloadSingleFile (resourceName, url, version, force, resolve, reject) { + // console.log('downloading file for: ', resourceName, url) let headers = {} const AppStore = require('../js/stores/appStore') const etag = AppStore.getState().getIn([resourceName, 'etag']) if (!force && etag) { + // console.log('setting etag: ', etag) headers = { 'If-None-Match': etag } @@ -34,6 +36,7 @@ function downloadSingleFile (resourceName, url, version, force, resolve, reject) reject('could not rename downloaded file') } else { appActions.setResourceETag(resourceName, newEtag) + // console.log('set resource last check: ', resourceName, version, new Date().getTime()) appActions.setResourceLastCheck(resourceName, version, new Date().getTime()) resolve() } @@ -107,8 +110,13 @@ module.exports.init = (resourceName, startExtension, onInitDone, forceDownload) }) }) + // console.log('should redownload first? ', resourceName, version, module.exports.shouldRedownloadFirst(resourceName, version)) + // If the last check version changes we always want to force a download, otherwise we always don't want to force + const AppStore = require('../js/stores/appStore') + const lastCheckVersion = AppStore.getState().getIn([resourceName, 'lastCheckVersion']) + // console.log('lastCheckVersion, version: ', lastCheckVersion, version, lastCheckVersion !== version) if (forceDownload || module.exports.shouldRedownloadFirst(resourceName, version)) { - module.exports.downloadDataFile(resourceName, url, version, false) + module.exports.downloadDataFile(resourceName, url, version, lastCheckVersion !== version) .then(loadProcess.bind(null, resourceName, version)) .catch(loadProcess.bind(null, resourceName, version)) } else { diff --git a/js/lib/request.js b/js/lib/request.js index 1ac5c51476b..f2f4f1431f2 100644 --- a/js/lib/request.js +++ b/js/lib/request.js @@ -28,9 +28,15 @@ module.exports.requestDataFile = (url, headers, path, reject, resolve) => { if (!defaultSession) { reject('Request failed, no session available') } else { + // console.log('webRequest.fetch: ', url, headers, path) defaultSession.webRequest.fetch(url, { headers, path }, (err, response) => { + // console.log('response: ', response) if (!err && response.statusCode === 200) { - resolve(headers['etag']) + let etag = response.headers['etag'] + if (etag && etag.constructor === Array) { + etag = etag[0] + } + resolve(etag) } else { reject(`Got HTTP status code ${response.statusCode}`) } diff --git a/test/components/braveryPanelTest.js b/test/components/braveryPanelTest.js index 7a836ebcaa1..cbc984a43e3 100644 --- a/test/components/braveryPanelTest.js +++ b/test/components/braveryPanelTest.js @@ -14,13 +14,20 @@ describe('Bravery Panel', function () { } function * openBraveMenu (client) { - yield client + return client .windowByUrl(Brave.browserWindowUrl) .waitForVisible(braveMenu) .click(braveMenu) .waitForVisible(braveryPanel) } + function * waitForDataFile (client, dataFile) { + return client.waitUntil(function () { + return this.getAppState().then((val) => + val.value[dataFile].etag && val.value[dataFile].etag.length > 0) + }) + } + describe('General', function () { Brave.beforeAll(this) before(function * () { @@ -44,6 +51,7 @@ describe('Bravery Panel', function () { yield setup(this.app.client) }) it('detects blocked elements', function * () { + yield waitForDataFile(this.app.client, 'trackingProtection') const url = Brave.server.url('tracking.html') yield this.app.client .tabByIndex(0) @@ -56,6 +64,7 @@ describe('Bravery Panel', function () { }) }) it('detects adblock elements', function * () { + yield waitForDataFile(this.app.client, 'adblock') const url = Brave.server.url('adblock.html') yield this.app.client .tabByIndex(0) @@ -68,6 +77,7 @@ describe('Bravery Panel', function () { }) }) it('detects https upgrades', function * () { + yield waitForDataFile(this.app.client, 'httpsEverywhere') const url = Brave.server.url('httpsEverywhere.html') yield this.app.client .tabByIndex(0)