From bea1da1fabb8f1d22c15d9d1d1ad5dfc5657435b Mon Sep 17 00:00:00 2001 From: Amanda Dillon Date: Fri, 18 Dec 2020 18:54:13 -0700 Subject: [PATCH 1/2] Default to 4/3 aspect ratio when response doesn't contain w or h --- modules/spotxBidAdapter.js | 46 +++++++++--------- test/spec/modules/spotxBidAdapter_spec.js | 57 ++++++++++++++++++++++- 2 files changed, 77 insertions(+), 26 deletions(-) diff --git a/modules/spotxBidAdapter.js b/modules/spotxBidAdapter.js index 6104fce1d97..f312271c435 100644 --- a/modules/spotxBidAdapter.js +++ b/modules/spotxBidAdapter.js @@ -51,7 +51,7 @@ export const spec = { return false; } if (!utils.getBidIdParameter('slot', bid.params.outstream_options)) { - utils.logError(BIDDER_CODE + ': please define parameters slot outstream_options object in the configuration.'); + utils.logError(BIDDER_CODE + ': please define parameter slot in outstream_options object in the configuration.'); return false; } } @@ -382,7 +382,7 @@ export const spec = { } }); } catch (err) { - utils.logWarn('Prebid Error calling setRender or setEve,tHandlers on renderer', err); + utils.logWarn('Prebid Error calling setRender or setEventHandlers on renderer', err); } bid.renderer = renderer; } @@ -408,7 +408,7 @@ function createOutstreamScript(bid) { dataSpotXParams['data-spotx_content_page_url'] = bid.renderer.config.content_page_url; dataSpotXParams['data-spotx_ad_unit'] = 'incontent'; - utils.logMessage('[SPOTX][renderer] Default beahavior'); + utils.logMessage('[SPOTX][renderer] Default behavior'); if (utils.getBidIdParameter('ad_mute', bid.renderer.config.outstream_options)) { dataSpotXParams['data-spotx_ad_mute'] = '1'; } @@ -419,30 +419,26 @@ function createOutstreamScript(bid) { const playersizeAutoAdapt = utils.getBidIdParameter('playersize_auto_adapt', bid.renderer.config.outstream_options); if (playersizeAutoAdapt && utils.isBoolean(playersizeAutoAdapt) && playersizeAutoAdapt === true) { - if (bid.width && utils.isNumber(bid.width) && bid.height && utils.isNumber(bid.height)) { - const ratio = bid.width / bid.height; - const slotClientWidth = window.document.getElementById(slot).clientWidth; - let playerWidth = bid.renderer.config.player_width; - let playerHeight = bid.renderer.config.player_height; - let contentWidth = 0; - let contentHeight = 0; - if (slotClientWidth < playerWidth) { - playerWidth = slotClientWidth; - playerHeight = playerWidth / ratio; - } - if (ratio <= 1) { - contentWidth = Math.round(playerHeight * ratio); - contentHeight = playerHeight; - } else { - contentWidth = playerWidth; - contentHeight = Math.round(playerWidth / ratio); - } - - dataSpotXParams['data-spotx_content_width'] = '' + contentWidth; - dataSpotXParams['data-spotx_content_height'] = '' + contentHeight; + const ratio = bid.width && utils.isNumber(bid.width) && bid.height && utils.isNumber(bid.height) ? bid.width / bid.height : 4 / 3; + const slotClientWidth = window.document.getElementById(slot).clientWidth; + let playerWidth = bid.renderer.config.player_width; + let playerHeight = bid.renderer.config.player_height; + let contentWidth = 0; + let contentHeight = 0; + if (slotClientWidth < playerWidth) { + playerWidth = slotClientWidth; + playerHeight = playerWidth / ratio; + } + if (ratio <= 1) { + contentWidth = Math.round(playerHeight * ratio); + contentHeight = playerHeight; } else { - utils.logWarn('[SPOTX][renderer] PlayerSize auto adapt: bid.width and bid.height are incorrect'); + contentWidth = playerWidth; + contentHeight = Math.round(playerWidth / ratio); } + + dataSpotXParams['data-spotx_content_width'] = '' + contentWidth; + dataSpotXParams['data-spotx_content_height'] = '' + contentHeight; } const customOverride = utils.getBidIdParameter('custom_override', bid.renderer.config.outstream_options); diff --git a/test/spec/modules/spotxBidAdapter_spec.js b/test/spec/modules/spotxBidAdapter_spec.js index 798fb3eec10..ebb51e87e60 100644 --- a/test/spec/modules/spotxBidAdapter_spec.js +++ b/test/spec/modules/spotxBidAdapter_spec.js @@ -488,7 +488,7 @@ describe('the spotx adapter', function () { }); }); - describe('oustreamRender', function() { + describe('outstreamRender', function() { var serverResponse, bidderRequestObj; beforeEach(function() { @@ -542,6 +542,61 @@ describe('the spotx adapter', function () { }; }); + it('should adjust width and height to slot\'s clientWidth if playersize_auto_adapt is used', function() { + var scriptTag; + sinon.stub(window.document, 'getElementById').returns({ + clientWidth: 200, + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) + }); + var responses = spec.interpretResponse(serverResponse, bidderRequestObj); + + responses[0].renderer.render(responses[0]); + + expect(scriptTag.getAttribute('type')).to.equal('text/javascript'); + expect(scriptTag.getAttribute('src')).to.equal('https://js.spotx.tv/easi/v1/12345.js'); + expect(scriptTag.getAttribute('data-spotx_channel_id')).to.equal('12345'); + expect(scriptTag.getAttribute('data-spotx_vast_url')).to.equal('https://search.spotxchange.com/ad/vast.html?key=cache123'); + expect(scriptTag.getAttribute('data-spotx_ad_unit')).to.equal('incontent'); + expect(scriptTag.getAttribute('data-spotx_collapse')).to.equal('0'); + expect(scriptTag.getAttribute('data-spotx_autoplay')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); + expect(scriptTag.getAttribute('data-spotx_ad_mute')).to.equal('1'); + window.document.getElementById.restore(); + }); + + it('should use a default 4/3 ratio if playersize_auto_adapt is used and response does not contain width or height', function() { + delete serverResponse.body.seatbid[0].bid[0].w; + delete serverResponse.body.seatbid[0].bid[0].h; + + var scriptTag; + sinon.stub(window.document, 'getElementById').returns({ + clientWidth: 200, + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) + }); + var responses = spec.interpretResponse(serverResponse, bidderRequestObj); + + responses[0].renderer.render(responses[0]); + + expect(scriptTag.getAttribute('type')).to.equal('text/javascript'); + expect(scriptTag.getAttribute('src')).to.equal('https://js.spotx.tv/easi/v1/12345.js'); + expect(scriptTag.getAttribute('data-spotx_channel_id')).to.equal('12345'); + expect(scriptTag.getAttribute('data-spotx_vast_url')).to.equal('https://search.spotxchange.com/ad/vast.html?key=cache123'); + expect(scriptTag.getAttribute('data-spotx_ad_unit')).to.equal('incontent'); + expect(scriptTag.getAttribute('data-spotx_collapse')).to.equal('0'); + expect(scriptTag.getAttribute('data-spotx_autoplay')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); + expect(scriptTag.getAttribute('data-spotx_ad_mute')).to.equal('1'); + window.document.getElementById.restore(); + }); + it('should attempt to insert the EASI script', function() { var scriptTag; sinon.stub(window.document, 'getElementById').returns({ From b977714b422ba430115823479ac8a1ac2357f99e Mon Sep 17 00:00:00 2001 From: Amanda Dillon Date: Mon, 4 Jan 2021 17:08:11 -0700 Subject: [PATCH 2/2] SpotX bid adapter: reorder tests and remove extra assertions --- test/spec/modules/spotxBidAdapter_spec.js | 76 +++++++++-------------- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/test/spec/modules/spotxBidAdapter_spec.js b/test/spec/modules/spotxBidAdapter_spec.js index ebb51e87e60..16fe8cb7534 100644 --- a/test/spec/modules/spotxBidAdapter_spec.js +++ b/test/spec/modules/spotxBidAdapter_spec.js @@ -542,11 +542,10 @@ describe('the spotx adapter', function () { }; }); - it('should adjust width and height to slot\'s clientWidth if playersize_auto_adapt is used', function() { + it('should attempt to insert the EASI script', function() { var scriptTag; sinon.stub(window.document, 'getElementById').returns({ - clientWidth: 200, - appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script; }) }); var responses = spec.interpretResponse(serverResponse, bidderRequestObj); @@ -562,21 +561,25 @@ describe('the spotx adapter', function () { expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); - expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('400'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('300'); expect(scriptTag.getAttribute('data-spotx_ad_mute')).to.equal('1'); window.document.getElementById.restore(); }); - it('should use a default 4/3 ratio if playersize_auto_adapt is used and response does not contain width or height', function() { - delete serverResponse.body.seatbid[0].bid[0].w; - delete serverResponse.body.seatbid[0].bid[0].h; - + it('should append into an iframe', function() { var scriptTag; sinon.stub(window.document, 'getElementById').returns({ - clientWidth: 200, - appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) + nodeName: 'IFRAME', + contentDocument: { + body: { + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script; }) + } + } }); + + bidderRequestObj.bidRequest.bids[0].params.outstream_options.in_iframe = 'iframeId'; + var responses = spec.interpretResponse(serverResponse, bidderRequestObj); responses[0].renderer.render(responses[0]); @@ -591,16 +594,16 @@ describe('the spotx adapter', function () { expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); - expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); - expect(scriptTag.getAttribute('data-spotx_ad_mute')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('400'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('300'); window.document.getElementById.restore(); }); - it('should attempt to insert the EASI script', function() { + it('should adjust width and height to match slot clientWidth if playersize_auto_adapt is used', function() { var scriptTag; sinon.stub(window.document, 'getElementById').returns({ - appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) + clientWidth: 200, + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script; }) }); var responses = spec.interpretResponse(serverResponse, bidderRequestObj); @@ -608,49 +611,28 @@ describe('the spotx adapter', function () { expect(scriptTag.getAttribute('type')).to.equal('text/javascript'); expect(scriptTag.getAttribute('src')).to.equal('https://js.spotx.tv/easi/v1/12345.js'); - expect(scriptTag.getAttribute('data-spotx_channel_id')).to.equal('12345'); - expect(scriptTag.getAttribute('data-spotx_vast_url')).to.equal('https://search.spotxchange.com/ad/vast.html?key=cache123'); - expect(scriptTag.getAttribute('data-spotx_ad_unit')).to.equal('incontent'); - expect(scriptTag.getAttribute('data-spotx_collapse')).to.equal('0'); - expect(scriptTag.getAttribute('data-spotx_autoplay')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('400'); - expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('300'); - expect(scriptTag.getAttribute('data-spotx_ad_mute')).to.equal('1'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); window.document.getElementById.restore(); }); - it('should append into an iframe', function() { + it('should use a default 4/3 ratio if playersize_auto_adapt is used and response does not contain width or height', function() { + delete serverResponse.body.seatbid[0].bid[0].w; + delete serverResponse.body.seatbid[0].bid[0].h; + var scriptTag; sinon.stub(window.document, 'getElementById').returns({ - nodeName: 'IFRAME', - contentDocument: { - body: { - appendChild: sinon.stub().callsFake(function(script) { scriptTag = script }) - } - } + clientWidth: 200, + appendChild: sinon.stub().callsFake(function(script) { scriptTag = script; }) }); - - bidderRequestObj.bidRequest.bids[0].params.outstream_options.in_iframe = 'iframeId'; - var responses = spec.interpretResponse(serverResponse, bidderRequestObj); responses[0].renderer.render(responses[0]); expect(scriptTag.getAttribute('type')).to.equal('text/javascript'); expect(scriptTag.getAttribute('src')).to.equal('https://js.spotx.tv/easi/v1/12345.js'); - expect(scriptTag.getAttribute('data-spotx_channel_id')).to.equal('12345'); - expect(scriptTag.getAttribute('data-spotx_vast_url')).to.equal('https://search.spotxchange.com/ad/vast.html?key=cache123'); - expect(scriptTag.getAttribute('data-spotx_ad_unit')).to.equal('incontent'); - expect(scriptTag.getAttribute('data-spotx_collapse')).to.equal('0'); - expect(scriptTag.getAttribute('data-spotx_autoplay')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_blocked_autoplay_override_mode')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_video_slot_can_autoplay')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_digitrust_opt_out')).to.equal('1'); - expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('400'); - expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('300'); + expect(scriptTag.getAttribute('data-spotx_content_width')).to.equal('200'); + expect(scriptTag.getAttribute('data-spotx_content_height')).to.equal('150'); window.document.getElementById.restore(); }); });