prebid-universal-creative 1.14.2 → 1.16.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 +31 -16
- package/README.md +21 -3
- package/dist/amp.js +3 -0
- package/dist/banner.js +3 -0
- package/dist/creative.js +4 -3
- package/dist/creative.max.js +546 -593
- 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 -45
- package/karma.conf.maker.js +4 -6
- 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 +91 -57
- package/src/nativeORTBTrackerManager.js +2 -2
- package/src/nativeRender.js +2 -2
- package/src/nativeRenderManager.js +46 -69
- package/src/postscribeRender.js +10 -0
- package/src/renderingManager.js +106 -358
- package/src/utils.js +1 -11
- 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 +316 -0
- package/test/spec/nativeAssetManager_spec.js +227 -79
- package/test/spec/nativeORTBTrackerManager_spec.js +3 -19
- package/test/spec/nativeRenderManager_spec.js +77 -55
- 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,133 @@
|
|
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
|
-
|
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 found = false;
|
23
|
+
let w = window;
|
24
|
+
for (let i = 0; i < 10; i++) {
|
25
|
+
w = w.parent;
|
26
|
+
if (w.$$PREBID_GLOBAL$$) {
|
81
27
|
try {
|
82
|
-
|
28
|
+
found = true;
|
29
|
+
w.$$PREBID_GLOBAL$$.renderAd(doc, adId);
|
30
|
+
break;
|
83
31
|
} catch (e) {
|
84
|
-
|
85
|
-
}
|
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);
|
32
|
+
continue;
|
140
33
|
}
|
141
34
|
}
|
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
35
|
}
|
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
|
-
}
|
36
|
+
if (!found) {
|
37
|
+
console.error("Unable to locate $$PREBID_GLOBAL$$.renderAd function!");
|
179
38
|
}
|
39
|
+
}
|
180
40
|
|
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));
|
41
|
+
/**
|
42
|
+
* Render ad in safeframe using postmessage
|
43
|
+
* @param {string} adId Id of creative to render
|
44
|
+
* @param {string} pubAdServerDomain publisher adserver domain name
|
45
|
+
* @param {string} pubUrl Url of publisher page
|
46
|
+
*/
|
47
|
+
export function renderCrossDomain(win, adId, pubAdServerDomain = '', pubUrl) {
|
48
|
+
let windowLocation = win.location;
|
49
|
+
let adServerDomain = pubAdServerDomain || win.location.hostname;
|
50
|
+
let fullAdServerDomain = windowLocation.protocol + '//' + adServerDomain;
|
51
|
+
const sendMessage = prebidMessenger(pubUrl, win);
|
52
|
+
|
53
|
+
function renderAd(ev) {
|
54
|
+
let key = ev.message ? "message" : "data";
|
55
|
+
let adObject = {};
|
56
|
+
try {
|
57
|
+
adObject = JSON.parse(ev[key]);
|
58
|
+
} catch (e) {
|
59
|
+
return;
|
202
60
|
}
|
203
|
-
}
|
204
61
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
let triggerBurl = function(){ utils.triggerPixel(bidObject.burl); };
|
239
|
-
if(isMobileApp) {
|
240
|
-
let mraidScript = utils.loadScript(win, 'mraid.js',
|
241
|
-
function() { // Success loading MRAID
|
242
|
-
let result = registerMRAIDViewableEvent(triggerBurl);
|
243
|
-
if (!result) {
|
244
|
-
triggerBurl(); // Error registering event
|
245
|
-
}
|
246
|
-
},
|
247
|
-
triggerBurl // Error loading MRAID
|
248
|
-
);
|
249
|
-
} else {
|
250
|
-
triggerBurl(); // Not a mobile app
|
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);
|
62
|
+
if (
|
63
|
+
adObject.message &&
|
64
|
+
adObject.message === "Prebid Response" &&
|
65
|
+
adObject.adId === adId
|
66
|
+
) {
|
67
|
+
try {
|
68
|
+
let body = win.document.body;
|
69
|
+
let ad = adObject.ad;
|
70
|
+
let url = adObject.adUrl;
|
71
|
+
let width = adObject.width;
|
72
|
+
let height = adObject.height;
|
73
|
+
|
74
|
+
if (adObject.mediaType === "video") {
|
75
|
+
signalRenderResult(false, {
|
76
|
+
reason: "preventWritingOnMainDocument",
|
77
|
+
message: `Cannot render video ad ${adId}`,
|
78
|
+
});
|
79
|
+
console.log("Error trying to write ad.");
|
80
|
+
} else if (ad) {
|
81
|
+
const iframe = getEmptyIframe(adObject.height, adObject.width);
|
82
|
+
body.appendChild(iframe);
|
83
|
+
iframe.contentDocument.open();
|
84
|
+
iframe.contentDocument.write(ad);
|
85
|
+
iframe.contentDocument.close();
|
86
|
+
signalRenderResult(true);
|
87
|
+
} else if (url) {
|
88
|
+
const iframe = getEmptyIframe(height, width);
|
89
|
+
iframe.style.display = "inline";
|
90
|
+
iframe.style.overflow = "hidden";
|
91
|
+
iframe.src = url;
|
92
|
+
|
93
|
+
insertElement(iframe, document, "body");
|
94
|
+
signalRenderResult(true);
|
259
95
|
} else {
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
96
|
+
signalRenderResult(false, {
|
97
|
+
reason: "noAd",
|
98
|
+
message: `No ad for ${adId}`,
|
99
|
+
});
|
100
|
+
console.log(
|
101
|
+
`Error trying to write ad. No ad markup or adUrl for ${adId}`
|
102
|
+
);
|
264
103
|
}
|
104
|
+
} catch (e) {
|
105
|
+
signalRenderResult(false, { reason: "exception", message: e.message });
|
106
|
+
console.log(`Error in rendering ad`, e);
|
265
107
|
}
|
266
108
|
}
|
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
109
|
|
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
|
-
}, '*');
|
110
|
+
function signalRenderResult(success, { reason, message } = {}) {
|
111
|
+
const payload = {
|
112
|
+
message: "Prebid Event",
|
113
|
+
adId,
|
114
|
+
event: success ? "adRenderSucceeded" : "adRenderFailed",
|
115
|
+
};
|
116
|
+
if (!success) {
|
117
|
+
payload.info = { reason, message };
|
333
118
|
}
|
119
|
+
sendMessage(payload);
|
334
120
|
}
|
335
121
|
}
|
336
122
|
|
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;
|
123
|
+
function requestAdFromPrebid() {
|
124
|
+
let message = {
|
125
|
+
message: 'Prebid Request',
|
126
|
+
adId: adId,
|
127
|
+
adServerDomain: fullAdServerDomain
|
379
128
|
}
|
129
|
+
sendMessage(message, renderAd);
|
380
130
|
}
|
381
131
|
|
382
|
-
|
383
|
-
renderAd
|
384
|
-
}
|
132
|
+
requestAdFromPrebid();
|
385
133
|
}
|
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
|
/**
|
@@ -31,15 +30,6 @@ export function writeAdUrl(adUrl, width, height) {
|
|
31
30
|
document.body.appendChild(iframe);
|
32
31
|
}
|
33
32
|
|
34
|
-
export function writeAdHtml(markup) {
|
35
|
-
// remove <?xml> and <!doctype> tags
|
36
|
-
// https://github.com/prebid/prebid-universal-creative/issues/134
|
37
|
-
markup = markup.replace(/\<(\?xml|(\!DOCTYPE[^\>\[]+(\[[^\]]+)?))+[^>]+\>/g, '');
|
38
|
-
postscribe(document.body, markup, {
|
39
|
-
error: console.error
|
40
|
-
});
|
41
|
-
}
|
42
|
-
|
43
33
|
export function sendRequest(url, callback) {
|
44
34
|
function reqListener() {
|
45
35
|
callback(oReq.responseText);
|
@@ -115,7 +105,7 @@ export function getCreativeComment(bid) {
|
|
115
105
|
* @param {*} bid
|
116
106
|
*/
|
117
107
|
export function getCreativeCommentMarkup(bid) {
|
118
|
-
let creativeComment =
|
108
|
+
let creativeComment = getCreativeComment(bid);
|
119
109
|
let wrapper = document.createElement('div');
|
120
110
|
wrapper.appendChild(creativeComment);
|
121
111
|
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
|
+
})
|