2015-12-09 16:21:54 +00:00
|
|
|
require 'json'
|
2014-09-17 21:48:44 +00:00
|
|
|
|
2014-04-01 08:46:48 +00:00
|
|
|
class CommonsPage
|
|
|
|
include PageObject
|
|
|
|
|
2015-12-09 16:21:54 +00:00
|
|
|
page_url 'File:Sunrise_over_fishing_boats_in_Kerala.jpg'
|
2014-04-01 08:46:48 +00:00
|
|
|
|
|
|
|
img(:commons_image, src: /Kerala\.jpg$/)
|
2015-12-09 16:21:54 +00:00
|
|
|
div(:mmv_image_loaded_cucumber, class: 'mw-mmv-image-loaded-cucumber')
|
2014-09-17 21:48:44 +00:00
|
|
|
|
|
|
|
def wait_for_image_load(selector)
|
|
|
|
browser.execute_script <<-end_script
|
|
|
|
function wait_for_image() {
|
|
|
|
var $img = $( #{selector.to_json} );
|
|
|
|
if ( $img.length
|
|
|
|
&& $img.attr( 'src' ).match(/Kerala/)
|
|
|
|
&& !$img.attr( 'src' ).match(/\\/220px-/) // Blurry placeholder
|
|
|
|
&& $img.prop( 'complete' ) ) {
|
|
|
|
$( 'body' ).append( '<div class=\"mw-mmv-image-loaded-cucumber\"/>' );
|
|
|
|
} else {
|
|
|
|
setTimeout( wait_for_image, 10 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_for_image();
|
|
|
|
end_script
|
|
|
|
|
|
|
|
wait_until { mmv_image_loaded_cucumber_element.exists? }
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_performance(stats)
|
2015-12-09 15:54:58 +00:00
|
|
|
stats = stats.reject { |_name, value| value.nil? || value.to_s.empty? }
|
2014-09-17 21:48:44 +00:00
|
|
|
stats[:duration] = stats[:duration].floor
|
|
|
|
|
|
|
|
browser.execute_script <<-end_script
|
|
|
|
mediaWiki.eventLog.declareSchema( 'MultimediaViewerVersusPageFilePerformance',
|
|
|
|
{ schema:
|
|
|
|
{ title: 'MultimediaViewerVersusPageFilePerformance',
|
|
|
|
properties: {
|
|
|
|
type: { type: 'string', required: true, enum: [ 'mmv', 'file-page' ] },
|
|
|
|
duration: { type: 'integer', required: true },
|
|
|
|
cache: { type: 'string', required: false, enum: [ 'cold', 'warm' ] },
|
|
|
|
windowSize: { type: 'string', required: false, enum: [ 'average', 'large'] }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
revision: 7907636
|
|
|
|
});
|
|
|
|
|
|
|
|
mw.eventLog.logEvent( 'MultimediaViewerVersusPageFilePerformance', #{stats.to_json} );
|
|
|
|
end_script
|
|
|
|
end
|
|
|
|
end
|