Skip to content

Commit

Permalink
Fix getTopWindowUrl (prebid#2673)
Browse files Browse the repository at this point in the history
* Fix getTopWindowUrl

getTopWindowUrl error, it should be exports.function not this.function

* Update utils.js

Fix to pass FB test

* Update audienceNetworkBidAdapter_spec.js

* Update utils.js

* Update utils.js

* Update utils.js
  • Loading branch information
Antoine Jacquemin (Rubicon) authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 7877d68 commit d270e9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
45 changes: 22 additions & 23 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ try {
* console.log(replaceTokenInString(str, map, '%%')); => "text it was subbed this text with something else"
*/
exports.replaceTokenInString = function (str, map, token) {
this._each(map, function (value, key) {
exports._each(map, function (value, key) {
value = (value === undefined) ? '' : value;

var keyString = token + key.toUpperCase() + token;
Expand Down Expand Up @@ -242,11 +242,10 @@ exports.getWindowLocation = function () {
exports.getTopWindowUrl = function () {
let href;
try {
href = this.getTopWindowLocation().href;
href = exports.getTopWindowLocation().href;
} catch (e) {
href = '';
}

return href;
};

Expand Down Expand Up @@ -366,10 +365,10 @@ exports.hasValidBidRequest = function (paramObj, requiredParamsArr, adapter) {
for (var i = 0; i < requiredParamsArr.length; i++) {
found = false;

this._each(paramObj, findParam);
exports._each(paramObj, findParam);

if (!found) {
this.logError('Params are missing for bid request. One of these required paramaters are missing: ' + requiredParamsArr, adapter);
exports.logError('Params are missing for bid request. One of these required paramaters are missing: ' + requiredParamsArr, adapter);
return false;
}
}
Expand Down Expand Up @@ -397,23 +396,23 @@ exports.isA = function (object, _t) {
};

exports.isFn = function (object) {
return this.isA(object, t_Fn);
return exports.isA(object, t_Fn);
};

exports.isStr = function (object) {
return this.isA(object, t_Str);
return exports.isA(object, t_Str);
};

exports.isArray = function (object) {
return this.isA(object, t_Arr);
return exports.isA(object, t_Arr);
};

exports.isNumber = function(object) {
return this.isA(object, t_Numb);
return exports.isA(object, t_Numb);
};

exports.isPlainObject = function(object) {
return this.isA(object, t_Object);
return exports.isA(object, t_Object);
}

/**
Expand Down Expand Up @@ -441,7 +440,7 @@ exports.isEmpty = function (object) {
* @returns {boolean} if string is empty
*/
exports.isEmptyStr = function(str) {
return this.isStr(str) && (!str || str.length === 0);
return exports.isStr(str) && (!str || str.length === 0);
};

/**
Expand All @@ -451,8 +450,8 @@ exports.isEmptyStr = function(str) {
* @param {Function(value, key, object)} fn
*/
exports._each = function (object, fn) {
if (this.isEmpty(object)) return;
if (this.isFn(object.forEach)) return object.forEach(fn, this);
if (exports.isEmpty(object)) return;
if (exports.isFn(object.forEach)) return object.forEach(fn, this);

var k = 0;
var l = object.length;
Expand All @@ -467,11 +466,11 @@ exports._each = function (object, fn) {
};

exports.contains = function (a, obj) {
if (this.isEmpty(a)) {
if (exports.isEmpty(a)) {
return false;
}

if (this.isFn(a.indexOf)) {
if (exports.isFn(a.indexOf)) {
return a.indexOf(obj) !== -1;
}

Expand Down Expand Up @@ -502,10 +501,10 @@ exports.indexOf = (function () {
* @return {Array}
*/
exports._map = function (object, callback) {
if (this.isEmpty(object)) return [];
if (this.isFn(object.map)) return object.map(callback);
if (exports.isEmpty(object)) return [];
if (exports.isFn(object.map)) return object.map(callback);
var output = [];
this._each(object, function (value, key) {
exports._each(object, function (value, key) {
output.push(callback(value, key, object));
});

Expand Down Expand Up @@ -586,7 +585,7 @@ exports.insertHtmlIntoIframe = function(htmlCode) {
* @param {string} encodeUri boolean if URL should be encoded before inserted. Defaults to true
*/
exports.insertUserSyncIframe = function(url) {
let iframeHtml = this.createTrackPixelIframeHtml(url, false, 'allow-scripts allow-same-origin');
let iframeHtml = exports.createTrackPixelIframeHtml(url, false, 'allow-scripts allow-same-origin');
let div = document.createElement('div');
div.innerHTML = iframeHtml;
let iframe = div.firstChild;
Expand Down Expand Up @@ -658,7 +657,7 @@ exports.getIframeDocument = function (iframe) {
doc = iframe.contentDocument;
}
} catch (e) {
this.logError('Cannot get iframe document', e);
exports.logError('Cannot get iframe document', e);
}

return doc;
Expand All @@ -668,13 +667,13 @@ exports.getValueString = function(param, val, defaultValue) {
if (val === undefined || val === null) {
return defaultValue;
}
if (this.isStr(val)) {
if (exports.isStr(val)) {
return val;
}
if (this.isNumber(val)) {
if (exports.isNumber(val)) {
return val.toString();
}
this.logWarn('Unsuported type for param: ' + param + ' required type: String');
exports.logWarn('Unsuported type for param: ' + param + ' required type: String');
};

export function uniques(value, index, arry) {
Expand Down
12 changes: 6 additions & 6 deletions test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['300x250'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: `placementids[]=test-placement-id&adformats[]=300x250&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
data: `placementids[]=test-placement-id&adformats[]=300x250&testmode=false&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

Expand All @@ -158,7 +158,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['640x480'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: `placementids[]=test-placement-id&adformats[]=video&testmode=false&pageurl=&sdk[]=&pbv=${pbv}&playerwidth=640&playerheight=480`
data: `placementids[]=test-placement-id&adformats[]=video&testmode=false&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&sdk[]=&pbv=${pbv}&playerwidth=640&playerheight=480`
}]);
});

Expand All @@ -177,7 +177,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['728x90'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: `placementids[]=test-placement-id&adformats[]=native&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
data: `placementids[]=test-placement-id&adformats[]=native&testmode=false&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

Expand All @@ -196,7 +196,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['300x250'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: `placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
data: `placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

Expand Down Expand Up @@ -410,7 +410,7 @@ describe('AudienceNetwork adapter', () => {
expect(bidResponse.cpm).to.equal(1.23);
expect(bidResponse.requestId).to.equal(requestId);
expect(bidResponse.mediaType).to.equal('video');
expect(bidResponse.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${placementId}&pageurl=&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${bidId}`);
expect(bidResponse.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${placementId}&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${bidId}`);
expect(bidResponse.width).to.equal(playerwidth);
expect(bidResponse.height).to.equal(playerheight);
});
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('AudienceNetwork adapter', () => {
expect(bidResponseVideo.cpm).to.equal(1.23);
expect(bidResponseVideo.requestId).to.equal(requestId);
expect(bidResponseVideo.mediaType).to.equal('video');
expect(bidResponseVideo.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${videoPlacementId}&pageurl=&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${videoBidId}`);
expect(bidResponseVideo.vastUrl).to.equal(`https://an.facebook.com/v1/instream/vast.xml?placementid=${videoPlacementId}&pageurl=http%3A%2F%2Flocalhost%3A9876%2F&playerwidth=${playerwidth}&playerheight=${playerheight}&bidid=${videoBidId}`);
expect(bidResponseVideo.width).to.equal(playerwidth);
expect(bidResponseVideo.height).to.equal(playerheight);

Expand Down

0 comments on commit d270e9c

Please sign in to comment.