Merge "Simple test for enter/exiting fullscreen mode"

This commit is contained in:
jenkins-bot 2014-01-28 10:21:14 +00:00 committed by Gerrit Code Review
commit d246d7709a
3 changed files with 47 additions and 3 deletions

View file

@ -176,7 +176,10 @@
// Register various event hooks. TODO: Make this a function that's only called once.
lightboxHooks.register( 'closeInterface', function () {
this.$nextButton.add( this.$prevButton ).css( 'top', '-999px' );
if ( this.$nextButton ) {
this.$nextButton.add( this.$prevButton ).css( 'top', '-999px' );
}
$( document.body ).removeClass( 'mw-mlb-lightbox-open' );
if ( comingFromPopstate === false ) {
history.pushState( {}, '', '#' );
@ -194,8 +197,6 @@
} );
lightboxHooks.register( 'fullscreen', function ( fullscreen ) {
viewer.ui.isFullscreen = fullscreen;
if ( this.$imageMetadata ) {
if ( fullscreen ) {
this.$imageMetadata.hide();

View file

@ -69,6 +69,8 @@
} );
$( document ).on( 'jq-fullscreen-change', function ( e ) {
lbinterface.isFullscreen = e.fullscreen;
lightboxHooks.callAll( 'fullscreen', this, e.fullscreen );
if ( !lbinterface.fullscreenButtonJustPressed && !e.fullscreen ) {

View file

@ -56,4 +56,45 @@
lightbox.load(img);
} );
QUnit.test( 'Fullscreen mode', 4, function ( assert ) {
var lightbox = new window.LightboxInterface(),
oldFnEnterFullscreen = $.fn.enterFullscreen,
oldFnExitFullscreen = $.fn.exitFullscreen;
// Since we don't want these tests to really open fullscreen
// which is subject to user security confirmation,
// we create a proxy and make it pretend that regular jquery.fullscreen behavior happened
$.fn.enterFullscreen = function() {
this.first().addClass( 'jq-fullscreened' ).data( 'isFullscreened', true );
$( document ).trigger( $.Event( 'jq-fullscreen-change', { element: this, fullscreen: true } ) );
};
$.fn.exitFullscreen = function() {
this.first().removeClass( 'jq-fullscreened' ).data( 'isFullscreened', false );
$( document ).trigger( $.Event( 'jq-fullscreen-change', { element: this, fullscreen: false } ) );
};
// Attach lightbox to testing fixture to avoid interference with other tests.
lightbox.attach( '#qunit-fixture' );
// Entering fullscreen
lightbox.$fullscreenButton.click();
assert.strictEqual( lightbox.$main.hasClass( 'jq-fullscreened' ) , true,
'Fullscreened area has the fullscreen class');
assert.strictEqual( lightbox.isFullscreen , true, 'Lightbox knows it\'s in fullscreen mode');
// Exiting fullscreen
lightbox.$fullscreenButton.click();
assert.strictEqual( lightbox.$main.hasClass( 'jq-fullscreened' ) , false,
'Fullscreened area doesn\'t have the fullscreen class anymore');
assert.strictEqual( lightbox.isFullscreen , false, 'Lightbox knows it\'s not in fullscreen mode');
$.fn.enterFullscreen = oldFnEnterFullscreen;
$.fn.exitFullscreen = oldFnExitFullscreen;
} );
}( mediaWiki, jQuery ) );