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 ) { ( function ( M, track, msg ) {
var MAX_PRINT_TIMEOUT = 3000, var MAX_PRINT_TIMEOUT = 3000,
GLYPH = 'download', mobile = M.require( 'mobile.startup' ),
icons = M.require( 'mobile.startup/icons' ), Icon = mobile.Icon,
Icon = M.require( 'mobile.startup/Icon' ), icons = mobile.icons,
browser = M.require( 'mobile.startup/Browser' ).getSingleton(); lazyImageLoader = mobile.lazyImages.lazyImageLoader,
browser = M.require( 'mobile.startup/Browser' ).getSingleton(),
GLYPH = 'download';
/** /**
* Helper function to retrieve the Android version * 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 // If all image downloads are taking longer to load then the MAX_PRINT_TIMEOUT
// abort the spinner and print regardless. // abort the spinner and print regardless.
icon.timeout = setTimeout( doPrint, MAX_PRINT_TIMEOUT ); 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 ) { ( 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', 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 ], VALID_SUPPORTED_NAMESPACES = [ 0 ],
Skin = M.require( 'mobile.startup/Skin' ), mobile = M.require( 'mobile.startup' ),
icons = M.require( 'mobile.startup/icons' ), Skin = mobile.Skin,
icons = mobile.icons,
Deferred = $.Deferred, Deferred = $.Deferred,
windowChrome = { chrome: true }, windowChrome = { chrome: true },
downloadIcon = icons.spinner(), downloadIcon = icons.spinner(),
windowNotChrome = {}, windowNotChrome = {},
getOnClickHandler = M.require( 'skins.minerva.scripts/test/getOnClickHandler' ), getOnClickHandler = M.require( 'skins.minerva.scripts/test/getOnClickHandler' ),
isAvailable = M.require( 'skins.minerva.scripts/test/isAvailable' ), isAvailable = M.require( 'skins.minerva.scripts/test/isAvailable' ),
browser = M.require( 'mobile.startup/Browser' ).getSingleton(), browser = mobile.Browser.getSingleton(),
Page = M.require( 'mobile.startup/Page' ); lazyImageLoader = mobile.lazyImages.lazyImageLoader,
Page = mobile.Page;
QUnit.module( 'Minerva DownloadIcon', { QUnit.module( 'Minerva DownloadIcon', {
beforeEach: function () { beforeEach: function () {
@ -31,7 +33,7 @@
d = Deferred(), d = Deferred(),
spy = this.sandbox.stub( window, 'print' ); spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d.resolve() ); this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d.resolve() );
handler(); handler();
d.then( function () { d.then( function () {
@ -46,7 +48,7 @@
d = Deferred(), d = Deferred(),
spy = this.sandbox.stub( window, 'print' ); spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d ); this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d );
window.setTimeout( function () { window.setTimeout( function () {
d.resolve(); d.resolve();
@ -55,7 +57,7 @@
handler(); handler();
d.then( function () { d.then( function () {
assert.strictEqual( spy.callCount, 1, 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; return d;
@ -66,7 +68,7 @@
d = Deferred(), d = Deferred(),
spy = this.sandbox.stub( window, 'print' ); spy = this.sandbox.stub( window, 'print' );
this.sandbox.stub( this.skin, 'loadImagesList' ).returns( d ); this.sandbox.stub( lazyImageLoader, 'loadImages' ).returns( d );
window.setTimeout( function () { window.setTimeout( function () {
d.resolve(); d.resolve();