prebid.js 9.53.3 → 9.53.4

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.
Files changed (208) hide show
  1. package/dist/33acrossAnalyticsAdapter.js +1 -1
  2. package/dist/33acrossBidAdapter.js +1 -1
  3. package/dist/33acrossIdSystem.js +1 -1
  4. package/dist/BTBidAdapter.js +1 -1
  5. package/dist/adagioAnalyticsAdapter.js +1 -1
  6. package/dist/adagioBidAdapter.js +1 -1
  7. package/dist/adagioUtils.js +1 -1
  8. package/dist/addefendBidAdapter.js +1 -1
  9. package/dist/adgenerationBidAdapter.js +1 -1
  10. package/dist/adlooxRtdProvider.js +1 -1
  11. package/dist/adqueryBidAdapter.js +1 -1
  12. package/dist/adrelevantisBidAdapter.js +1 -1
  13. package/dist/adstirBidAdapter.js +1 -1
  14. package/dist/adtrgtmeBidAdapter.js +1 -1
  15. package/dist/adxcgAnalyticsAdapter.js +1 -1
  16. package/dist/adxcgBidAdapter.js +1 -1
  17. package/dist/adyoulikeBidAdapter.js +1 -1
  18. package/dist/agmaAnalyticsAdapter.js +1 -1
  19. package/dist/ajaBidAdapter.js +1 -1
  20. package/dist/amxBidAdapter.js +1 -1
  21. package/dist/amxIdSystem.js +1 -1
  22. package/dist/aniviewBidAdapter.js +1 -1
  23. package/dist/appierAnalyticsAdapter.js +1 -1
  24. package/dist/appnexusBidAdapter.js +1 -1
  25. package/dist/asoBidAdapter.js +1 -1
  26. package/dist/axonixBidAdapter.js +1 -1
  27. package/dist/beopBidAdapter.js +1 -1
  28. package/dist/bidderTimeoutUtils.js +1 -0
  29. package/dist/bidglassBidAdapter.js +1 -1
  30. package/dist/big-richmediaBidAdapter.js +1 -1
  31. package/dist/bitmediaBidAdapter.js +1 -1
  32. package/dist/bridBidAdapter.js +1 -1
  33. package/dist/bridgeuppBidAdapter.js +1 -1
  34. package/dist/bridgewellBidAdapter.js +1 -1
  35. package/dist/brightMountainMediaBidAdapter.js +1 -1
  36. package/dist/carodaBidAdapter.js +1 -1
  37. package/dist/chtnwBidAdapter.js +1 -1
  38. package/dist/chunk-core.js +1 -1
  39. package/dist/concertBidAdapter.js +1 -1
  40. package/dist/connectadBidAdapter.js +1 -1
  41. package/dist/consumableBidAdapter.js +1 -1
  42. package/dist/contxtfulBidAdapter.js +1 -1
  43. package/dist/conversantAnalyticsAdapter.js +1 -1
  44. package/dist/conversantBidAdapter.js +1 -1
  45. package/dist/craftBidAdapter.js +1 -1
  46. package/dist/criteoBidAdapter.js +1 -1
  47. package/dist/cwireBidAdapter.js +1 -1
  48. package/dist/dailymotionBidAdapter.js +1 -1
  49. package/dist/dependencies.json +10 -1
  50. package/dist/dspxBidAdapter.js +1 -1
  51. package/dist/dxkultureBidAdapter.js +1 -1
  52. package/dist/eplanningBidAdapter.js +1 -1
  53. package/dist/equativBidAdapter.js +1 -1
  54. package/dist/eskimiBidAdapter.js +1 -1
  55. package/dist/euidIdSystem.js +1 -1
  56. package/dist/exadsBidAdapter.js +1 -1
  57. package/dist/excoBidAdapter.js +1 -1
  58. package/dist/feedadBidAdapter.js +1 -1
  59. package/dist/finativeBidAdapter.js +1 -1
  60. package/dist/freewheel-sspBidAdapter.js +1 -1
  61. package/dist/fwsspBidAdapter.js +1 -1
  62. package/dist/gmosspBidAdapter.js +1 -1
  63. package/dist/greenbidsAnalyticsAdapter.js +1 -1
  64. package/dist/greenbidsBidAdapter.js +1 -1
  65. package/dist/greenbidsRtdProvider.js +1 -1
  66. package/dist/gridBidAdapter.js +1 -1
  67. package/dist/gumgumBidAdapter.js +1 -1
  68. package/dist/h12mediaBidAdapter.js +1 -1
  69. package/dist/hypelabBidAdapter.js +1 -1
  70. package/dist/id5AnalyticsAdapter.js +1 -1
  71. package/dist/id5IdSystem.js +1 -1
  72. package/dist/imdsBidAdapter.js +1 -1
  73. package/dist/improvedigitalBidAdapter.js +1 -1
  74. package/dist/inmobiBidAdapter.js +1 -1
  75. package/dist/insticatorBidAdapter.js +1 -1
  76. package/dist/intentIqAnalyticsAdapter.js +1 -1
  77. package/dist/ixBidAdapter.js +1 -1
  78. package/dist/jixieBidAdapter.js +1 -1
  79. package/dist/justpremiumBidAdapter.js +1 -1
  80. package/dist/kargoBidAdapter.js +1 -1
  81. package/dist/kimberliteBidAdapter.js +1 -1
  82. package/dist/konduitAnalyticsAdapter.js +1 -1
  83. package/dist/kueezBidAdapter.js +1 -1
  84. package/dist/lassoBidAdapter.js +1 -1
  85. package/dist/lifestreetBidAdapter.js +1 -1
  86. package/dist/liveIntentId.js +1 -1
  87. package/dist/logicadBidAdapter.js +1 -1
  88. package/dist/loglyliftBidAdapter.js +1 -1
  89. package/dist/luceadBidAdapter.js +1 -1
  90. package/dist/mabidderBidAdapter.js +1 -1
  91. package/dist/madsenseBidAdapter.js +1 -1
  92. package/dist/magniteAnalyticsAdapter.js +1 -1
  93. package/dist/malltvAnalyticsAdapter.js +1 -1
  94. package/dist/marsmediaBidAdapter.js +1 -1
  95. package/dist/mediafuseBidAdapter.js +1 -1
  96. package/dist/medianetBidAdapter.js +1 -1
  97. package/dist/medianetUtils.js +1 -1
  98. package/dist/mediasquareBidAdapter.js +1 -1
  99. package/dist/mgidBidAdapter.js +1 -1
  100. package/dist/missenaBidAdapter.js +1 -1
  101. package/dist/mobilefuseBidAdapter.js +1 -1
  102. package/dist/nextMillenniumBidAdapter.js +1 -1
  103. package/dist/nexx360Utils.js +1 -1
  104. package/dist/nobidAnalyticsAdapter.js +1 -1
  105. package/dist/nobidBidAdapter.js +1 -1
  106. package/dist/nodalsAiRtdProvider.js +1 -1
  107. package/dist/not-for-prod/prebid.js +175 -172
  108. package/dist/objectGuard.js +1 -1
  109. package/dist/oguryBidAdapter.js +1 -1
  110. package/dist/onetagBidAdapter.js +1 -1
  111. package/dist/ooloAnalyticsAdapter.js +1 -1
  112. package/dist/openxBidAdapter.js +1 -1
  113. package/dist/optableRtdProvider.js +1 -1
  114. package/dist/optidigitalBidAdapter.js +1 -1
  115. package/dist/orbidderBidAdapter.js +1 -1
  116. package/dist/outbrainBidAdapter.js +1 -1
  117. package/dist/pixfutureBidAdapter.js +1 -1
  118. package/dist/publinkIdSystem.js +1 -1
  119. package/dist/pubmaticAnalyticsAdapter.js +1 -1
  120. package/dist/pubmaticBidAdapter.js +1 -1
  121. package/dist/pubmaticRtdProvider.js +1 -1
  122. package/dist/pubmaticUtils.js +1 -0
  123. package/dist/pubwiseAnalyticsAdapter.js +1 -1
  124. package/dist/pubxaiAnalyticsAdapter.js +1 -1
  125. package/dist/pxyzBidAdapter.js +1 -1
  126. package/dist/quantcastBidAdapter.js +1 -1
  127. package/dist/readpeakBidAdapter.js +1 -1
  128. package/dist/relaidoBidAdapter.js +1 -1
  129. package/dist/retailspotBidAdapter.js +1 -1
  130. package/dist/rhythmoneBidAdapter.js +1 -1
  131. package/dist/riseUtils.js +1 -1
  132. package/dist/rtdModule.js +1 -1
  133. package/dist/rubiconBidAdapter.js +1 -1
  134. package/dist/seedingAllianceBidAdapter.js +1 -1
  135. package/dist/seedtagBidAdapter.js +1 -1
  136. package/dist/sevioBidAdapter.js +1 -0
  137. package/dist/sharethroughAnalyticsAdapter.js +1 -1
  138. package/dist/sharethroughBidAdapter.js +1 -1
  139. package/dist/showheroes-bsBidAdapter.js +1 -1
  140. package/dist/smaatoBidAdapter.js +1 -1
  141. package/dist/smartadserverBidAdapter.js +1 -1
  142. package/dist/smartxBidAdapter.js +1 -1
  143. package/dist/smilewantedBidAdapter.js +1 -1
  144. package/dist/snigelBidAdapter.js +1 -1
  145. package/dist/sonobiBidAdapter.js +1 -1
  146. package/dist/sovrnBidAdapter.js +1 -1
  147. package/dist/sparteoBidAdapter.js +1 -1
  148. package/dist/sspBCBidAdapter.js +1 -1
  149. package/dist/stvBidAdapter.js +1 -1
  150. package/dist/sublimeBidAdapter.js +1 -1
  151. package/dist/taboolaBidAdapter.js +1 -1
  152. package/dist/tappxBidAdapter.js +1 -1
  153. package/dist/targetVideoBidAdapter.js +1 -1
  154. package/dist/teadsBidAdapter.js +1 -1
  155. package/dist/terceptAnalyticsAdapter.js +1 -1
  156. package/dist/themoneytizerBidAdapter.js +1 -1
  157. package/dist/timeoutRtdProvider.js +1 -1
  158. package/dist/trionBidAdapter.js +1 -1
  159. package/dist/tripleliftBidAdapter.js +1 -1
  160. package/dist/ttdBidAdapter.js +1 -1
  161. package/dist/ucfunnelAnalyticsAdapter.js +1 -1
  162. package/dist/uid2IdSystem.js +1 -1
  163. package/dist/underdogmediaBidAdapter.js +1 -1
  164. package/dist/undertoneBidAdapter.js +1 -1
  165. package/dist/unrulyBidAdapter.js +1 -1
  166. package/dist/vidazooUtils.js +1 -1
  167. package/dist/videobyteBidAdapter.js +1 -1
  168. package/dist/visxBidAdapter.js +1 -1
  169. package/dist/vuukleBidAdapter.js +1 -1
  170. package/dist/widespaceBidAdapter.js +1 -1
  171. package/dist/winrBidAdapter.js +1 -1
  172. package/dist/yahooAdsBidAdapter.js +1 -1
  173. package/dist/yandexBidAdapter.js +1 -1
  174. package/dist/yieldmoBidAdapter.js +1 -1
  175. package/dist/yieldoneAnalyticsAdapter.js +1 -1
  176. package/integrationExamples/gpt/pubmaticRtdProvider_Example.html +161 -0
  177. package/libraries/bidderTimeoutUtils/bidderTimeoutUtils.js +119 -0
  178. package/libraries/objectGuard/objectGuard.js +36 -15
  179. package/libraries/pubmaticUtils/plugins/dynamicTimeout.js +209 -0
  180. package/libraries/pubmaticUtils/plugins/floorProvider.js +168 -0
  181. package/libraries/pubmaticUtils/plugins/pluginManager.js +106 -0
  182. package/libraries/pubmaticUtils/plugins/unifiedPricingRule.js +375 -0
  183. package/libraries/pubmaticUtils/pubmaticUtils.js +76 -0
  184. package/modules/fwsspBidAdapter.js +134 -69
  185. package/modules/fwsspBidAdapter.md +121 -26
  186. package/modules/optableRtdProvider.js +33 -12
  187. package/modules/pubmaticAnalyticsAdapter.js +5 -1
  188. package/modules/pubmaticRtdProvider.js +105 -565
  189. package/modules/rtdModule/index.js +23 -2
  190. package/modules/sevioBidAdapter.js +413 -0
  191. package/modules/sevioBidAdapter.md +29 -0
  192. package/modules/sparteoBidAdapter.js +122 -10
  193. package/modules/timeoutRtdProvider.js +2 -105
  194. package/package.json +1 -1
  195. package/test/spec/activities/objectGuard_spec.js +49 -16
  196. package/test/spec/libraries/bidderTimeoutUtils/bidderTimeoutUtils_spec.js +213 -0
  197. package/test/spec/libraries/pubmaticUtils/plugins/dynamicTimeout_spec.js +746 -0
  198. package/test/spec/libraries/pubmaticUtils/plugins/floorProvider_spec.js +184 -0
  199. package/test/spec/libraries/pubmaticUtils/plugins/pluginManager_spec.js +489 -0
  200. package/test/spec/libraries/pubmaticUtils/plugins/unifiedPricingRule_spec.js +359 -0
  201. package/test/spec/libraries/pubmaticUtils/pubmaticUtils_spec.js +236 -0
  202. package/test/spec/modules/fwsspBidAdapter_spec.js +513 -78
  203. package/test/spec/modules/optableRtdProvider_spec.js +55 -5
  204. package/test/spec/modules/pubmaticRtdProvider_spec.js +252 -1183
  205. package/test/spec/modules/realTimeDataModule_spec.js +58 -8
  206. package/test/spec/modules/sevioBidAdapter_spec.js +513 -0
  207. package/test/spec/modules/sparteoBidAdapter_spec.js +528 -43
  208. package/test/spec/modules/timeoutRtdProvider_spec.js +1 -201
