tests: Remove pointless "Hash handling" test that leaves black overlay
This test was leaving behind the black overlay, obscuring the test
results interface. Upon closer inspection, it appears not one part
of this test is doing anything that actually works.
* Assertion 1: `viewer.isOpen === false`
This is the initial and default state. Not essential for the test,
but so far so good.
* Prep for Assertion 2 & 3:
We call loadImageByTitle. One might think that this will set isOpen
to true, but, this isn't asserted. If one did, the test would fail,
because loadImageByTitle returns early from its first branch
in `!this.thumbs.length` and is thus a no-op, and adds nothing to
the test.
We set `location.hash = 'Foo'`.
* Assertion 2: `location.hash === '#Foo'`
Assertion 3: `viewer.isOpen === false`
Assertion 2 is meaningless because handling of hash changes appears
to be asynchronous. Perhaps not always, but at least the indirection
used in this codebase makes it async. Hence, the fact that it is
correctly normalised to '#Foo' is meaningless as the popstate
and hashchange event handler haven't been processed yet. If they
were, it would still be meaningless since viewer.isOpen was never
true in the first place and MMV's event handlers for popstate/hashchange
are guarded by `isOpen`.
* Prep for Assertion 4: location.hash = Bar
* Assertion 4: `location.hash === '#Bar'`
Idem.
* Prep for Assertion 5: Replace the viewer.loadImageByTitle function
with a function that performs a nested assertion.
This function is never called and its assertion never reached.
This is a textbook example why assertions should never be
nested. If you rewrite this in following with the advice from
<https://api.qunitjs.com/assert/verifySteps/>, we find that
the array is in fact empty by the end of the test() function.
```js
var seen = [];
viewer.loadImageByTitle = function ( title ) {
// assert.strictEqual( … );
seen.push( title.getPrefixedText() );
};
location.hash = …;
location.hash = …;
location.hash = …;
location.hash = …;
assert.deepEqual( seen, [ 'File:' + imageSrc' } );
// Actual: []
```
== Misc notes ==
The test ends with "#/media/File:Foo bar.jpg" set on location.hash,
and the black overlay covering the page. It seems that the hashchange
are async, and that the first in a given event loop tick "wins", with
later ones being ignored. Observing this with debugger/breakpoints is
hard given that each pause results in the effect not being observable.
console.log(location.href) at the end of the test shows hash='#',
but placing a debugger at the end of the test results in the hash
being "#/media/…" instead.
Exprienced in Firefox 117 on macOS.
Change-Id: Ib37bec1b3e67fcab1da89d23381a3adbb6312827
2023-10-06 02:41:22 +00:00
const { MultimediaViewer , Thumbnail } = require ( 'mmv' ) ;
2023-05-20 08:30:52 +00:00
const { getMultimediaViewer } = require ( './mmv.testhelpers.js' ) ;
const { MultimediaViewerBootstrap } = require ( 'mmv.bootstrap' ) ;
2018-11-12 16:33:24 +00:00
( function ( ) {
2023-10-06 02:58:23 +00:00
QUnit . module ( 'mmv' , QUnit . newMwEnvironment ( {
beforeEach : function ( ) {
// prevent a real "back" navigation from taking place
this . sandbox . stub ( require ( 'mediawiki.router' ) , 'back' ) ;
}
} ) ) ;
2013-11-27 21:57:45 +00:00
2019-05-18 16:19:44 +00:00
QUnit . test ( 'eachPreloadableLightboxIndex()' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
let expectedIndices ;
let i ;
2014-02-13 09:52:40 +00:00
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 ] ;
2019-05-18 16:19:44 +00:00
viewer . eachPreloadableLightboxIndex ( 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 ] ;
2019-05-18 16:19:44 +00:00
viewer . eachPreloadableLightboxIndex ( 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 ( 'Progress' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const imageDeferred = $ . Deferred ( ) ;
const viewer = getMultimediaViewer ( ) ;
const fakeImage = {
filePageTitle : new mw . Title ( 'File:Stuff.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ;
// custom clock ensures progress handlers execute in correct sequence
const clock = this . sandbox . useFakeTimers ( ) ;
2014-02-25 13:43:22 +00:00
viewer . thumbs = [ ] ;
2019-02-05 23:59:52 +00:00
viewer . displayPlaceholderThumbnail = function ( ) { } ;
viewer . setImage = function ( ) { } ;
viewer . scroll = function ( ) { } ;
viewer . preloadFullscreenThumbnail = function ( ) { } ;
2023-06-27 20:33:13 +00:00
viewer . fetchSizeIndependentLightboxInfo = ( ) => $ . Deferred ( ) . resolve ( { } ) ;
2014-03-05 02:24:18 +00:00
viewer . ui = {
2019-02-05 23:59:52 +00:00
setFileReuseData : function ( ) { } ,
setupForLoad : function ( ) { } ,
canvas : { set : function ( ) { } ,
unblurWithAnimation : function ( ) { } ,
unblur : function ( ) { } ,
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 : {
2019-02-05 23:59:52 +00:00
setImageInfo : function ( ) { } ,
2014-05-05 21:44:27 +00:00
scroller : {
2019-02-05 23:59:52 +00:00
animateMetadataOnce : function ( ) { }
2014-05-05 21:44:27 +00:00
} ,
2014-04-21 21:48:40 +00:00
progressBar : {
2023-04-25 08:49:10 +00:00
hide : 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
animateTo : this . sandbox . stub ( ) ,
jumpTo : this . sandbox . stub ( )
2014-03-05 02:24:18 +00:00
}
} ,
2019-02-05 23:59:52 +00:00
open : function ( ) { } } ;
2014-02-25 13:43:22 +00:00
2023-06-27 20:33:13 +00:00
viewer . imageProvider . get = ( ) => imageDeferred . promise ( ) ;
viewer . imageInfoProvider . get = ( ) => $ . Deferred ( ) . resolve ( { } ) ;
viewer . thumbnailInfoProvider . get = ( ) => $ . 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . jumpTo . lastCall . calledWith ( 0 ) , 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
'Percentage correctly reset by loadImage' ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . firstCall . calledWith ( 5 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . secondCall . calledWith ( 45 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . thirdCall . calledWith ( 100 ) , 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
'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 ) {
2023-10-24 09:53:23 +00:00
const firstImageDeferred = $ . Deferred ( ) ;
const secondImageDeferred = $ . Deferred ( ) ;
const firstImage = {
index : 1 ,
filePageTitle : new mw . Title ( 'File:First.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ;
const secondImage = {
index : 2 ,
filePageTitle : new mw . Title ( 'File:Second.jpg' ) ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ;
const viewer = getMultimediaViewer ( ) ;
// custom clock ensures progress handlers execute in correct sequence
const 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 = [ ] ;
2019-02-05 23:59:52 +00:00
viewer . displayPlaceholderThumbnail = function ( ) { } ;
viewer . setImage = function ( ) { } ;
viewer . scroll = function ( ) { } ;
viewer . preloadFullscreenThumbnail = function ( ) { } ;
viewer . preloadImagesMetadata = function ( ) { } ;
viewer . preloadThumbnails = function ( ) { } ;
2023-06-27 20:33:13 +00:00
viewer . fetchSizeIndependentLightboxInfo = ( ) => $ . 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 = {
2019-02-05 23:59:52 +00:00
setFileReuseData : function ( ) { } ,
setupForLoad : function ( ) { } ,
canvas : { set : function ( ) { } ,
unblurWithAnimation : function ( ) { } ,
unblur : function ( ) { } ,
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 : {
2019-02-05 23:59:52 +00:00
setImageInfo : function ( ) { } ,
2014-05-05 21:44:27 +00:00
scroller : {
2019-02-05 23:59:52 +00:00
animateMetadataOnce : function ( ) { }
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 ( )
}
} ,
2019-02-05 23:59:52 +00:00
open : function ( ) { } ,
empty : function ( ) { } } ;
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
2023-06-27 20:33:13 +00:00
viewer . imageInfoProvider . get = ( ) => $ . Deferred ( ) . resolve ( { } ) ;
viewer . thumbnailInfoProvider . get = ( ) => $ . 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . jumpTo . getCall ( 0 ) . calledWith ( 0 ) , 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
'Percentage correctly reset for new first image' ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . getCall ( 0 ) . calledWith ( 5 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . getCall ( 1 ) . calledWith ( 20 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . jumpTo . getCall ( 1 ) . calledWith ( 0 ) , 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
'Percentage correctly reset for second new image' ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . getCall ( 2 ) . calledWith ( 5 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . getCall ( 3 ) . calledWith ( 30 ) , 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
'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 ) ;
2018-06-06 17:23:16 +00:00
assert . strictEqual ( 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . getCall ( 4 ) . calledWith ( 50 ) , true ,
2017-05-11 15:03:52 +00:00
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . jumpTo . getCall ( 2 ) . calledWith ( 40 ) , 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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . hide . called , false ,
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
'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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . hide . called , true ,
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 ) {
2023-10-24 09:53:23 +00:00
const viewer = 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 ( ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , false , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , false , 'Placeholder state is correct' ) ;
2014-02-25 13:43:22 +00:00
viewer . realThumbnailShown = true ;
viewer . blurredThumbnailShown = true ;
viewer . resetBlurredThumbnailStates ( ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , false , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , false , 'Placeholder state is correct' ) ;
2014-02-25 13:43:22 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Placeholder first, then real thumbnail' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
2019-02-05 23:59:52 +00:00
viewer . setImage = function ( ) { } ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
2019-02-05 23:59:52 +00:00
unblurWithAnimation : function ( ) { } ,
unblur : function ( ) { } ,
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
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . blurredThumbnailShown , true , 'Placeholder state is correct' ) ;
assert . strictEqual ( viewer . realThumbnailShown , false , 'Real thumbnail state is correct' ) ;
2014-04-24 01:03:24 +00:00
2015-01-23 12:48:27 +00:00
viewer . displayRealThumbnail ( { url : undefined } ) ;
2014-04-24 01:03:24 +00:00
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , true , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , true , 'Placeholder state is correct' ) ;
2014-04-24 01:03:24 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Placeholder first, then real thumbnail - missing size' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
2014-04-24 01:03:24 +00:00
viewer . currentIndex = 1 ;
2019-02-05 23:59:52 +00:00
viewer . setImage = function ( ) { } ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
2019-02-05 23:59:52 +00:00
unblurWithAnimation : function ( ) { } ,
unblur : function ( ) { } ,
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
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . blurredThumbnailShown , true , 'Placeholder state is correct' ) ;
assert . strictEqual ( viewer . realThumbnailShown , false , 'Real thumbnail state is correct' ) ;
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
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , true , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , true , 'Placeholder state is correct' ) ;
2014-02-25 13:43:22 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Real thumbnail first, then placeholder' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
2019-02-05 23:59:52 +00:00
viewer . setImage = function ( ) { } ;
2014-03-05 02:24:18 +00:00
viewer . ui = {
2019-02-05 23:59:52 +00:00
showImage : function ( ) { } ,
2015-01-23 12:48:27 +00:00
canvas : {
2019-02-05 23:59:52 +00:00
unblurWithAnimation : function ( ) { } ,
unblur : function ( ) { }
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
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , true , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , false , 'Placeholder state is correct' ) ;
2014-02-25 13:43:22 +00:00
2015-01-23 12:48:27 +00:00
viewer . displayPlaceholderThumbnail ( { } , undefined , undefined ) ;
2014-02-25 13:43:22 +00:00
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . realThumbnailShown , true , 'Real thumbnail state is correct' ) ;
assert . strictEqual ( viewer . blurredThumbnailShown , false , 'Placeholder state is correct' ) ;
2014-02-25 13:43:22 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'displayRealThumbnail' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
2014-02-25 13:43:22 +00:00
2019-02-05 23:59:52 +00:00
viewer . setImage = function ( ) { } ;
2015-01-23 12:48:27 +00:00
viewer . ui = { canvas : {
unblurWithAnimation : this . sandbox . stub ( ) ,
2019-02-05 23:59:52 +00:00
unblur : function ( ) { }
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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . canvas . unblurWithAnimation . called , false , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . canvas . unblurWithAnimation . called , true , '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 ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
const firstImageDeferred = $ . Deferred ( ) ;
const secondImageDeferred = $ . Deferred ( ) ;
const firstLigthboxInfoDeferred = $ . Deferred ( ) ;
const secondLigthboxInfoDeferred = $ . Deferred ( ) ;
const firstImage = {
filePageTitle : new mw . Title ( 'File:Foo.jpg' ) ,
index : 0 ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ;
const secondImage = {
filePageTitle : new mw . Title ( 'File:Bar.jpg' ) ,
index : 1 ,
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ;
// custom clock ensures progress handlers execute in correct sequence
const clock = this . sandbox . useFakeTimers ( ) ;
2014-02-27 00:40:39 +00:00
2019-02-05 23:59:52 +00:00
viewer . preloadFullscreenThumbnail = function ( ) { } ;
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 = {
2019-02-05 23:59:52 +00:00
setFileReuseData : function ( ) { } ,
setupForLoad : function ( ) { } ,
2015-01-23 12:48:27 +00:00
canvas : {
2019-02-05 23:59:52 +00:00
set : function ( ) { } ,
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 : this . sandbox . stub ( ) ,
2014-05-05 21:44:27 +00:00
scroller : {
2019-02-05 23:59:52 +00:00
animateMetadataOnce : function ( ) { }
2014-05-05 21:44:27 +00:00
} ,
2014-04-21 21:48:40 +00:00
progressBar : {
2023-04-25 08:49:10 +00:00
hide : this . sandbox . stub ( ) ,
2015-01-23 12:48:27 +00:00
animateTo : this . sandbox . stub ( ) ,
jumpTo : this . sandbox . stub ( )
2014-03-05 02:24:18 +00:00
} ,
2019-02-05 23:59:52 +00:00
empty : function ( ) { }
2014-03-05 02:24:18 +00:00
} ,
2019-02-05 23:59:52 +00:00
open : function ( ) { } ,
empty : function ( ) { } } ;
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 ( ) ;
2019-05-18 16:19:44 +00:00
viewer . eachPreloadableLightboxIndex = function ( ) { } ;
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 ( ) ;
2023-06-27 20:33:13 +00:00
viewer . imageInfoProvider . get = ( ) => $ . Deferred ( ) . reject ( { } ) ;
viewer . thumbnailInfoProvider . get = ( ) => $ . 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . animateMetadataDivOnce . called , false , 'Metadata of the first image should not be animated' ) ;
assert . strictEqual ( viewer . ui . panel . setImageInfo . called , false , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . ui . panel . progressBar . animateTo . reset . called , undefined , 'Progress of the first image should not be shown' ) ;
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
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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . displayRealThumbnail . called , false , 'The first image being done loading should have no effect' ) ;
2014-02-27 00:40:39 +00:00
2023-06-27 20:33:13 +00:00
viewer . displayRealThumbnail = this . sandbox . spy ( ( ) => 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( viewer . displayRealThumbnail . called , true , '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 ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
const $document = $ ( document ) ;
const $qf = $ ( '#qunit-fixture' ) ;
const eventTypes = [ 'keydown' , 'keyup' , 'keypress' , 'click' , 'mousedown' , 'mouseup' ] ;
const modifiers = [ undefined , 'altKey' , 'ctrlKey' , 'shiftKey' , 'metaKey' ] ;
// Events are async, we need to wait for the last event to be caught before ending the test
const done = assert . async ( ) ;
const oldScrollTo = $ . scrollTo ;
2014-03-29 01:38:22 +00:00
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 ( ) ;
2023-06-27 20:33:13 +00:00
$ . scrollTo = function ( ) {
return { scrollTop : ( ) => { } , on : ( ) => { } , off : ( ) => { } } ;
} ;
2014-03-03 11:20:52 +00:00
2014-03-04 11:53:53 +00:00
viewer . setupEventHandlers ( ) ;
2023-06-27 20:33:13 +00:00
viewer . imageProvider . get = ( ) => $ . Deferred ( ) . reject ( ) ;
viewer . imageInfoProvider . get = ( ) => $ . Deferred ( ) . reject ( ) ;
viewer . thumbnailInfoProvider . get = ( ) => $ . Deferred ( ) . reject ( ) ;
viewer . fileRepoInfoProvider . get = ( ) => $ . Deferred ( ) . reject ( ) ;
2014-03-03 11:20:52 +00:00
2019-02-05 23:59:52 +00:00
viewer . preloadFullscreenThumbnail = function ( ) { } ;
2014-03-03 11:20:52 +00:00
viewer . initWithThumbs ( [ ] ) ;
2017-10-31 17:49:29 +00:00
viewer . loadImage (
{
filePageTitle : new mw . Title ( 'File:Stuff.jpg' ) ,
2023-05-20 08:30:52 +00:00
thumbnail : new Thumbnail ( 'foo' , 10 , 10 ) ,
2017-10-31 17:49:29 +00:00
extraStatsDeferred : $ . Deferred ( ) . reject ( )
} ,
new Image ( )
) ;
2014-03-03 11:20:52 +00:00
2018-04-24 14:47:41 +00:00
viewer . ui . $closeButton . trigger ( '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 ( ) ) {
2022-05-20 00:18:43 +00:00
assert . true ( 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
}
}
2023-10-24 09:53:23 +00:00
for ( let j = 0 ; j < eventTypes . length ; j ++ ) {
2014-03-03 11:20:52 +00:00
$document . on ( eventTypes [ j ] + '.mmvtest' , eventHandler ) ;
2016-07-18 13:49:27 +00:00
eventloop :
2023-10-24 09:53:23 +00:00
for ( let i = 0 ; i < 256 ; i ++ ) {
2014-03-03 11:20:52 +00:00
// 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 ;
}
}
2023-10-24 09:53:23 +00:00
for ( let k = 0 ; k < modifiers . length ; k ++ ) {
const 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 ) {
2023-10-24 09:53:23 +00:00
let expectedWidth ;
const reuestedWidth = 1000 ;
const originalWidth = 50 ;
const viewer = getMultimediaViewer ( ) ;
2014-04-15 00:01:03 +00:00
viewer . thumbnailInfoProvider . get = function ( fileTitle , width ) {
2018-11-22 15:17:40 +00:00
assert . strictEqual ( width , expectedWidth ) ;
2014-04-15 00:01:03 +00:00
return $ . Deferred ( ) . reject ( ) ;
} ;
2018-11-22 15:17:40 +00:00
// non-vector should be capped to original size
2023-10-24 09:53:23 +00:00
let title = mw . Title . newFromText ( 'File:Foobar.png' ) ;
2018-11-22 15:17:40 +00:00
expectedWidth = originalWidth ;
viewer . fetchThumbnail ( title , reuestedWidth , null , originalWidth , 60 ) ;
// vector images can be aritrarily large
title = mw . Title . newFromText ( 'File:Foobar.svg' ) ;
expectedWidth = reuestedWidth ;
viewer . fetchThumbnail ( title , reuestedWidth , null , originalWidth , 60 ) ;
2014-04-10 01:08:36 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'fetchThumbnail()' , function ( assert ) {
2023-10-24 09:53:23 +00:00
let guessedThumbnailInfoStub ;
let thumbnailInfoStub ;
let imageStub ;
let promise ;
let useThumbnailGuessing ;
const viewer = new MultimediaViewer ( {
imageQueryParameter : function ( ) { } ,
language : function ( ) { } ,
recordVirtualViewBeaconURI : function ( ) { } ,
extensions : function ( ) {
return { jpg : 'default' } ;
} ,
useThumbnailGuessing : ( ) => useThumbnailGuessing
} ) ;
const sandbox = this . sandbox ;
const file = new mw . Title ( 'File:Copyleft.svg' ) ;
const sampleURL = 'http://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Copyleft.svg/300px-Copyleft.svg.png' ;
const width = 100 ;
const originalWidth = 1000 ;
const originalHeight = 1000 ;
const image = { } ;
// custom clock ensures progress handlers execute in correct sequence
const 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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . called , false , 'When we lack sample URL and original dimensions, GuessedThumbnailInfoProvider is not called' ) ;
assert . strictEqual ( thumbnailInfoStub . calledOnce , true , 'When we lack sample URL and original dimensions, ThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( imageStub . calledOnce , true , 'When we lack sample URL and original dimensions, ImageProvider is called once' ) ;
assert . strictEqual ( imageStub . calledWith ( 'apiURL' ) , true , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . calledOnce , true , 'When the guesser bails out, GuessedThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( thumbnailInfoStub . calledOnce , true , 'When the guesser bails out, ThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( imageStub . calledOnce , true , 'When the guesser bails out, ImageProvider is called once' ) ;
assert . strictEqual ( imageStub . calledWith ( 'apiURL' ) , true , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . calledOnce , true , 'When the guesser returns an URL, GuessedThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( thumbnailInfoStub . called , false , 'When the guesser returns an URL, ThumbnailInfoProvider is not called' ) ;
assert . strictEqual ( imageStub . calledOnce , true , 'When the guesser returns an URL, ImageProvider is called once' ) ;
assert . strictEqual ( imageStub . calledWith ( 'guessedURL' ) , true , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . calledOnce , true , 'When the guesser returns an URL, but that returns 404, GuessedThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( thumbnailInfoStub . calledOnce , true , 'When the guesser returns an URL, but that returns 404, ThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( imageStub . calledTwice , true , 'When the guesser returns an URL, but that returns 404, ImageProvider is called twice' ) ;
assert . strictEqual ( imageStub . getCall ( 0 ) . calledWith ( 'guessedURL' ) , true , 'When the guesser returns an URL, but that returns 404, ImageProvider is called first with the guessed url' ) ;
assert . strictEqual ( imageStub . getCall ( 1 ) . calledWith ( 'apiURL' ) , true , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . calledOnce , true , 'When even the retry fails, GuessedThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( thumbnailInfoStub . calledOnce , true , 'When even the retry fails, ThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( imageStub . calledTwice , true , 'When even the retry fails, ImageProvider is called twice' ) ;
assert . strictEqual ( imageStub . getCall ( 0 ) . calledWith ( 'guessedURL' ) , true , 'When even the retry fails, ImageProvider is called first with the guessed url' ) ;
assert . strictEqual ( imageStub . getCall ( 1 ) . calledWith ( 'apiURL' ) , true , '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 ) ;
2018-06-06 18:23:25 +00:00
assert . strictEqual ( guessedThumbnailInfoStub . called , false , 'When guessing is disabled, GuessedThumbnailInfoProvider is not called' ) ;
assert . strictEqual ( thumbnailInfoStub . calledOnce , true , 'When guessing is disabled, ThumbnailInfoProvider is called once' ) ;
assert . strictEqual ( imageStub . calledOnce , true , 'When guessing is disabled, ImageProvider is called once' ) ;
assert . strictEqual ( imageStub . calledWith ( 'apiURL' ) , true , '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 ) {
2023-10-24 09:53:23 +00:00
const viewer = getMultimediaViewer ( ) ;
const bootstrap = new MultimediaViewerBootstrap ( ) ;
const title = new mw . Title ( 'File:This_should_show_up_in_document_title.png' ) ;
const oldDocumentTitle = document . title ;
2014-07-01 22:22:06 +00:00
2023-04-28 21:49:00 +00:00
this . sandbox . stub ( mw . loader , 'using' ) . returns ( $ . Deferred ( ) . resolve ( viewer ) ) ;
2014-07-01 22:22:06 +00:00
viewer . currentImageFileTitle = title ;
bootstrap . setupEventHandlers ( ) ;
2023-04-28 21:49:00 +00:00
viewer . setTitle ( ) ;
2014-07-01 22:22:06 +00:00
2022-05-20 00:18:43 +00:00
assert . notStrictEqual ( document . title . match ( title . getNameText ( ) ) , null , 'File name is visible in title' ) ;
2014-07-01 22:22:06 +00:00
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
} ) ;
2018-11-12 16:33:24 +00:00
} ( ) ) ;