' ).attr( 'src', ( imageSrc || 'thumb.jpg' ) ).appendTo( link );
return div;
}
QUnit.test( 'Check viewer invoked when clicking on an legit image links', 4, function ( assert ) {
// TODO: Is
valid ???
var div, link, link2, link3, viewer;
// Create viewer, no images in page.
viewer = new mw.MultimediaViewer();
assert.strictEqual( viewer.lightbox, null, 'There are not legit links, a lightbox should not be created.' );
// Create gallery with legit link image
div = createGallery();
link = div.find( 'a.image' );
// Legit isolated thumbnail
link2 = $( '
',
whitelisted = 'Blahblah',
okjq = $.parseHTML( okhtml ),
nwljq = $.parseHTML( needswhitelisting ),
$sandbox = $( '
' );
viewer.whitelistHtml( $sandbox.empty().append( okjq ) );
assert.strictEqual( $sandbox.html(), okhtml, 'Whitelisted elements are let through.' );
viewer.whitelistHtml( $sandbox.empty().append( nwljq ) );
assert.strictEqual( $sandbox.html(), whitelisted, 'Not-whitelisted elements are removed.' );
// Clean up the viewer, to avoid seeing it catch events when running other tests
mw.mmvTestHelpers.resetViewer();
} );
QUnit.asyncTest( 'loadAndSetImage(): Basic load', 3, function ( assert ) {
var widths = new mw.mmv.model.ThumbnailWidth( 8, 8, 640 ), // Current area < imageData.width
viewer = new mw.MultimediaViewer(),
ui = new mw.LightboxInterface( viewer ),
size = 120,
width = 10,
height = 11,
imageUrl = 'http://en.wikipedia.org/w/skins/vector/images/search-ltr.png',
imageData = new mw.mmv.model.Image(
mw.Title.newFromText( 'File:Foobar.pdf.jpg' ),
size, width, height, 'image/jpeg',
imageUrl,
'http://example.com',
'example', 'tester', '2013-11-10', '2013-11-09', 'Blah blah blah',
'A person', 'Another person', 'CC-BY-SA-3.0', 0, 0
);
ui.replaceImageWith = function ( image ) {
assert.strictEqual( image.src, imageUrl, 'Image to replace has correct "src" attribute.' );
assert.strictEqual( image.width, widths.css, 'Image to replace has correct "width" attribute.' );
};
viewer.updateControls = function () {
assert.ok( true, 'Controls updated.' );
QUnit.start();
};
// Test case when image loaded is bigger than current area
viewer.loadAndSetImage( ui, imageData, widths );
mw.mmvTestHelpers.resetViewer();
} );
QUnit.test( 'Hash handling', 5, function ( assert ) {
var oldLoadImage = mw.mediaViewer.loadImage,
oldLightbox = mw.mediaViewer.lightbox,
imageSrc = 'Foo bar.jpg',
image = { filePageTitle: new mw.Title( 'File:' + imageSrc ) };
document.location.hash = '';
mw.mediaViewer.lightbox = { iface: { unattach: function() {
assert.ok( true, 'Interface unattached' );
} } };
// Verify that passing an invalid mmv hash triggers unattach()
document.location.hash = 'Foo';
mw.mediaViewer.lightbox = { images: [ image ] };
$( '#qunit-fixture' ).append( '
' );
mw.mediaViewer.loadImage = function( img, src ) {
assert.strictEqual( img, image, 'The image object matches' );
assert.ok( src.match( encodeURIComponent( imageSrc ) ), 'The image url matches' );
};
// Open a valid mmv hash link and check that the right image is requested.
// imageSrc contains a space without any encoding on purpose
document.location.hash = 'mediaviewer/File:' + imageSrc + '/0';
// Reset the hash, because for some browsers switching from the non-URI-encoded to
// the non-URI-encoded version of the same text with a space will not trigger a hash change
document.location.hash = '';
// Try again with an URI-encoded imageSrc containing a space
document.location.hash = 'mediaviewer/File:' + encodeURIComponent( imageSrc ) + '/0';
mw.mediaViewer.lightbox = oldLightbox;
mw.mediaViewer.loadImage = oldLoadImage;
document.location.hash = '';
} );
}( mediaWiki, jQuery ) );