@@ -2,6 +2,7 @@ import { submodule } from '../src/hook.js';
2
2
  import * as ajax from '../src/ajax.js';
3
3
  import { logInfo, deepAccess, logError } from '../src/utils.js';
4
4
  import { getGlobal } from '../src/prebidGlobal.js';
5
+ import { bidderTimeoutFunctions } from '../libraries/bidderTimeoutUtils/bidderTimeoutUtils.js';
5
6
 
6
7
  /**
7
8
  * @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
@@ -11,113 +12,9 @@ const SUBMODULE_NAME = 'timeout';
11
12
 
12
13
  // this allows the stubbing of functions during testing
13
14
  export const timeoutRtdFunctions = {
14
- getDeviceType,
15
- getConnectionSpeed,
16
- checkVideo,
17
- calculateTimeoutModifier,
18
15
  handleTimeoutIncrement
19
16
  };
20
17
 
21
- const entries = Object.entries || function(obj) {
22
- const ownProps = Object.keys(obj);
23
- let i = ownProps.length;
24
- let resArray = new Array(i);
25
- while (i--) { resArray[i] = [ownProps[i], obj[ownProps[i]]]; }
26
- return resArray;
27
- };
28
-
29
- function getDeviceType() {
30
- const userAgent = window.navigator.userAgent.toLowerCase();
31
- if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(userAgent))) {
32
- return 5; // tablet
33
- }
34
- if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(userAgent))) {
35
- return 4; // mobile
36
- }
37
- return 2; // personal computer
38
- }
39
-
40
- function checkVideo(adUnits) {
41
- return adUnits.some((adUnit) => {
42
- return adUnit.mediaTypes && adUnit.mediaTypes.video;
43
- });
44
- }
45
-
46
- function getConnectionSpeed() {
47
- const connection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection || {}
48
- const connectionType = connection.type || connection.effectiveType;
49
-
50
- switch (connectionType) {
51
- case 'slow-2g':
52
- case '2g':
53
- return 'slow';
54
-
55
- case '3g':
56
- return 'medium';
57
-
58
- case 'bluetooth':
59
- case 'cellular':
60
- case 'ethernet':
61
- case 'wifi':
62
- case 'wimax':
63
- case '4g':
64
- return 'fast';
65
- }
66
-
67
- return 'unknown';
68
- }
69
- /**
70
- * Calculate the time to be added to the timeout
71
- * @param {Array} adUnits
72
- * @param {Object} rules
73
- * @return {number}
74
- */
75
- function calculateTimeoutModifier(adUnits, rules) {
76
- logInfo('Timeout rules', rules);
77
- let timeoutModifier = 0;
78
- let toAdd = 0;
79
-
80
- if (rules.includesVideo) {
81
- const hasVideo = timeoutRtdFunctions.checkVideo(adUnits);
82
- toAdd = rules.includesVideo[hasVideo] || 0;
83
- logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`)
84
- timeoutModifier += toAdd;
85
- }
86
-
87
- if (rules.numAdUnits) {
88
- const numAdUnits = adUnits.length;
89
- if (rules.numAdUnits[numAdUnits]) {
90
- timeoutModifier += rules.numAdUnits[numAdUnits];
91
- } else {
92
- for (const [rangeStr, timeoutVal] of entries(rules.numAdUnits)) {
93
- const [lowerBound, upperBound] = rangeStr.split('-');
94
- if (parseInt(lowerBound) <= numAdUnits && numAdUnits <= parseInt(upperBound)) {
95
- logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`)
96
- timeoutModifier += timeoutVal;
97
- break;
98
- }
99
- }
100
- }
101
- }
102
-
103
- if (rules.deviceType) {
104
- const deviceType = timeoutRtdFunctions.getDeviceType();
105
- toAdd = rules.deviceType[deviceType] || 0;
106
- logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`)
107
- timeoutModifier += toAdd;
108
- }
109
-
110
- if (rules.connectionSpeed) {
111
- const connectionSpeed = timeoutRtdFunctions.getConnectionSpeed();
112
- toAdd = rules.connectionSpeed[connectionSpeed] || 0;
113
- logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`)
114
- timeoutModifier += toAdd;
115
- }
116
-
117
- logInfo('timeout Modifier calculated', timeoutModifier);
118
- return timeoutModifier;
119
- }
120
-
121
18
  /**
122
19
  *
123
20
  * @param {Object} reqBidsConfigObj
@@ -161,7 +58,7 @@ function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) {
161
58
  */
