From d1a20753face958880e3c1eb279b9bc798ef8b9d Mon Sep 17 00:00:00 2001 From: Stephen Niedzielski Date: Tue, 8 Jan 2019 20:35:28 +0000 Subject: [PATCH] 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 --- .../downloadPageAction.js | 14 +++++++++----- .../downloadPageAction.test.js | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/resources/skins.minerva.scripts/downloadPageAction.js b/resources/skins.minerva.scripts/downloadPageAction.js index f6eb2d2..d65125d 100644 --- a/resources/skins.minerva.scripts/downloadPageAction.js +++ b/resources/skins.minerva.scripts/downloadPageAction.js @@ -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 ); } } diff --git a/tests/qunit/skins.minerva.scripts/downloadPageAction.test.js b/tests/qunit/skins.minerva.scripts/downloadPageAction.test.js index 2a48217..dfd2ba8 100644 --- a/tests/qunit/skins.minerva.scripts/downloadPageAction.test.js +++ b/tests/qunit/skins.minerva.scripts/downloadPageAction.test.js @@ -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();