Hygiene: revise lazy image loading API

Update the API usage for lazily loaded images. This is still clumsy and
may be further revised in future patches.

Bug: T211724
Depends-On: Ic73f78825eaab561e8ed694aa6cc102ccb471f95
Change-Id: Ia708cda688e6bdb12074d85d98f7e98fdf7b0ca8
This commit is contained in:
Stephen Niedzielski 2019-01-08 20:35:28 +00:00
parent b9f8b86c8b
commit d1a20753fa
2 changed files with 19 additions and 13 deletions

View File

@ -1,9 +1,11 @@
( function ( M, track, msg ) {
var MAX_PRINT_TIMEOUT = 3000,
GLYPH = 'download',
icons = M.require( 'mobile.startup/icons' ),
Icon = M.require( 'mobile.startup/Icon' ),
browser = M.require( 'mobile.startup/Browser' ).getSingleton();
mobile = M.require( 'mobile.startup' ),
Icon = mobile.Icon,
icons = mobile.icons,
lazyImageLoader = mobile.lazyImages.lazyImageLoader,
browser = M.require( 'mobile.startup/Browser' ).getSingleton(),
GLYPH = 'download';
/**
* Helper function to retrieve the Android version
@ -94,7 +96,9 @@
// If all image downloads are taking longer to load then the MAX_PRINT_TIMEOUT
// abort the spinner and print regardless.
icon.timeout = setTimeout( doPrint, MAX_PRINT_TIMEOUT );
skin.loadImagesList().then( doPrintBeforeTimeout, doPrintBeforeTimeout );
lazyImageLoader.loadImages(
skin.$.bind( skin ), skin.getUnloadedImages()
).then( doPrintBeforeTimeout, doPrintBeforeTimeout );
}
}

View File

@ -1,16 +1,18 @@
( function ( M ) {
var VALID_UA = 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Mobile Safari/537.36',
VALID_SUPPORTED_NAMESPACES = [ 0 ],
Skin = M.require( 'mobile.startup/Skin' ),
icons = M.require( 'mobile.startup/icons' ),
mobile = M.require( 'mobile.startup' ),
Skin = mobile.Skin,
icons = mobile.icons,
Deferred = $.Deferred,
windowChrome = { chrome: true },
downloadIcon = icons.spinner(),
windowNotChrome = {},
getOnClickHandler = M.require( 'skins.minerva.scripts/test/getOnClickHandler' ),
isAvailable = M.require( 'skins.minerva.scripts/test/isAvailable' ),
browser = M.require( 'mobile.startup/Browser' ).getSingleton(),
Page = M.require( 'mobile.startup/Page' );
browser = mobile.Browser.getSingleton(),
lazyImageLoader = mobile.lazyImages.lazyImageLoader,
Page = mobile.Page;
QUnit.module( 'Minerva DownloadIcon', {
beforeEach: function () {
@ -31,7 +33,7 @@
d = Deferred(),
spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d.resolve() );
this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d.resolve() );
handler();
d.then( function () {
@ -46,7 +48,7 @@
d = Deferred(),
spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d );
this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d );
window.setTimeout( function () {
d.resolve();
@ -55,7 +57,7 @@
handler();
d.then( function () {
assert.strictEqual( spy.callCount, 1,
'Print was called once despite loadImagesList resolving after MAX_PRINT_TIMEOUT' );
'Print was called once despite loadImages resolving after MAX_PRINT_TIMEOUT' );
} );
return d;
@ -66,7 +68,7 @@
d = Deferred(),
spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d );
this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d );
window.setTimeout( function () {
d.resolve();