162
59
  function handleTimeoutIncrement(reqBidsConfigObj, rules) {
163
60
  const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits;
164
- const timeoutModifier = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules);
61
+ const timeoutModifier = bidderTimeoutFunctions.calculateTimeoutModifier(adUnits, rules);
165
62
  const bidderTimeout = reqBidsConfigObj.timeout || getGlobal().getConfig('bidderTimeout');
166
63
  reqBidsConfigObj.timeout = bidderTimeout + timeoutModifier;
167
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prebid.js",
3
- "version": "9.53.3",
3
+ "version": "9.53.4",
4
4
  "description": "Header Bidding Management Library",
5
5
  "main": "src/prebid.public.js",
6
6
  "exports": {
@@ -13,6 +13,18 @@ describe('objectGuard', () => {
13
13
  get(val) { return `repl${val}` },
14
14
  }
15
15
  })
16
+
17
+ it('should reject conflicting rules', () => {
18
+ const crule = {...rule, paths: ['outer']};
19
+ expect(() => objectGuard([rule, crule])).to.throw();
20
+ expect(() => objectGuard([crule, rule])).to.throw();
21
+ });
22
+
23
+ it('should preserve object identity', () => {
24
+ const guard = objectGuard([rule])({outer: {inner: {foo: 'bar'}}});
25
+ expect(guard.outer).to.equal(guard.outer);
26
+ expect(guard.outer.inner).to.equal(guard.outer.inner);
27
+ })
16
28
  it('can prevent top level read access', () => {
17
29
  const obj = objectGuard([rule])({'foo': 1, 'other': 2});
18
30
  expect(obj).to.eql({
@@ -97,6 +109,18 @@ describe('objectGuard', () => {
97
109
  });
98
110
  });
99
111
 
112
+ it('should reject conflicting rules', () => {
113
+ const crule = {...rule, paths: ['outer']};
114
+ expect(() => objectGuard([rule, crule])).to.throw();
115
+ expect(() => objectGuard([crule, rule])).to.throw();
116
+ });
117
+
118
+ it('should preserve object identity', () => {
119
+ const guard = objectGuard([rule])({outer: {inner: {foo: 'bar'}}});
120
+ expect(guard.outer).to.equal(guard.outer);
121
+ expect(guard.outer.inner).to.equal(guard.outer.inner);
122
+ })
123
+
100
124
  it('does not mess up array reads', () => {
101
125
  const guard = objectGuard([rule])({foo: [{bar: 'baz'}]});
102
126
  expect(guard.foo).to.eql([{bar: 'baz'}]);
@@ -247,22 +271,31 @@ describe('objectGuard', () => {
247
271
  expect(obj.foo).to.eql('21bar');
248
272
  });
249
273
 
250
- it('can apply both redact and write protect', () => {
251
- const obj = objectGuard([
252
- redactRule({
253
- paths: ['foo'],
254
- applies: () => true,
255
- get(val) {
256
- return 'redact' + val;
257
- },
258
- }),
259
- writeProtectRule({
260
- paths: ['foo'],
261
- applies: () => true,
274
+ describe('when a property has both redact and write protect rules', () => {
275
+ let rules;
276
+ beforeEach(() => {
277
+ rules = [
278
+ redactRule({
279
+ paths: ['foo'],
280
+ applies: () => true,
281
+ }),
282
+ writeProtectRule({
283
+ paths: ['foo'],
284
+ applies: () => true,
285
+ })
286
+ ];
287
+ })
288
+ Object.entries({
289
+ 'simple value': 'val',
290
+ 'object value': {inner: 'val'}
291
+ }).forEach(([t, val]) => {
292
+ it(`can apply them both (on ${t})`, () => {
293
+ const obj = objectGuard(rules)({foo: val});
294
+ expect(obj.foo).to.not.exist;
295
+ obj.foo = {other: 'val'};
296
+ expect(obj.foo).to.not.exist;
262
297
  })
263
- ])({foo: 'bar'});
264
- obj.foo = 'baz';
265
- expect(obj.foo).to.eql('redactbar');
266
- });
298
+ })
299
+ })
267
300
  })
268
301
  });
@@ -0,0 +1,213 @@
1
+ import { bidderTimeoutFunctions } from '../../../../libraries/bidderTimeoutUtils/bidderTimeoutUtils.js'
2
+ import { expect } from 'chai';
3
+
4
+ const DEFAULT_USER_AGENT = window.navigator.userAgent;
5
+ const DEFAULT_CONNECTION = window.navigator.connection;
6
+
7
+ const PC_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246';
8
+ const MOBILE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1';
9
+ const TABLET_USER_AGENT = 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148';
10
+
11
+ function resetUserAgent() {
12
+ window.navigator.__defineGetter__('userAgent', () => DEFAULT_USER_AGENT);
13
+ };
14
+
15
+ function setUserAgent(userAgent) {
16
+ window.navigator.__defineGetter__('userAgent', () => userAgent);
17
+ }
18
+
19
+ function resetConnection() {
20
+ window.navigator.__defineGetter__('connection', () => DEFAULT_CONNECTION);
21
+ }
22
+ function setConnectionType(connectionType) {
23
+ window.navigator.__defineGetter__('connection', () => { return { 'type': connectionType } });
24
+ }
25
+
26
+ describe('Timeout RTD submodule', () => {
27
+ let sandbox;
28
+ beforeEach(() => {
29
+ sandbox = sinon.createSandbox();
30
+ });
31
+
32
+ afterEach(() => {
33
+ sandbox.restore();
34
+ });
35
+
36
+ describe('getDeviceType', () => {
37
+ afterEach(() => {
38
+ resetUserAgent();
39
+ });
40
+
41
+ [
42
+ // deviceType, userAgent, deviceTypeNum
43
+ ['pc', PC_USER_AGENT, 2],
44
+ ['mobile', MOBILE_USER_AGENT, 4],
45
+ ['tablet', TABLET_USER_AGENT, 5],
46
+ ].forEach(function (args) {
47
+ const [deviceType, userAgent, deviceTypeNum] = args;
48
+ it(`should be able to recognize ${deviceType} devices`, () => {
49
+ setUserAgent(userAgent);
50
+ const res = bidderTimeoutFunctions.getDeviceType();
51
+ expect(res).to.equal(deviceTypeNum)
52
+ })
53
+ })
54
+ });
55
+
56
+ describe('getConnectionSpeed', () => {
57
+ afterEach(() => {
58
+ resetConnection();
59
+ });
60
+ [
61
+ // connectionType, connectionSpeed
62
+ ['slow-2g', 'slow'],
63
+ ['2g', 'slow'],
64
+ ['3g', 'medium'],
65
+ ['bluetooth', 'fast'],
66
+ ['cellular', 'fast'],
67
+ ['ethernet', 'fast'],
68
+ ['wifi', 'fast'],
69
+ ['wimax', 'fast'],
70
+ ['4g', 'fast'],
71
+ ['not known', 'unknown'],
72
+ [undefined, 'unknown'],
73
+ ].forEach(function (args) {
74
+ const [connectionType, connectionSpeed] = args;
75
+ it(`should be able to categorize connection speed when the connection type is ${connectionType}`, () => {
76
+ setConnectionType(connectionType);
77
+ const res = bidderTimeoutFunctions.getConnectionSpeed();
78
+ expect(res).to.equal(connectionSpeed)
79
+ })
80
+ })
81
+ });
82
+
83
+ describe('Timeout modifier calculations', () => {
84
+ let sandbox;
85
+ beforeEach(() => {
86
+ sandbox = sinon.createSandbox();
87
+ });
88
+
89
+ afterEach(() => {
90
+ sandbox.restore();
91
+ });
92
+
93
+ it('should be able to detect video ad units', () => {
94
+ let adUnits = []
95
+ let res = bidderTimeoutFunctions.checkVideo(adUnits);
96
+ expect(res).to.be.false;
97
+
98
+ adUnits = [{
99
+ mediaTypes: {
100
+ video: []
101
+ }
102
+ }];
103
+ res = bidderTimeoutFunctions.checkVideo(adUnits);
104
+ expect(res).to.be.true;
105
+
106
+ adUnits = [{
107
+ mediaTypes: {
108
+ banner: []
109
+ }
110
+ }];
111
+ res = bidderTimeoutFunctions.checkVideo(adUnits);
112
+ expect(res).to.be.false;
113
+ });
114
+
115
+ it('should calculate the timeout modifier for video', () => {
116
+ sandbox.stub(bidderTimeoutFunctions, 'checkVideo').returns(true);
117
+ const rules = {
118
+ includesVideo: {
119
+ 'true': 200,
120
+ 'false': 50
121
+ }
122
+ }
123
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier([], rules);
124
+ expect(res).to.equal(200)
125
+ });
126
+
127
+ it('should calculate the timeout modifier for connectionSpeed', () => {
128
+ sandbox.stub(bidderTimeoutFunctions, 'getConnectionSpeed').returns('slow');
129
+ const rules = {
130
+ connectionSpeed: {
131
+ 'slow': 200,
132
+ 'medium': 100,
133
+ 'fast': 50
134
+ }
135
+ }
136
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier([], rules);
137
+ expect(res).to.equal(200);
138
+ });
139
+
140
+ it('should calculate the timeout modifier for deviceType', () => {
141
+ sandbox.stub(bidderTimeoutFunctions, 'getDeviceType').returns(4);
142
+ const rules = {
143
+ deviceType: {
144
+ '2': 50,
145
+ '4': 100,
146
+ '5': 200
147
+ },
148
+ }
149
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier([], rules);
150
+ expect(res).to.equal(100)
151
+ });
152
+
153
+ it('should calculate the timeout modifier for ranged numAdunits', () => {
154
+ const rules = {
155
+ numAdUnits: {
156
+ '1-5': 100,
157
+ '6-10': 200,
158
+ '11-15': 300,
159
+ }
160
+ }
161
+ const adUnits = [1, 2, 3, 4, 5, 6];
162
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier(adUnits, rules);
163
+ expect(res).to.equal(200)
164
+ });
165
+
166
+ it('should calculate the timeout modifier for exact numAdunits', () => {
167
+ const rules = {
168
+ numAdUnits: {
169
+ '1': 100,
170
+ '2': 200,
171
+ '3': 300,
172
+ '4-5': 400,
173
+ }
174
+ }
175
+ const adUnits = [1, 2];
176
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier(adUnits, rules);
177
+ expect(res).to.equal(200);
178
+ });
179
+
180
+ it('should add up all the modifiers when all the rules are present', () => {
181
+ sandbox.stub(bidderTimeoutFunctions, 'getConnectionSpeed').returns('slow');
182
+ sandbox.stub(bidderTimeoutFunctions, 'getDeviceType').returns(4);
183
+ const rules = {
184
+ connectionSpeed: {
185
+ 'slow': 200,
186
+ 'medium': 100,
187
+ 'fast': 50
188
+ },
189
+ deviceType: {
190
+ '2': 50,
191
+ '4': 100,
192
+ '5': 200
193
+ },
194
+ includesVideo: {
195
+ 'true': 200,
196
+ 'false': 50
197
+ },
198
+ numAdUnits: {
199
+ '1': 100,
200
+ '2': 200,
201
+ '3': 300,
202
+ '4-5': 400,
203
+ }
204
+ }
205
+ const res = bidderTimeoutFunctions.calculateTimeoutModifier([{
206
+ mediaTypes: {
207
+ video: []
208
+ }
209
+ }], rules);
210
+ expect(res).to.equal(600);
211
+ });
212
+ });
213
+ });