Let PhantomJS load local images

This change fix a memory leak due to a Webkit bug:
https://github.com/ariya/phantomjs/issues/12903

Also:

- Whitelist only localhost and 127.0.0.1 in Capybara + JS specs
- Blacklist all requests to media such as images, videos, PDFs, CSVs etc.
- Log all the requests made.

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2017-06-08 11:55:07 +02:00
parent 194c40df20
commit 448fc23e47
No known key found for this signature in database
GPG Key ID: 46DF07E5CD9E96AB
4 changed files with 12 additions and 13 deletions

View File

@ -11,8 +11,10 @@ Capybara.register_driver :poltergeist do |app|
js_errors: true, js_errors: true,
timeout: timeout, timeout: timeout,
window_size: [1366, 768], window_size: [1366, 768],
url_whitelist: %w[localhost 127.0.0.1],
url_blacklist: %w[.mp4 .png .gif .avi .bmp .jpg .jpeg],
phantomjs_options: [ phantomjs_options: [
'--load-images=no' '--load-images=yes'
] ]
) )
end end

View File

@ -34,7 +34,7 @@ describe 'Help Pages', feature: true do
end end
end end
context 'in a production environment with version check enabled', js: true do context 'in a production environment with version check enabled', :js do
before do before do
allow(Rails.env).to receive(:production?) { true } allow(Rails.env).to receive(:production?) { true }
allow(current_application_settings).to receive(:version_check_enabled) { true } allow(current_application_settings).to receive(:version_check_enabled) { true }
@ -44,18 +44,12 @@ describe 'Help Pages', feature: true do
visit help_path visit help_path
end end
it 'should display a version check image' do it 'has a version check image' do
expect(find('.js-version-status-badge')).to be_visible expect(find('.js-version-status-badge', visible: false)['src']).to end_with('/version-check-url')
end end
it 'should have a src url' do it 'hides the version check image if the image request fails' do
expect(find('.js-version-status-badge')['src']).to match(/\/version-check-url/) # We use '--load-images=yes' with poltergeist so the image fails to load
end
it 'should hide the version check image if the image request fails' do
# We use '--load-images=no' with poltergeist so we must trigger manually
execute_script("$('.js-version-status-badge').trigger('error');")
expect(find('.js-version-status-badge', visible: false)).not_to be_visible expect(find('.js-version-status-badge', visible: false)).not_to be_visible
end end
end end

View File

@ -39,6 +39,7 @@ feature 'Artifact file', :js, feature: true do
context 'JPG file' do context 'JPG file' do
before do before do
page.driver.browser.url_blacklist = []
visit_file('rails_sample.jpg') visit_file('rails_sample.jpg')
wait_for_requests wait_for_requests

View File

@ -14,8 +14,10 @@ Capybara.register_driver :poltergeist do |app|
js_errors: true, js_errors: true,
timeout: timeout, timeout: timeout,
window_size: [1366, 768], window_size: [1366, 768],
url_whitelist: %w[localhost 127.0.0.1],
url_blacklist: %w[.mp4 .png .gif .avi .bmp .jpg .jpeg],
phantomjs_options: [ phantomjs_options: [
'--load-images=no' '--load-images=yes'
] ]
) )
end end