Skip to content

Commit

Permalink
[Luis, Carlos] Refactored VASTClient ad validation to be able to chec…
Browse files Browse the repository at this point in the history
…k in an Inline ad is supported
  • Loading branch information
carpasse committed Feb 3, 2016
1 parent 3f056f8 commit 1bd48ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/scripts/ads/vast/InLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ function InLine(inlineJTree) {
}
}


/**
* Returns true if the browser is able to play at least one of the creatives.
*/
InLine.prototype.isSupported = function(){
if(this.creatives.length === 0) {
return false;
}

return true;
};

module.exports = InLine;
6 changes: 4 additions & 2 deletions src/scripts/ads/vast/VASTClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,15 @@ VASTClient.prototype._getVASTAd = function (adTagUrl, callback) {
return new VASTError(errMsgPrefix + "nor wrapper nor inline elements found on the Ad", 101);
}

if (inLine && inLine.creatives.length === 0) {
return new VASTError(errMsgPrefix + "missing creative in InLine element", 101);
if (inLine && !inLine.isSupported()) {
return new VASTError(errMsgPrefix + "could not find MediaFile that is supported by this video player", 403);
}

if (wrapper && !wrapper.VASTAdTagURI) {
return new VASTError(errMsgPrefix + "missing 'VASTAdTagURI' in wrapper", 101);
}

return null;
}

function requestVASTAd(adTagUrl, callback) {
Expand Down
13 changes: 13 additions & 0 deletions test/ads/vast/Inline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,17 @@ describe("InLine", function () {
});
});
});

describe("isSupported", function(){
var inLine;

beforeEach(function(){
inLine = new InLine(xml.toJXONTree(inlineXML));
});

it("must return false if the inLine has no creatives", function(){
inLine.creatives.length = 0;
assert.isFalse(inLine.isSupported());
});
});
});
8 changes: 4 additions & 4 deletions test/ads/vast/VASTClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ describe("VASTClient", function () {
'<VAST version="2.0"><Ad id="secondAd"><InLine></InLine></Ad></VAST>');
this.clock.tick();

assertError(callback, "on VASTClient.getVASTAd.validateAd, missing creative in InLine element", 101);
assertErrorTrack("on VASTClient.getVASTAd.validateAd, missing creative in InLine element", 101, ['firstAd', 'secondAd']);
assertError(callback, "on VASTClient.getVASTAd.validateAd, could not find MediaFile that is supported by this video player", 403);
assertErrorTrack("on VASTClient.getVASTAd.validateAd, could not find MediaFile that is supported by this video player", 403, ['firstAd', 'secondAd']);
});

it("must return a 101 error to the callback and track it if one of the ads in the chain is a wrapper with no VASTAdTagURI", function(){
Expand Down Expand Up @@ -589,8 +589,8 @@ describe("VASTClient", function () {
requests[1].respond(200, {"Content-Type": "text"}, vastXML('<Ad id="adChain2"><InLine><Creatives></Creatives></InLine></Ad>'));
this.clock.tick();

assertError(callback, "on VASTClient.getVASTAd.validateAd, missing creative in InLine element", 101);
assertErrorTrack("on VASTClient.getVASTAd.validateAd, missing creative in InLine element", 101, ['adChain2', 'adChain2']);
assertError(callback, "on VASTClient.getVASTAd.validateAd, could not find MediaFile that is supported by this video player", 403);
assertErrorTrack("on VASTClient.getVASTAd.validateAd, could not find MediaFile that is supported by this video player", 403, ['adChain2', 'adChain2']);
});

it("must not pass an error to the callback if one of the adChains in the VAST waterfall returned a valid ad", function(){
Expand Down

0 comments on commit 1bd48ce

Please sign in to comment.