prebid-universal-creative 1.14.2 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +1 -2
- package/.github/workflows/issue_tracker.yml +0 -1
- package/README.md +19 -3
- package/dist/amp.js +3 -0
- package/dist/banner.js +3 -0
- package/dist/creative.js +4 -3
- package/dist/creative.max.js +537 -585
- package/dist/load-cookie-with-consent.html +1 -1
- package/dist/load-cookie.html +1 -1
- package/dist/mobile.js +3 -0
- package/dist/native-render.js +3 -3
- package/dist/native-trk.js +3 -3
- package/dist/native.js +3 -0
- package/dist/uid.js +3 -3
- package/dist/video.js +3 -0
- package/gulpfile.js +84 -41
- package/package.json +80 -82
- package/src/ampOrMobile.js +14 -0
- package/src/creative.js +2 -9
- package/src/environment.js +62 -75
- package/src/legacy.js +29 -0
- package/src/legacyNativeRender.js +6 -0
- package/src/mobileAndAmpRender.js +239 -0
- package/src/nativeAssetManager.js +7 -8
- package/src/nativeRender.js +2 -2
- package/src/nativeRenderManager.js +5 -5
- package/src/postscribeRender.js +8 -0
- package/src/renderingManager.js +102 -359
- package/src/utils.js +1 -2
- package/template/amp/dfp-creative.html +1 -1
- package/test/spec/environment_spec.js +4 -11
- package/test/spec/legacyNativeRender_spec.js +25 -0
- package/test/spec/mobileAndAmpRender_spec.js +308 -0
- package/test/spec/nativeAssetManager_spec.js +1 -0
- package/test/spec/nativeRenderManager_spec.js +12 -11
- package/test/spec/nativeRender_spec.js +23 -0
- package/test/spec/renderingManager_spec.js +16 -265
- package/webpack.conf.js +3 -1
package/src/renderingManager.js
CHANGED
@@ -1,385 +1,128 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import {
|
1
|
+
import { parseUrl, transformAuctionTargetingData } from './utils';
|
2
|
+
import { canLocatePrebid } from './environment';
|
3
|
+
import { insertElement, getEmptyIframe } from './domHelper';
|
4
4
|
import {prebidMessenger} from './messaging.js';
|
5
5
|
|
6
|
-
|
7
|
-
const
|
6
|
+
export function renderBannerOrDisplayAd(doc, dataObject) {
|
7
|
+
const targetingData = transformAuctionTargetingData(dataObject);
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
* @returns {Object}
|
14
|
-
*/
|
15
|
-
export function newRenderingManager(win, environment) {
|
16
|
-
/**
|
17
|
-
* DataObject passed to render the ad
|
18
|
-
* @typedef {Object} dataObject
|
19
|
-
* @property {string} host - Prebid cache host
|
20
|
-
* @property {string} uuid - ID to fetch the value from prebid cache
|
21
|
-
* @property {string} mediaType - Creative media type, It can be banner, native or video
|
22
|
-
* @property {string} pubUrl - Publisher url
|
23
|
-
* @property {string} winurl
|
24
|
-
* @property {string} winbidid
|
25
|
-
*/
|
26
|
-
|
27
|
-
/**
|
28
|
-
* Public render ad function to be used in dfp creative setup
|
29
|
-
* @param {object} doc
|
30
|
-
* @param {dataObject} dataObject
|
31
|
-
*/
|
32
|
-
let renderAd = function(doc, dataObject) {
|
33
|
-
const targetingData = utils.transformAuctionTargetingData(dataObject);
|
34
|
-
|
35
|
-
if (environment.isMobileApp(targetingData.env)) {
|
36
|
-
renderAmpOrMobileAd(targetingData.cacheHost, targetingData.cachePath, targetingData.uuid, targetingData.size, targetingData.hbPb, true);
|
37
|
-
} else if (environment.isAmp(targetingData.uuid)) {
|
38
|
-
renderAmpOrMobileAd(targetingData.cacheHost, targetingData.cachePath, targetingData.uuid, targetingData.size, targetingData.hbPb);
|
39
|
-
} else if (!environment.canLocatePrebid()) {
|
40
|
-
renderCrossDomain(targetingData.adId, targetingData.adServerDomain, targetingData.pubUrl);
|
41
|
-
} else {
|
42
|
-
renderLegacy(doc, targetingData.adId);
|
43
|
-
}
|
44
|
-
};
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Calls prebid.js renderAd function to render ad
|
48
|
-
* @param {Object} doc Document
|
49
|
-
* @param {string} adId Id of creative to render
|
50
|
-
*/
|
51
|
-
function renderLegacy(doc, adId) {
|
52
|
-
let w = win;
|
53
|
-
for (let i = 0; i < 10; i++) {
|
54
|
-
w = w.parent;
|
55
|
-
if (w.$$PREBID_GLOBAL$$) {
|
56
|
-
try {
|
57
|
-
w.$$PREBID_GLOBAL$$.renderAd(doc, adId);
|
58
|
-
break;
|
59
|
-
} catch (e) {
|
60
|
-
continue;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
9
|
+
if (!canLocatePrebid(window)) {
|
10
|
+
renderCrossDomain(window, targetingData.adId, targetingData.adServerDomain, targetingData.pubUrl);
|
11
|
+
} else {
|
12
|
+
renderLegacy(doc, targetingData.adId);
|
64
13
|
}
|
14
|
+
}
|
65
15
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
const sendMessage = prebidMessenger(pubUrl, win);
|
77
|
-
|
78
|
-
function renderAd(ev) {
|
79
|
-
let key = ev.message ? 'message' : 'data';
|
80
|
-
let adObject = {};
|
16
|
+
/**
|
17
|
+
* Calls prebid.js renderAd function to render ad
|
18
|
+
* @param {Object} doc Document
|
19
|
+
* @param {string} adId Id of creative to render
|
20
|
+
*/
|
21
|
+
export function renderLegacy(doc, adId) {
|
22
|
+
let w = window;
|
23
|
+
for (let i = 0; i < 10; i++) {
|
24
|
+
w = w.parent;
|
25
|
+
if (w.$$PREBID_GLOBAL$$) {
|
81
26
|
try {
|
82
|
-
|
27
|
+
w.$$PREBID_GLOBAL$$.renderAd(doc, adId);
|
28
|
+
break;
|
83
29
|
} catch (e) {
|
84
|
-
|
30
|
+
continue;
|
85
31
|
}
|
86
|
-
|
87
|
-
if (adObject.message && adObject.message === 'Prebid Response' &&
|
88
|
-
adObject.adId === adId) {
|
89
|
-
try {
|
90
|
-
let body = win.document.body;
|
91
|
-
let ad = adObject.ad;
|
92
|
-
let url = adObject.adUrl;
|
93
|
-
let width = adObject.width;
|
94
|
-
let height = adObject.height;
|
95
|
-
|
96
|
-
if (adObject.mediaType === 'video') {
|
97
|
-
signalRenderResult(false, {
|
98
|
-
reason: 'preventWritingOnMainDocument',
|
99
|
-
message: `Cannot render video ad ${adId}`
|
100
|
-
});
|
101
|
-
console.log('Error trying to write ad.');
|
102
|
-
} else if (ad) {
|
103
|
-
const iframe = domHelper.getEmptyIframe(adObject.height, adObject.width);
|
104
|
-
body.appendChild(iframe);
|
105
|
-
iframe.contentDocument.open();
|
106
|
-
iframe.contentDocument.write(ad);
|
107
|
-
iframe.contentDocument.close();
|
108
|
-
signalRenderResult(true);
|
109
|
-
} else if (url) {
|
110
|
-
const iframe = domHelper.getEmptyIframe(height, width);
|
111
|
-
iframe.style.display = 'inline';
|
112
|
-
iframe.style.overflow = 'hidden';
|
113
|
-
iframe.src = url;
|
114
|
-
|
115
|
-
domHelper.insertElement(iframe, document, 'body');
|
116
|
-
signalRenderResult(true);
|
117
|
-
} else {
|
118
|
-
signalRenderResult(false, {
|
119
|
-
reason: 'noAd',
|
120
|
-
message: `No ad for ${adId}`
|
121
|
-
});
|
122
|
-
console.log(`Error trying to write ad. No ad markup or adUrl for ${adId}`);
|
123
|
-
}
|
124
|
-
} catch (e) {
|
125
|
-
signalRenderResult(false, {reason: "exception", message: e.message});
|
126
|
-
console.log(`Error in rendering ad`, e);
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
function signalRenderResult(success, {reason, message} = {}) {
|
131
|
-
const payload = {
|
132
|
-
message: 'Prebid Event',
|
133
|
-
adId,
|
134
|
-
event: success ? 'adRenderSucceeded' : 'adRenderFailed',
|
135
|
-
}
|
136
|
-
if (!success) {
|
137
|
-
payload.info = {reason, message};
|
138
|
-
}
|
139
|
-
sendMessage(payload);
|
140
|
-
}
|
141
|
-
}
|
142
|
-
|
143
|
-
|
144
|
-
function requestAdFromPrebid() {
|
145
|
-
let message = {
|
146
|
-
message: 'Prebid Request',
|
147
|
-
adId: adId,
|
148
|
-
adServerDomain: fullAdServerDomain
|
149
|
-
}
|
150
|
-
sendMessage(message, renderAd);
|
151
|
-
}
|
152
|
-
|
153
|
-
requestAdFromPrebid();
|
154
|
-
}
|
155
|
-
|
156
|
-
/**
|
157
|
-
* Returns cache endpoint concatenated with cache path
|
158
|
-
* @param {string} cacheHost Cache Endpoint host
|
159
|
-
* @param {string} cachePath Cache Endpoint path
|
160
|
-
*/
|
161
|
-
function getCacheEndpoint(cacheHost, cachePath) {
|
162
|
-
let host = (typeof cacheHost === 'undefined' || cacheHost === "") ? DEFAULT_CACHE_HOST : cacheHost;
|
163
|
-
let path = (typeof cachePath === 'undefined' || cachePath === "") ? DEFAULT_CACHE_PATH : cachePath;
|
164
|
-
|
165
|
-
return `https://${host}${path}`;
|
166
|
-
}
|
167
|
-
|
168
|
-
/**
|
169
|
-
* update iframe by using size string to resize
|
170
|
-
* @param {string} size
|
171
|
-
*/
|
172
|
-
function updateIframe(size) {
|
173
|
-
if (size) {
|
174
|
-
const sizeArr = size.split('x').map(Number);
|
175
|
-
resizeIframe(sizeArr[0], sizeArr[1]);
|
176
|
-
} else {
|
177
|
-
console.log('Targeting key hb_size not found to resize creative');
|
178
32
|
}
|
179
33
|
}
|
34
|
+
}
|
180
35
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
updateIframe(size);
|
201
|
-
utils.sendRequest(adUrl, responseCallback(isMobileApp, hbPb));
|
36
|
+
/**
|
37
|
+
* Render ad in safeframe using postmessage
|
38
|
+
* @param {string} adId Id of creative to render
|
39
|
+
* @param {string} pubAdServerDomain publisher adserver domain name
|
40
|
+
* @param {string} pubUrl Url of publisher page
|
41
|
+
*/
|
42
|
+
export function renderCrossDomain(win, adId, pubAdServerDomain = '', pubUrl) {
|
43
|
+
let windowLocation = win.location;
|
44
|
+
let adServerDomain = pubAdServerDomain || win.location.hostname;
|
45
|
+
let fullAdServerDomain = windowLocation.protocol + '//' + adServerDomain;
|
46
|
+
const sendMessage = prebidMessenger(pubUrl, win);
|
47
|
+
|
48
|
+
function renderAd(ev) {
|
49
|
+
let key = ev.message ? "message" : "data";
|
50
|
+
let adObject = {};
|
51
|
+
try {
|
52
|
+
adObject = JSON.parse(ev[key]);
|
53
|
+
} catch (e) {
|
54
|
+
return;
|
202
55
|
}
|
203
|
-
}
|
204
|
-
|
205
|
-
/**
|
206
|
-
* Cache request Callback to display creative
|
207
|
-
* @param {Bool} isMobileApp
|
208
|
-
* @param {string} hbPb final price of the winning bid
|
209
|
-
* @returns {function} a callback function that parses response
|
210
|
-
*/
|
211
|
-
function responseCallback(isMobileApp, hbPb) {
|
212
|
-
return function(response) {
|
213
|
-
let bidObject = parseResponse(response);
|
214
|
-
let auctionPrice = bidObject.price || hbPb;
|
215
|
-
let ad = utils.getCreativeCommentMarkup(bidObject);
|
216
|
-
let width = (bidObject.width) ? bidObject.width : bidObject.w;
|
217
|
-
let height = (bidObject.height) ? bidObject.height : bidObject.h;
|
218
56
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
if (
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
}
|
253
|
-
utils.writeAdHtml(ad);
|
254
|
-
} else if (bidObject.nurl) {
|
255
|
-
if(isMobileApp) {
|
256
|
-
let adhtml = utils.loadScript(win, bidObject.nurl);
|
257
|
-
ad += constructMarkup(adhtml.outerHTML, width, height);
|
258
|
-
utils.writeAdHtml(ad);
|
57
|
+
if (
|
58
|
+
adObject.message &&
|
59
|
+
adObject.message === "Prebid Response" &&
|
60
|
+
adObject.adId === adId
|
61
|
+
) {
|
62
|
+
try {
|
63
|
+
let body = win.document.body;
|
64
|
+
let ad = adObject.ad;
|
65
|
+
let url = adObject.adUrl;
|
66
|
+
let width = adObject.width;
|
67
|
+
let height = adObject.height;
|
68
|
+
|
69
|
+
if (adObject.mediaType === "video") {
|
70
|
+
signalRenderResult(false, {
|
71
|
+
reason: "preventWritingOnMainDocument",
|
72
|
+
message: `Cannot render video ad ${adId}`,
|
73
|
+
});
|
74
|
+
console.log("Error trying to write ad.");
|
75
|
+
} else if (ad) {
|
76
|
+
const iframe = getEmptyIframe(adObject.height, adObject.width);
|
77
|
+
body.appendChild(iframe);
|
78
|
+
iframe.contentDocument.open();
|
79
|
+
iframe.contentDocument.write(ad);
|
80
|
+
iframe.contentDocument.close();
|
81
|
+
signalRenderResult(true);
|
82
|
+
} else if (url) {
|
83
|
+
const iframe = getEmptyIframe(height, width);
|
84
|
+
iframe.style.display = "inline";
|
85
|
+
iframe.style.overflow = "hidden";
|
86
|
+
iframe.src = url;
|
87
|
+
|
88
|
+
insertElement(iframe, document, "body");
|
89
|
+
signalRenderResult(true);
|
259
90
|
} else {
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
91
|
+
signalRenderResult(false, {
|
92
|
+
reason: "noAd",
|
93
|
+
message: `No ad for ${adId}`,
|
94
|
+
});
|
95
|
+
console.log(
|
96
|
+
`Error trying to write ad. No ad markup or adUrl for ${adId}`
|
97
|
+
);
|
264
98
|
}
|
99
|
+
} catch (e) {
|
100
|
+
signalRenderResult(false, { reason: "exception", message: e.message });
|
101
|
+
console.log(`Error in rendering ad`, e);
|
265
102
|
}
|
266
103
|
}
|
267
|
-
};
|
268
|
-
|
269
|
-
/**
|
270
|
-
* Load response from localStorage. In case of MoPub, sdk caches response
|
271
|
-
* @param {string} cacheId
|
272
|
-
*/
|
273
|
-
function loadFromLocalCache(cacheId) {
|
274
|
-
let bid = win.localStorage.getItem(cacheId);
|
275
|
-
let displayFn = responseCallback(true);
|
276
|
-
displayFn(bid);
|
277
|
-
}
|
278
|
-
|
279
|
-
/**
|
280
|
-
* Parse response
|
281
|
-
* @param {string} response
|
282
|
-
* @returns {Object} bidObject parsed response
|
283
|
-
*/
|
284
|
-
function parseResponse(response) {
|
285
|
-
let bidObject;
|
286
|
-
try {
|
287
|
-
bidObject = JSON.parse(response);
|
288
|
-
} catch (error) {
|
289
|
-
console.log(`Error parsing response from cache host: ${error}`);
|
290
|
-
}
|
291
|
-
return bidObject;
|
292
|
-
}
|
293
|
-
|
294
|
-
/**
|
295
|
-
* Wrap mobile app creative in div
|
296
|
-
* @param {string} ad html for creative
|
297
|
-
* @param {Number} width width of creative
|
298
|
-
* @param {Number} height height of creative
|
299
|
-
* @returns {string} creative markup
|
300
|
-
*/
|
301
|
-
function constructMarkup(ad, width, height) {
|
302
|
-
let id = utils.getUUID();
|
303
|
-
return `<div id="${id}" style="border-style: none; position: absolute; width:100%; height:100%;">
|
304
|
-
<div id="${id}_inner" style="margin: 0 auto; width:${width}px; height:${height}px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">${ad}</div>
|
305
|
-
</div>`;
|
306
|
-
}
|
307
|
-
|
308
|
-
/**
|
309
|
-
* Resize container iframe
|
310
|
-
* @param {Number} width width of creative
|
311
|
-
* @param {Number} height height of creative
|
312
|
-
*/
|
313
|
-
function resizeIframe(width, height) {
|
314
|
-
if (environment.isSafeFrame()) {
|
315
|
-
const iframeWidth = win.innerWidth;
|
316
|
-
const iframeHeight = win.innerHeight;
|
317
104
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
if (
|
325
|
-
|
326
|
-
// we need to resize the DFP container as well
|
327
|
-
win.parent.postMessage({
|
328
|
-
sentinel: 'amp',
|
329
|
-
type: 'embed-size',
|
330
|
-
width: width,
|
331
|
-
height: height
|
332
|
-
}, '*');
|
105
|
+
function signalRenderResult(success, { reason, message } = {}) {
|
106
|
+
const payload = {
|
107
|
+
message: "Prebid Event",
|
108
|
+
adId,
|
109
|
+
event: success ? "adRenderSucceeded" : "adRenderFailed",
|
110
|
+
};
|
111
|
+
if (!success) {
|
112
|
+
payload.info = { reason, message };
|
333
113
|
}
|
114
|
+
sendMessage(payload);
|
334
115
|
}
|
335
116
|
}
|
336
117
|
|
337
|
-
function
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
callback();
|
343
|
-
}
|
344
|
-
}
|
345
|
-
|
346
|
-
function viewableChangeListener(viewable) {
|
347
|
-
if (viewable) {
|
348
|
-
mraid.removeEventListener('viewableChange', viewableChangeListener);
|
349
|
-
callback();
|
350
|
-
}
|
351
|
-
}
|
352
|
-
|
353
|
-
function registerViewableChecks() {
|
354
|
-
if (win.MRAID_ENV && parseFloat(win.MRAID_ENV.version) >= 3) {
|
355
|
-
mraid.addEventListener('exposureChange', exposureChangeListener);
|
356
|
-
} else if(win.MRAID_ENV && parseFloat(win.MRAID_ENV.version) < 3) {
|
357
|
-
if (mraid.isViewable()) {
|
358
|
-
callback();
|
359
|
-
} else {
|
360
|
-
mraid.addEventListener('viewableChange', viewableChangeListener);
|
361
|
-
}
|
362
|
-
}
|
363
|
-
}
|
364
|
-
|
365
|
-
function readyListener() {
|
366
|
-
mraid.removeEventListener('ready', readyListener);
|
367
|
-
registerViewableChecks();
|
368
|
-
}
|
369
|
-
|
370
|
-
if (win.mraid && win.MRAID_ENV) {
|
371
|
-
if (mraid.getState() == 'loading') {
|
372
|
-
mraid.addEventListener('ready', readyListener);
|
373
|
-
} else {
|
374
|
-
registerViewableChecks();
|
375
|
-
}
|
376
|
-
return true;
|
377
|
-
} else {
|
378
|
-
return false;
|
118
|
+
function requestAdFromPrebid() {
|
119
|
+
let message = {
|
120
|
+
message: 'Prebid Request',
|
121
|
+
adId: adId,
|
122
|
+
adServerDomain: fullAdServerDomain
|
379
123
|
}
|
124
|
+
sendMessage(message, renderAd);
|
380
125
|
}
|
381
126
|
|
382
|
-
|
383
|
-
renderAd
|
384
|
-
}
|
127
|
+
requestAdFromPrebid();
|
385
128
|
}
|
package/src/utils.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
const postscribe = require('postscribe');
|
2
1
|
import * as domHelper from './domHelper';
|
3
2
|
|
4
3
|
/**
|
@@ -115,7 +114,7 @@ export function getCreativeComment(bid) {
|
|
115
114
|
* @param {*} bid
|
116
115
|
*/
|
117
116
|
export function getCreativeCommentMarkup(bid) {
|
118
|
-
let creativeComment =
|
117
|
+
let creativeComment = getCreativeComment(bid);
|
119
118
|
let wrapper = document.createElement('div');
|
120
119
|
wrapper.appendChild(creativeComment);
|
121
120
|
return wrapper.innerHTML;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<script src = "https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist
|
1
|
+
<script src = "https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/%%PATTERN::hb_format%%.js"></script>
|
2
2
|
<script>
|
3
3
|
var ucTagData = {};
|
4
4
|
ucTagData.adServerDomain = "";
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { expect } from 'chai';
|
2
|
-
import
|
2
|
+
import * as env from 'src/environment';
|
3
3
|
import { mocks } from 'test/helpers/mocks';
|
4
4
|
import { merge } from 'lodash';
|
5
5
|
|
@@ -16,8 +16,6 @@ const envMocks = {
|
|
16
16
|
describe('environment module', function() {
|
17
17
|
|
18
18
|
it('should return env object with proper public api', function() {
|
19
|
-
const mockWin = merge(mocks.createFakeWindow('http://appnexus.com'), envMocks.getWindowObject());
|
20
|
-
const env = newEnvironment(mockWin);
|
21
19
|
expect(env.isMobileApp).to.exist;
|
22
20
|
expect(env.isCrossDomain).to.exist;
|
23
21
|
expect(env.isSafeFrame).to.exist;
|
@@ -26,8 +24,7 @@ describe('environment module', function() {
|
|
26
24
|
|
27
25
|
it('should detect safeframe', function() {
|
28
26
|
const mockWin = merge(mocks.createFakeWindow('http://appnexus.com'), envMocks.getWindowObject());
|
29
|
-
|
30
|
-
expect(env.isSafeFrame()).to.equal(true);
|
27
|
+
expect(env.isSafeFrame(mockWin)).to.equal(true);
|
31
28
|
});
|
32
29
|
|
33
30
|
it('should detect amp', function() {
|
@@ -39,8 +36,7 @@ describe('environment module', function() {
|
|
39
36
|
}
|
40
37
|
}
|
41
38
|
const mockWin = merge(mocks.createFakeWindow('http://appnexus.com'), envMocks.getWindowObject(), localWindow);
|
42
|
-
|
43
|
-
expect(env.isAmp('some-uuid')).to.equal(true);
|
39
|
+
expect(env.isAmp('some-uuid', mockWin)).to.equal(true);
|
44
40
|
});
|
45
41
|
|
46
42
|
it('should detect Prebid in higher window', function() {
|
@@ -54,13 +50,10 @@ describe('environment module', function() {
|
|
54
50
|
}
|
55
51
|
};
|
56
52
|
const mockWin = merge(mocks.createFakeWindow('http://appnexus.com'), envMocks.getWindowObject(), localWindow);
|
57
|
-
|
58
|
-
expect(env.canLocatePrebid()).to.equal(true);
|
53
|
+
expect(env.canLocatePrebid(mockWin)).to.equal(true);
|
59
54
|
});
|
60
55
|
|
61
56
|
it('should detect mobile app', function() {
|
62
|
-
const mockWin = merge(mocks.createFakeWindow('http://appnexus.com'), envMocks.getWindowObject());
|
63
|
-
const env = newEnvironment(mockWin);
|
64
57
|
expect(env.isMobileApp('mobile-app')).to.equal(true);
|
65
58
|
});
|
66
59
|
});
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import '../../src/legacyNativeRender';
|
2
|
+
|
3
|
+
describe('legacyNativeRender', () => {
|
4
|
+
|
5
|
+
after(() => {
|
6
|
+
delete window.pbNativeTag;
|
7
|
+
window.nativeRenderManager.renderNativeAd.reset();
|
8
|
+
})
|
9
|
+
it('should accept only one argument', () => {
|
10
|
+
|
11
|
+
expect(window.pbNativeTag.renderNativeAd).to.exist;
|
12
|
+
//expect exactly one argument by this function
|
13
|
+
expect(window.pbNativeTag.renderNativeAd.length).to.equal(1);
|
14
|
+
|
15
|
+
const args = {
|
16
|
+
pubUrl: 'http://prebidjs.com',
|
17
|
+
adId: 'abc123'
|
18
|
+
};
|
19
|
+
window.nativeRenderManager.renderNativeAd = sinon.stub();
|
20
|
+
|
21
|
+
window.pbNativeTag.renderNativeAd(args);
|
22
|
+
expect(nativeRenderManager.renderNativeAd.calledOnceWith(document, args)).to.be.true;
|
23
|
+
|
24
|
+
})
|
25
|
+
})
|