2013-11-27 21:57:45 +00:00
( function ( mw , $ ) {
2014-01-23 21:44:26 +00:00
QUnit . module ( 'mmv' , QUnit . newMwEnvironment ( ) ) ;
2013-11-27 21:57:45 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'eachPrealoadableLightboxIndex()' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-02-13 09:52:40 +00:00
expectedIndices ,
i ;
viewer . preloadDistance = 3 ;
2014-02-17 15:09:23 +00:00
viewer . thumbs = [ ] ;
// 0..10
for ( i = 0 ; i < 11 ; i ++ ) {
2015-01-23 12:48:27 +00:00
viewer . thumbs . push ( { image : false } ) ;
2014-02-17 15:09:23 +00:00
}
2014-02-13 09:52:40 +00:00
2014-03-05 02:24:18 +00:00
viewer . currentIndex = 2 ;
2014-02-13 09:52:40 +00:00
i = 0 ;
2016-07-18 13:49:27 +00:00
expectedIndices = [ 2 , 3 , 1 , 4 , 0 , 5 ] ;
2015-01-23 12:48:27 +00:00
viewer . eachPrealoadableLightboxIndex ( function ( index ) {
2016-07-18 13:49:27 +00:00
assert . strictEqual ( index , expectedIndices [ i ++ ] , 'preload on left edge' ) ;
2014-02-13 09:52:40 +00:00
} ) ;
2014-03-05 02:24:18 +00:00
viewer . currentIndex = 9 ;
2014-02-13 09:52:40 +00:00
i = 0 ;
2016-07-18 13:49:27 +00:00
expectedIndices = [ 9 , 10 , 8 , 7 , 6 ] ;
2015-01-23 12:48:27 +00:00
viewer . eachPrealoadableLightboxIndex ( function ( index ) {
2016-07-18 13:49:27 +00:00
assert . strictEqual ( index , expectedIndices [ i ++ ] , 'preload on right edge' ) ;
2014-02-13 09:52:40 +00:00
} ) ;
} ) ;
2014-02-21 11:16:30 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Hash handling' , function ( assert ) {
2014-02-21 11:16:30 +00:00
var oldUnattach ,
2016-04-03 09:18:26 +00:00
viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-03-05 02:24:18 +00:00
ui = new mw . mmv . LightboxInterface ( ) ,
2014-02-21 11:16:30 +00:00
imageSrc = 'Foo bar.jpg' ,
image = { filePageTitle : new mw . Title ( 'File:' + imageSrc ) } ;
2015-06-24 18:54:22 +00:00
// animation would keep running, conflict with other tests
this . sandbox . stub ( $ . fn , 'animate' ) . returnsThis ( ) ;
2014-02-24 09:29:14 +00:00
window . location . hash = '' ;
2014-02-21 11:16:30 +00:00
2014-03-04 11:53:53 +00:00
viewer . setupEventHandlers ( ) ;
2014-03-05 02:24:18 +00:00
oldUnattach = ui . unattach ;
2014-02-21 11:16:30 +00:00
2014-03-05 02:24:18 +00:00
ui . unattach = function ( ) {
2014-02-21 11:16:30 +00:00
assert . ok ( true , 'Lightbox was unattached' ) ;
oldUnattach . call ( this ) ;
} ;
2014-03-05 02:24:18 +00:00
viewer . ui = ui ;
2014-02-25 02:28:49 +00:00
viewer . close ( ) ;
2014-02-21 11:16:30 +00:00
2014-02-25 02:28:49 +00:00
assert . ok ( ! viewer . isOpen , 'Viewer is closed' ) ;
2014-02-21 11:16:30 +00:00
2014-02-25 02:28:49 +00:00
viewer . isOpen = true ;
2014-02-21 11:16:30 +00:00
// Verify that passing an invalid mmv hash when the mmv is open triggers unattach()
2014-02-24 09:29:14 +00:00
window . location . hash = 'Foo' ;
2014-02-25 02:28:49 +00:00
viewer . hash ( ) ;
2014-02-21 11:16:30 +00:00
// Verify that mmv doesn't reset a foreign hash
2014-02-24 09:29:14 +00:00
assert . strictEqual ( window . location . hash , '#Foo' , 'Foreign hash remains intact' ) ;
2014-02-25 02:28:49 +00:00
assert . ok ( ! viewer . isOpen , 'Viewer is closed' ) ;
2014-02-21 11:16:30 +00:00
2014-03-05 02:24:18 +00:00
ui . unattach = function ( ) {
2014-02-21 11:16:30 +00:00
assert . ok ( false , 'Lightbox was not unattached' ) ;
oldUnattach . call ( this ) ;
} ;
2015-01-23 12:48:27 +00:00
// Verify that passing an invalid mmv hash when the mmv is closed doesn't trigger unattach()
2014-02-24 09:29:14 +00:00
window . location . hash = 'Bar' ;
2014-02-25 02:28:49 +00:00
viewer . hash ( ) ;
2014-02-21 11:16:30 +00:00
// Verify that mmv doesn't reset a foreign hash
2014-02-24 09:29:14 +00:00
assert . strictEqual ( window . location . hash , '#Bar' , 'Foreign hash remains intact' ) ;
2014-02-21 11:16:30 +00:00
2015-09-25 19:55:00 +00:00
viewer . ui = { images : [ image ] , disconnect : $ . noop } ;
2014-02-21 11:16:30 +00:00
$ ( '#qunit-fixture' ) . append ( '<a class="image"><img src="' + imageSrc + '"></a>' ) ;
2015-01-23 12:48:27 +00:00
viewer . loadImageByTitle = function ( title ) {
2014-04-14 23:22:28 +00:00
assert . strictEqual ( title . getPrefixedText ( ) , 'File:' + imageSrc , 'The title matches' ) ;
2014-02-21 11:16:30 +00:00
} ;
// Open a valid mmv hash link and check that the right image is requested.
// imageSrc contains a space without any encoding on purpose
2015-02-25 14:55:37 +00:00
window . location . hash = '/media/File:' + imageSrc ;
2014-02-25 02:28:49 +00:00
viewer . hash ( ) ;
2014-02-21 11:16:30 +00:00
// 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
2014-02-24 09:29:14 +00:00
window . location . hash = '' ;
2014-02-25 02:28:49 +00:00
viewer . hash ( ) ;
2014-02-21 11:16:30 +00:00
// Try again with an URI-encoded imageSrc containing a space
2015-02-25 14:55:37 +00:00
window . location . hash = '/media/File:' + encodeURIComponent ( imageSrc ) ;
viewer . hash ( ) ;
// Reset the hash
window . location . hash = '' ;
viewer . hash ( ) ;
// Try again with a legacy hash
window . location . hash = 'mediaviewer/File:' + imageSrc ;
2014-02-25 02:28:49 +00:00
viewer . hash ( ) ;
2014-02-21 11:16:30 +00:00
2014-03-04 11:53:53 +00:00
viewer . cleanupEventHandlers ( ) ;
2014-02-21 11:16:30 +00:00
2014-02-24 09:29:14 +00:00
window . location . hash = '' ;
2014-02-21 11:16:30 +00:00
} ) ;
2014-02-25 13:43:22 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Progress' , function ( assert ) {
2014-02-25 13:43:22 +00:00
var imageDeferred = $ . Deferred ( ) ,
2016-04-03 09:18:26 +00:00
viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-12-02 10:05:12 +00:00
fakeImage = {
filePageTitle : new mw . Title ( 'File:Stuff.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
2017-05-11 15:03:52 +00:00
} ,
// custom clock ensures progress handlers execute in correct sequence
clock = this . sandbox . useFakeTimers ( ) ;
2014-02-25 13:43:22 +00:00
viewer . thumbs = [ ] ;
viewer . displayPlaceholderThumbnail = $ . noop ;
viewer . setImage = $ . noop ;
viewer . scroll = $ . noop ;
viewer . preloadFullscreenThumbnail = $ . noop ;
2014-12-02 10:05:12 +00:00
viewer . fetchSizeIndependentLightboxInfo = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
2014-03-05 02:24:18 +00:00
viewer . ui = {
2014-09-12 18:05:13 +00:00
setFileReuseData : $ . noop ,
setupForLoad : $ . noop ,
2014-12-02 10:05:12 +00:00
canvas : { set : $ . noop ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblurWithAnimation : $ . noop ,
unblur : $ . noop ,
2014-12-02 10:05:12 +00:00
getCurrentImageWidths : function ( ) { return { real : 0 } ; } ,
2014-09-26 18:37:53 +00:00
getDimensions : function ( ) { return { } ; }
} ,
2014-09-12 18:05:13 +00:00
panel : {
setImageInfo : $ . noop ,
2014-05-05 21:44:27 +00:00
scroller : {
2014-09-12 18:05:13 +00:00
animateMetadataOnce : $ . noop
2014-05-05 21:44:27 +00:00
} ,
2014-04-21 21:48:40 +00:00
progressBar : {
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
animateTo : this . sandbox . stub ( ) ,
jumpTo : this . sandbox . stub ( )
2014-03-05 02:24:18 +00:00
}
} ,
2014-09-12 18:05:13 +00:00
open : $ . noop } ;
2014-02-25 13:43:22 +00:00
2015-01-23 12:48:27 +00:00
viewer . imageProvider . get = function ( ) { return imageDeferred . promise ( ) ; } ;
viewer . imageInfoProvider . get = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
viewer . thumbnailInfoProvider . get = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
2014-02-25 13:43:22 +00:00
2017-05-11 15:03:52 +00:00
// loadImage will call setupProgressBar, which will attach done, fail &
// progress handlers
2014-12-02 10:05:12 +00:00
viewer . loadImage ( fakeImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( viewer . ui . panel . progressBar . jumpTo . lastCall . calledWith ( 0 ) ,
'Percentage correctly reset by loadImage' ) ;
2017-05-11 15:03:52 +00:00
assert . ok ( viewer . ui . panel . progressBar . animateTo . firstCall . calledWith ( 5 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly animated to 5 by loadImage' ) ;
2014-02-25 13:43:22 +00:00
imageDeferred . notify ( 'response' , 45 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . secondCall . calledWith ( 45 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly funneled to panel UI' ) ;
2014-12-30 05:10:27 +00:00
imageDeferred . resolve ( { } , { } ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . thirdCall . calledWith ( 100 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly funneled to panel UI' ) ;
2017-05-11 15:03:52 +00:00
clock . restore ( ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . close ( ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Progress when switching images' , function ( assert ) {
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
var firstImageDeferred = $ . Deferred ( ) ,
secondImageDeferred = $ . Deferred ( ) ,
2014-12-02 10:05:12 +00:00
firstImage = {
index : 1 ,
filePageTitle : new mw . Title ( 'File:First.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ,
secondImage = {
index : 2 ,
filePageTitle : new mw . Title ( 'File:Second.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ,
2017-05-11 15:03:52 +00:00
viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
// custom clock ensures progress handlers execute in correct sequence
clock = this . sandbox . useFakeTimers ( ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
2015-06-24 18:54:22 +00:00
// animation would keep running, conflict with other tests
this . sandbox . stub ( $ . fn , 'animate' ) . returnsThis ( ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . thumbs = [ ] ;
viewer . displayPlaceholderThumbnail = $ . noop ;
viewer . setImage = $ . noop ;
viewer . scroll = $ . noop ;
viewer . preloadFullscreenThumbnail = $ . noop ;
viewer . preloadImagesMetadata = $ . noop ;
viewer . preloadThumbnails = $ . noop ;
2014-12-02 10:05:12 +00:00
viewer . fetchSizeIndependentLightboxInfo = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . ui = {
2014-09-12 18:05:13 +00:00
setFileReuseData : $ . noop ,
2015-01-23 12:48:27 +00:00
setupForLoad : $ . noop ,
canvas : { set : $ . noop ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblurWithAnimation : $ . noop ,
unblur : $ . noop ,
2015-01-23 12:48:27 +00:00
getCurrentImageWidths : function ( ) { return { real : 0 } ; } ,
2014-09-26 18:37:53 +00:00
getDimensions : function ( ) { return { } ; }
} ,
2015-01-23 12:48:27 +00:00
panel : {
setImageInfo : $ . noop ,
2014-05-05 21:44:27 +00:00
scroller : {
2015-01-23 12:48:27 +00:00
animateMetadataOnce : $ . noop
2014-05-05 21:44:27 +00:00
} ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
progressBar : {
hide : this . sandbox . stub ( ) ,
animateTo : this . sandbox . stub ( ) ,
jumpTo : this . sandbox . stub ( )
}
} ,
2015-01-23 12:48:27 +00:00
open : $ . noop ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
empty : $ . noop } ;
2015-01-23 12:48:27 +00:00
viewer . imageInfoProvider . get = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
viewer . thumbnailInfoProvider . get = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
// load some image
viewer . imageProvider . get = this . sandbox . stub ( ) . returns ( firstImageDeferred ) ;
viewer . loadImage ( firstImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . jumpTo . getCall ( 0 ) . calledWith ( 0 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly reset for new first image' ) ;
2017-05-11 15:03:52 +00:00
assert . ok ( viewer . ui . panel . progressBar . animateTo . getCall ( 0 ) . calledWith ( 5 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly animated to 5 for first new image' ) ;
2017-05-11 15:03:52 +00:00
// progress on active image
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
firstImageDeferred . notify ( 'response' , 20 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . getCall ( 1 ) . calledWith ( 20 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly animated when active image is loading' ) ;
// change to another image
viewer . imageProvider . get = this . sandbox . stub ( ) . returns ( secondImageDeferred ) ;
viewer . loadImage ( secondImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . jumpTo . getCall ( 1 ) . calledWith ( 0 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly reset for second new image' ) ;
2017-05-11 15:03:52 +00:00
assert . ok ( viewer . ui . panel . progressBar . animateTo . getCall ( 2 ) . calledWith ( 5 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly animated to 5 for second new image' ) ;
2017-05-11 15:03:52 +00:00
// progress on active image
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
secondImageDeferred . notify ( 'response' , 30 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . getCall ( 3 ) . calledWith ( 30 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage correctly animated when active image is loading' ) ;
2017-05-11 15:03:52 +00:00
// progress on inactive image
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
firstImageDeferred . notify ( 'response' , 40 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . callCount === 4 ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage not animated when inactive image is loading' ) ;
2017-05-11 15:03:52 +00:00
// progress on active image
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
secondImageDeferred . notify ( 'response' , 50 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . animateTo . getCall ( 4 ) . calledWith ( 50 ) ,
'Percentage correctly ignored inactive image & only animated when active image is loading' ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
// change back to first image
2017-05-11 15:03:52 +00:00
viewer . imageProvider . get = this . sandbox . stub ( ) . returns ( firstImageDeferred ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . loadImage ( firstImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
assert . ok ( viewer . ui . panel . progressBar . jumpTo . getCall ( 2 ) . calledWith ( 40 ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
'Percentage jumps to right value when changing images' ) ;
2014-12-30 05:10:27 +00:00
secondImageDeferred . resolve ( { } , { } ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( ! viewer . ui . panel . progressBar . hide . called ,
'Progress bar not hidden when something finishes in the background' ) ;
2017-05-11 15:03:52 +00:00
// change back to second image, which has finished loading
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . imageProvider . get = this . sandbox . stub ( ) . returns ( secondImageDeferred ) ;
viewer . loadImage ( secondImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( viewer . ui . panel . progressBar . hide . called ,
2017-05-11 15:03:52 +00:00
'Progress bar hidden when switching to finished image' ) ;
clock . restore ( ) ;
2014-02-25 13:43:22 +00:00
viewer . close ( ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'resetBlurredThumbnailStates' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
2015-06-24 18:54:22 +00:00
// animation would keep running, conflict with other tests
this . sandbox . stub ( $ . fn , 'animate' ) . returnsThis ( ) ;
2014-02-25 13:43:22 +00:00
assert . ok ( ! viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( ! viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
viewer . realThumbnailShown = true ;
viewer . blurredThumbnailShown = true ;
viewer . resetBlurredThumbnailStates ( ) ;
assert . ok ( ! viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( ! viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Placeholder first, then real thumbnail' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
viewer . setImage = $ . noop ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblurWithAnimation : $ . noop ,
unblur : $ . noop ,
2015-01-23 12:48:27 +00:00
maybeDisplayPlaceholder : function ( ) { return true ; }
2014-03-05 02:24:18 +00:00
} } ;
2014-04-24 01:03:24 +00:00
viewer . imageInfoProvider . get = this . sandbox . stub ( ) ;
2014-02-25 13:43:22 +00:00
2015-01-23 12:48:27 +00:00
viewer . displayPlaceholderThumbnail ( { originalWidth : 100 , originalHeight : 100 } , undefined , undefined ) ;
2014-04-24 01:03:24 +00:00
assert . ok ( viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
assert . ok ( ! viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } ) ;
2014-04-24 01:03:24 +00:00
assert . ok ( viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Placeholder first, then real thumbnail - missing size' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ;
2014-04-24 01:03:24 +00:00
viewer . currentIndex = 1 ;
viewer . setImage = $ . noop ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblurWithAnimation : $ . noop ,
unblur : $ . noop ,
2015-01-23 12:48:27 +00:00
maybeDisplayPlaceholder : function ( ) { return true ; }
2014-04-24 01:03:24 +00:00
} } ;
2015-01-23 12:48:27 +00:00
viewer . imageInfoProvider . get = this . sandbox . stub ( ) . returns ( $ . Deferred ( ) . resolve ( { width : 100 , height : 100 } ) ) ;
2014-04-24 01:03:24 +00:00
2015-01-23 12:48:27 +00:00
viewer . displayPlaceholderThumbnail ( { index : 1 } , undefined , undefined ) ;
2014-02-25 13:43:22 +00:00
assert . ok ( viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
assert . ok ( ! viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } ) ;
2014-02-25 13:43:22 +00:00
assert . ok ( viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Real thumbnail first, then placeholder' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
viewer . setImage = $ . noop ;
2014-03-05 02:24:18 +00:00
viewer . ui = {
2015-01-23 12:48:27 +00:00
showImage : $ . noop ,
canvas : {
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblurWithAnimation : $ . noop ,
unblur : $ . noop
2016-07-18 13:49:27 +00:00
} } ;
2014-02-25 13:43:22 +00:00
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } ) ;
2014-02-25 13:43:22 +00:00
assert . ok ( viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( ! viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
2015-01-23 12:48:27 +00:00
viewer . displayPlaceholderThumbnail ( { } , undefined , undefined ) ;
2014-02-25 13:43:22 +00:00
assert . ok ( viewer . realThumbnailShown , 'Real thumbnail state is correct' ) ;
assert . ok ( ! viewer . blurredThumbnailShown , 'Placeholder state is correct' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'displayRealThumbnail' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
viewer . setImage = $ . noop ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
unblurWithAnimation : this . sandbox . stub ( ) ,
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
unblur : $ . noop
2014-03-05 02:24:18 +00:00
} } ;
2014-02-25 13:43:22 +00:00
viewer . blurredThumbnailShown = true ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
// Should not result in an unblurWithAnimation animation (image cache from cache)
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } , undefined , undefined , 5 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( ! viewer . ui . canvas . unblurWithAnimation . called , 'There should not be an unblurWithAnimation animation' ) ;
2014-02-25 13:43:22 +00:00
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
// Should result in an unblurWithAnimation (image didn't come from cache)
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } , undefined , undefined , 1000 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( viewer . ui . canvas . unblurWithAnimation . called , 'There should be an unblurWithAnimation animation' ) ;
2014-02-25 13:43:22 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'New image loaded while another one is loading' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-02-27 00:40:39 +00:00
firstImageDeferred = $ . Deferred ( ) ,
secondImageDeferred = $ . Deferred ( ) ,
firstLigthboxInfoDeferred = $ . Deferred ( ) ,
2014-12-02 10:05:12 +00:00
secondLigthboxInfoDeferred = $ . Deferred ( ) ,
firstImage = {
filePageTitle : new mw . Title ( 'File:Foo.jpg' ) ,
index : 0 ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ,
secondImage = {
filePageTitle : new mw . Title ( 'File:Bar.jpg' ) ,
index : 1 ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
2017-05-11 15:03:52 +00:00
} ,
// custom clock ensures progress handlers execute in correct sequence
clock = this . sandbox . useFakeTimers ( ) ;
2014-02-27 00:40:39 +00:00
viewer . preloadFullscreenThumbnail = $ . noop ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . fetchSizeIndependentLightboxInfo = this . sandbox . stub ( ) ;
2014-03-05 02:24:18 +00:00
viewer . ui = {
2014-09-12 18:05:13 +00:00
setFileReuseData : $ . noop ,
2015-01-23 12:48:27 +00:00
setupForLoad : $ . noop ,
canvas : {
set : $ . noop ,
getCurrentImageWidths : function ( ) { return { real : 0 } ; } ,
2014-09-26 18:37:53 +00:00
getDimensions : function ( ) { return { } ; }
} ,
2015-01-23 12:48:27 +00:00
panel : {
setImageInfo : this . sandbox . stub ( ) ,
2014-05-05 21:44:27 +00:00
scroller : {
2015-01-23 12:48:27 +00:00
animateMetadataOnce : $ . noop
2014-05-05 21:44:27 +00:00
} ,
2014-04-21 21:48:40 +00:00
progressBar : {
2015-01-23 12:48:27 +00:00
animateTo : this . sandbox . stub ( ) ,
jumpTo : this . sandbox . stub ( )
2014-03-05 02:24:18 +00:00
} ,
2014-05-28 22:43:35 +00:00
empty : $ . noop
2014-03-05 02:24:18 +00:00
} ,
2015-01-23 12:48:27 +00:00
open : $ . noop ,
2014-03-05 02:24:18 +00:00
empty : $ . noop } ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . displayRealThumbnail = this . sandbox . stub ( ) ;
2014-02-27 00:40:39 +00:00
viewer . eachPrealoadableLightboxIndex = $ . noop ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . animateMetadataDivOnce = this . sandbox . stub ( ) . returns ( $ . Deferred ( ) . reject ( ) ) ;
viewer . imageProvider . get = this . sandbox . stub ( ) ;
2015-01-23 12:48:27 +00:00
viewer . imageInfoProvider . get = function ( ) { return $ . Deferred ( ) . reject ( ) ; } ;
viewer . thumbnailInfoProvider . get = function ( ) { return $ . Deferred ( ) . resolve ( { } ) ; } ;
2014-02-27 00:40:39 +00:00
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . imageProvider . get . returns ( firstImageDeferred . promise ( ) ) ;
viewer . fetchSizeIndependentLightboxInfo . returns ( firstLigthboxInfoDeferred . promise ( ) ) ;
2014-12-02 10:05:12 +00:00
viewer . loadImage ( firstImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( ! viewer . animateMetadataDivOnce . called , 'Metadata of the first image should not be animated' ) ;
assert . ok ( ! viewer . ui . panel . setImageInfo . called , 'Metadata of the first image should not be shown' ) ;
2014-02-27 00:40:39 +00:00
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . imageProvider . get . returns ( secondImageDeferred . promise ( ) ) ;
viewer . fetchSizeIndependentLightboxInfo . returns ( secondLigthboxInfoDeferred . promise ( ) ) ;
2014-12-02 10:05:12 +00:00
viewer . loadImage ( secondImage , new Image ( ) ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-02-27 00:40:39 +00:00
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . ui . panel . progressBar . animateTo . reset ( ) ;
2014-02-27 00:40:39 +00:00
firstImageDeferred . notify ( undefined , 45 ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
assert . ok ( ! viewer . ui . panel . progressBar . animateTo . reset . called , 'Progress of the first image should not be shown' ) ;
2014-12-30 05:10:27 +00:00
firstImageDeferred . resolve ( { } , { } ) ;
2014-12-02 10:05:12 +00:00
firstLigthboxInfoDeferred . resolve ( { } ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2015-01-23 12:48:27 +00:00
assert . ok ( ! viewer . displayRealThumbnail . called , 'The first image being done loading should have no effect' ) ;
2014-02-27 00:40:39 +00:00
Refactor progressbar & blur handling
This tries to fix a number of related issues:
* the blurred thumbnail was visible for a split-second sometimes
when switching back to an already-loaded image. (Presumably when
JS was sluggish enough to take more than 10 ms to execute.) We
now check whether the promise is pending before showing a placeholder.
(More generally, a lot of unnecessary logic was executed when paging
through already loaded images, like displaying the placeholder, so
this might make the UI a bit more responsive.)
* the blur could get stuck sometimes - I have seen this a few times,
but have never been able to reproduce it, so I'm only guessing, but
maybe the timing was really unfortunate, and we switched back less
than 10 ms before loading finished. We now remove the blur on every
branch, just to be sure.
* adding a progress handler to a promise might not have any immediate
effect, so when switching to an image which was loading, the progress
bar reacted too late. We now store the progress state per thumbnail
so it is always available immediately.
* the progress would animate from 0 to its actual state whenever we
navigated to the image. The change on paging is now instant; the
progress bar only animates when we are looking at it.
* switching quickly back and forthe between a loaded and a loading
image resulted in the loading image becoming unblurred. This seems
fixed now, I'm not sure why. Maybe the "skip on non-pending promise"
logic affects it somehow.
Also removes some unused things / renames some things which were
confusing, and makes an unrelated fix in the image provider, which kept
amassing fail handlers.
Change-Id: I580becff246f197ec1bc65e82acd422620e35578
Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/489
2014-04-25 22:26:34 +00:00
viewer . displayRealThumbnail = this . sandbox . spy ( function ( ) { viewer . close ( ) ; } ) ;
2014-12-30 05:10:27 +00:00
secondImageDeferred . resolve ( { } , { } ) ;
2014-12-02 10:05:12 +00:00
secondLigthboxInfoDeferred . resolve ( { } ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2015-01-23 12:48:27 +00:00
assert . ok ( viewer . displayRealThumbnail . called , 'The second image being done loading should result in the image being shown' ) ;
2017-05-11 15:03:52 +00:00
clock . restore ( ) ;
2014-02-27 00:40:39 +00:00
} ) ;
2014-03-03 11:20:52 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Events are not trapped after the viewer is closed' , function ( assert ) {
2014-03-03 11:20:52 +00:00
var i , j , k , eventParameters ,
2016-04-03 09:18:26 +00:00
viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-03-03 11:20:52 +00:00
$document = $ ( document ) ,
$qf = $ ( '#qunit-fixture' ) ,
eventTypes = [ 'keydown' , 'keyup' , 'keypress' , 'click' , 'mousedown' , 'mouseup' ] ,
2014-03-29 01:38:22 +00:00
modifiers = [ undefined , 'altKey' , 'ctrlKey' , 'shiftKey' , 'metaKey' ] ,
2017-07-26 00:01:07 +00:00
// Events are async, we need to wait for the last event to be caught before ending the test
done = assert . async ( ) ,
2014-03-29 01:38:22 +00:00
oldScrollTo = $ . scrollTo ;
2017-07-25 23:38:21 +00:00
assert . expect ( 0 ) ;
2015-06-24 18:54:22 +00:00
// animation would keep running, conflict with other tests
this . sandbox . stub ( $ . fn , 'animate' ) . returnsThis ( ) ;
2015-01-23 12:48:27 +00:00
$ . scrollTo = function ( ) { return { scrollTop : $ . noop , on : $ . noop , off : $ . noop } ; } ;
2014-03-03 11:20:52 +00:00
2014-03-04 11:53:53 +00:00
viewer . setupEventHandlers ( ) ;
2015-01-23 12:48:27 +00:00
viewer . imageProvider . get = function ( ) { return $ . Deferred ( ) . reject ( ) ; } ;
viewer . imageInfoProvider . get = function ( ) { return $ . Deferred ( ) . reject ( ) ; } ;
viewer . thumbnailInfoProvider . get = function ( ) { return $ . Deferred ( ) . reject ( ) ; } ;
viewer . fileRepoInfoProvider . get = function ( ) { return $ . Deferred ( ) . reject ( ) ; } ;
2014-03-03 11:20:52 +00:00
viewer . preloadFullscreenThumbnail = $ . noop ;
viewer . initWithThumbs ( [ ] ) ;
2014-12-02 10:05:12 +00:00
viewer . loadImage ( { filePageTitle : new mw . Title ( 'File:Stuff.jpg' ) ,
thumbnail : new mw . mmv . model . Thumbnail ( 'foo' , 10 , 10 ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( ) } ,
2014-03-03 11:20:52 +00:00
new Image ( ) ) ;
2014-03-05 02:24:18 +00:00
viewer . ui . $closeButton . click ( ) ;
2014-03-03 11:20:52 +00:00
2016-07-18 13:49:27 +00:00
function eventHandler ( e ) {
2014-03-03 11:20:52 +00:00
if ( e . isDefaultPrevented ( ) ) {
2015-01-23 12:48:27 +00:00
assert . ok ( false , 'Event was incorrectly trapped: ' + e . which ) ;
2014-03-03 11:20:52 +00:00
}
e . preventDefault ( ) ;
// Wait for the last event
if ( e . which === 32 && e . type === 'mouseup' ) {
2014-03-04 11:53:53 +00:00
$document . off ( '.mmvtest' ) ;
viewer . cleanupEventHandlers ( ) ;
2014-03-29 01:38:22 +00:00
$ . scrollTo = oldScrollTo ;
2017-07-26 00:01:07 +00:00
done ( ) ;
2014-03-03 11:20:52 +00:00
}
}
for ( j = 0 ; j < eventTypes . length ; j ++ ) {
$document . on ( eventTypes [ j ] + '.mmvtest' , eventHandler ) ;
2016-07-18 13:49:27 +00:00
eventloop :
2014-03-03 11:20:52 +00:00
for ( i = 0 ; i < 256 ; i ++ ) {
// Save some time by not testing unlikely values for mouse events
if ( i > 32 ) {
switch ( eventTypes [ j ] ) {
case 'click' :
case 'mousedown' :
case 'mouseup' :
break eventloop ;
}
}
for ( k = 0 ; k < modifiers . length ; k ++ ) {
2015-01-23 12:48:27 +00:00
eventParameters = { which : i } ;
2014-03-03 11:20:52 +00:00
if ( modifiers [ k ] !== undefined ) {
eventParameters [ modifiers [ k ] ] = true ;
}
$qf . trigger ( $ . Event ( eventTypes [ j ] , eventParameters ) ) ;
}
}
}
} ) ;
2014-04-15 00:01:03 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Refuse to load too-big thumbnails' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-04-15 00:01:03 +00:00
intendedWidth = 50 ,
title = mw . Title . newFromText ( 'File:Foobar.svg' ) ;
viewer . thumbnailInfoProvider . get = function ( fileTitle , width ) {
assert . strictEqual ( width , intendedWidth ) ;
return $ . Deferred ( ) . reject ( ) ;
} ;
2014-04-10 01:08:36 +00:00
viewer . fetchThumbnail ( title , 1000 , null , intendedWidth , 60 ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'fetchThumbnail()' , function ( assert ) {
2014-04-17 03:00:42 +00:00
var guessedThumbnailInfoStub ,
thumbnailInfoStub ,
imageStub ,
promise ,
2016-04-03 09:18:26 +00:00
useThumbnailGuessing ,
2016-07-18 13:49:27 +00:00
viewer = new mw . mmv . MultimediaViewer ( { imageQueryParameter : $ . noop , language : $ . noop , recordVirtualViewBeaconURI : $ . noop , extensions : function ( ) { return { jpg : 'default' } ; } , useThumbnailGuessing : function ( ) { return useThumbnailGuessing ; } } ) ,
2014-04-17 03:00:42 +00:00
sandbox = this . sandbox ,
2014-04-10 01:08:36 +00:00
file = new mw . Title ( 'File:Copyleft.svg' ) ,
sampleURL = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png' ,
width = 100 ,
originalWidth = 1000 ,
originalHeight = 1000 ,
2017-05-11 15:03:52 +00:00
image = { } ,
// custom clock ensures progress handlers execute in correct sequence
clock = this . sandbox . useFakeTimers ( ) ;
2014-04-10 01:08:36 +00:00
2014-04-17 03:00:42 +00:00
function setupStubs ( ) {
guessedThumbnailInfoStub = viewer . guessedThumbnailInfoProvider . get = sandbox . stub ( ) ;
thumbnailInfoStub = viewer . thumbnailInfoProvider . get = sandbox . stub ( ) ;
imageStub = viewer . imageProvider . get = sandbox . stub ( ) ;
}
2014-04-10 01:08:36 +00:00
2016-04-03 09:18:26 +00:00
useThumbnailGuessing = true ;
2014-04-10 01:08:36 +00:00
2014-04-17 03:00:42 +00:00
// When we lack sample URL and original dimensions, the classic provider should be used
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'guessedURL' } ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . returns ( $ . Deferred ( ) . resolve ( image ) ) ;
promise = viewer . fetchThumbnail ( file , width ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( ! guessedThumbnailInfoStub . called , 'When we lack sample URL and original dimensions, GuessedThumbnailInfoProvider is not called' ) ;
assert . ok ( thumbnailInfoStub . calledOnce , 'When we lack sample URL and original dimensions, ThumbnailInfoProvider is called once' ) ;
assert . ok ( imageStub . calledOnce , 'When we lack sample URL and original dimensions, ImageProvider is called once' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . calledWith ( 'apiURL' ) , 'When we lack sample URL and original dimensions, ImageProvider is called with the API url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'resolved' , 'When we lack sample URL and original dimensions, fetchThumbnail resolves' ) ;
// When the guesser bails out, the classic provider should be used
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . reject ( ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . returns ( $ . Deferred ( ) . resolve ( image ) ) ;
promise = viewer . fetchThumbnail ( file , width , sampleURL , originalWidth , originalHeight ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( guessedThumbnailInfoStub . calledOnce , 'When the guesser bails out, GuessedThumbnailInfoProvider is called once' ) ;
assert . ok ( thumbnailInfoStub . calledOnce , 'When the guesser bails out, ThumbnailInfoProvider is called once' ) ;
assert . ok ( imageStub . calledOnce , 'When the guesser bails out, ImageProvider is called once' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . calledWith ( 'apiURL' ) , 'When the guesser bails out, ImageProvider is called with the API url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'resolved' , 'When the guesser bails out, fetchThumbnail resolves' ) ;
// When the guesser returns an URL, that should be used
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'guessedURL' } ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . returns ( $ . Deferred ( ) . resolve ( image ) ) ;
promise = viewer . fetchThumbnail ( file , width , sampleURL , originalWidth , originalHeight ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( guessedThumbnailInfoStub . calledOnce , 'When the guesser returns an URL, GuessedThumbnailInfoProvider is called once' ) ;
assert . ok ( ! thumbnailInfoStub . called , 'When the guesser returns an URL, ThumbnailInfoProvider is not called' ) ;
assert . ok ( imageStub . calledOnce , 'When the guesser returns an URL, ImageProvider is called once' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . calledWith ( 'guessedURL' ) , 'When the guesser returns an URL, ImageProvider is called with the guessed url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'resolved' , 'When the guesser returns an URL, fetchThumbnail resolves' ) ;
// When the guesser returns an URL, but that returns 404, image loading should be retried with the classic provider
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'guessedURL' } ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . withArgs ( 'guessedURL' ) . returns ( $ . Deferred ( ) . reject ( ) ) ;
imageStub . withArgs ( 'apiURL' ) . returns ( $ . Deferred ( ) . resolve ( image ) ) ;
promise = viewer . fetchThumbnail ( file , width , sampleURL , originalWidth , originalHeight ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( guessedThumbnailInfoStub . calledOnce , 'When the guesser returns an URL, but that returns 404, GuessedThumbnailInfoProvider is called once' ) ;
assert . ok ( thumbnailInfoStub . calledOnce , 'When the guesser returns an URL, but that returns 404, ThumbnailInfoProvider is called once' ) ;
assert . ok ( imageStub . calledTwice , 'When the guesser returns an URL, but that returns 404, ImageProvider is called twice' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . getCall ( 0 ) . calledWith ( 'guessedURL' ) , 'When the guesser returns an URL, but that returns 404, ImageProvider is called first with the guessed url' ) ;
assert . ok ( imageStub . getCall ( 1 ) . calledWith ( 'apiURL' ) , 'When the guesser returns an URL, but that returns 404, ImageProvider is called second with the guessed url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'resolved' , 'When the guesser returns an URL, but that returns 404, fetchThumbnail resolves' ) ;
// When even the retry fails, fetchThumbnail() should reject
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'guessedURL' } ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . withArgs ( 'guessedURL' ) . returns ( $ . Deferred ( ) . reject ( ) ) ;
imageStub . withArgs ( 'apiURL' ) . returns ( $ . Deferred ( ) . reject ( ) ) ;
promise = viewer . fetchThumbnail ( file , width , sampleURL , originalWidth , originalHeight ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( guessedThumbnailInfoStub . calledOnce , 'When even the retry fails, GuessedThumbnailInfoProvider is called once' ) ;
assert . ok ( thumbnailInfoStub . calledOnce , 'When even the retry fails, ThumbnailInfoProvider is called once' ) ;
assert . ok ( imageStub . calledTwice , 'When even the retry fails, ImageProvider is called twice' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . getCall ( 0 ) . calledWith ( 'guessedURL' ) , 'When even the retry fails, ImageProvider is called first with the guessed url' ) ;
assert . ok ( imageStub . getCall ( 1 ) . calledWith ( 'apiURL' ) , 'When even the retry fails, ImageProvider is called second with the guessed url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'rejected' , 'When even the retry fails, fetchThumbnail rejects' ) ;
2014-04-10 01:08:36 +00:00
2016-04-03 09:18:26 +00:00
useThumbnailGuessing = false ;
2014-04-10 01:08:36 +00:00
2014-04-17 03:00:42 +00:00
// When guessing is disabled, the classic provider is used
setupStubs ( ) ;
guessedThumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'guessedURL' } ) ) ;
thumbnailInfoStub . returns ( $ . Deferred ( ) . resolve ( { url : 'apiURL' } ) ) ;
imageStub . returns ( $ . Deferred ( ) . resolve ( image ) ) ;
promise = viewer . fetchThumbnail ( file , width ) ;
2017-05-11 15:03:52 +00:00
clock . tick ( 10 ) ;
2014-04-17 03:00:42 +00:00
assert . ok ( ! guessedThumbnailInfoStub . called , 'When guessing is disabled, GuessedThumbnailInfoProvider is not called' ) ;
assert . ok ( thumbnailInfoStub . calledOnce , 'When guessing is disabled, ThumbnailInfoProvider is called once' ) ;
assert . ok ( imageStub . calledOnce , 'When guessing is disabled, ImageProvider is called once' ) ;
2015-01-21 00:56:45 +00:00
assert . ok ( imageStub . calledWith ( 'apiURL' ) , 'When guessing is disabled, ImageProvider is called with the API url' ) ;
2014-04-17 03:00:42 +00:00
assert . strictEqual ( promise . state ( ) , 'resolved' , 'When guessing is disabled, fetchThumbnail resolves' ) ;
2017-05-11 15:03:52 +00:00
clock . restore ( ) ;
2014-04-15 00:01:03 +00:00
} ) ;
2014-07-01 22:22:06 +00:00
2017-07-25 23:38:21 +00:00
QUnit . test ( 'document.title' , function ( assert ) {
2016-04-03 09:18:26 +00:00
var viewer = mw . mmv . testHelpers . getMultimediaViewer ( ) ,
2014-07-01 22:22:06 +00:00
bootstrap = new mw . mmv . MultimediaViewerBootstrap ( ) ,
2015-01-23 12:48:27 +00:00
title = new mw . Title ( 'File:This_should_show_up_in_document_title.png' ) ,
2014-07-01 22:22:06 +00:00
oldDocumentTitle = document . title ;
viewer . currentImageFileTitle = title ;
bootstrap . setupEventHandlers ( ) ;
viewer . setHash ( ) ;
assert . ok ( document . title . match ( title . getNameText ( ) ) , 'File name is visible in title' ) ;
viewer . close ( ) ;
bootstrap . cleanupEventHandlers ( ) ;
2015-01-23 12:48:27 +00:00
assert . strictEqual ( document . title , oldDocumentTitle , 'Original title restored after viewer is closed' ) ;
2014-07-01 22:22:06 +00:00
} ) ;
2013-11-27 21:57:45 +00:00
} ( mediaWiki , jQuery ) ) ;