Skip to content

Commit

Permalink
pb9: Organize adloader.js (prebid#11489)
Browse files Browse the repository at this point in the history
* Update adloader.js

* Update adloader.js

* Update adloader_spec.js

* Update adloader.js
  • Loading branch information
patmmccann authored and zkosanovic committed May 29, 2024
1 parent d4adb8c commit 6f36300
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
35 changes: 18 additions & 17 deletions src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,37 @@ import { logError, logWarn, insertElement, setScriptAttributes } from './utils.j
const _requestCache = new WeakMap();
// The below list contains modules or vendors whom Prebid allows to load external JS.
const _approvedLoadExternalJSList = [
// Prebid maintained modules:
'debugging',
'adloox',
'criteo',
'outstream',
// Bid Modules:
'adagio',
'browsi',
'brandmetrics',
'justtag',
'tncId',
'akamaidap',
'ftrackId',
'inskin',
'hadron',
'medianet',
'improvedigital',
'azerionedge',
'lucead',
// RTD modules:
'aaxBlockmeter',
'confiant',
'adloox',
'akamaidap',
'arcspan',
'airgrid',
'browsi',
'brandmetrics',
'clean.io',
'confiant',
'contxtful',
'hadron',
'mediafilter',
'medianet',
'azerionedge',
'a1Media',
'geoedge',
'mediafilter',
'qortex',
'dynamicAdBoost',
'contxtful',
// UserId Submodules
'justtag',
'tncId',
'ftrackId',
'id5',
'lucead',
'51Degrees',
];

/**
Expand Down
18 changes: 9 additions & 9 deletions test/spec/adloader_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ describe('adLoader', function () {
});

it('only allows whitelisted vendors to load scripts', function () {
adLoader.loadExternalScript('someURL', 'criteo');
adLoader.loadExternalScript('someURL', 'debugging');
expect(utilsLogErrorStub.called).to.be.false;
expect(utilsinsertElementStub.called).to.be.true;
});

it('should not load cached script again', function() {
adLoader.loadExternalScript('someURL', 'criteo');
adLoader.loadExternalScript('someURL', 'debugging');
expect(utilsinsertElementStub.called).to.be.false;
});

it('callback function can be passed to the function', function() {
let callback = function() {};
adLoader.loadExternalScript('someURL1', 'criteo', callback);
adLoader.loadExternalScript('someURL1', 'debugging', callback);
expect(utilsinsertElementStub.called).to.be.true;
});

Expand All @@ -61,11 +61,11 @@ describe('adLoader', function () {
}
const doc1 = getDocSpec();
const doc2 = getDocSpec();
adLoader.loadExternalScript('someURL', 'criteo', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'criteo', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'criteo', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'criteo', () => {}, doc2);
adLoader.loadExternalScript('someURL', 'criteo', () => {}, doc2);
adLoader.loadExternalScript('someURL', 'debugging', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'debugging', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'debugging', () => {}, doc1);
adLoader.loadExternalScript('someURL', 'debugging', () => {}, doc2);
adLoader.loadExternalScript('someURL', 'debugging', () => {}, doc2);
expect(utilsinsertElementStub.callCount).to.equal(2);
});
});
Expand All @@ -88,7 +88,7 @@ describe('adLoader', function () {
}
},
attrs = {'z': 'A', 'y': 2};
let script = adLoader.loadExternalScript('someUrl', 'criteo', undefined, doc, attrs);
let script = adLoader.loadExternalScript('someUrl', 'debugging', undefined, doc, attrs);
expect(script.z).to.equal('A');
expect(script.y).to.equal(2);
});
Expand Down

0 comments on commit 6f36300

Please sign in to comment.