Skip to content

Commit

Permalink
clean.io RTD Module: Use loadExternalScript function instead of inser…
Browse files Browse the repository at this point in the history
…tElement() method to insert the Clean.io script. (prebid#9991)

Co-authored-by: yevhen.tykhonov <yevhen.tykhonov@gmail.com>
  • Loading branch information
eugen-tikhonov and avetihon authored May 24, 2023
1 parent c6fa40b commit ce9c164
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions modules/cleanioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { submodule } from '../src/hook.js';
import { loadExternalScript } from '../src/adloader.js';
import { logError, generateUUID, insertElement } from '../src/utils.js';
import * as events from '../src/events.js';
import CONSTANTS from '../src/constants.json';
Expand Down Expand Up @@ -52,10 +53,7 @@ function pageInitStepPreloadScript(scriptURL) {
* @param {string} scriptURL The script URL to add to the page for protection
*/
function pageInitStepProtectPage(scriptURL) {
const scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.src = scriptURL;
insertElement(scriptElement);
loadExternalScript(scriptURL, 'clean.io');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const _approvedLoadExternalJSList = [
'improvedigital',
'aaxBlockmeter',
'confiant',
'arcspan'
'arcspan',
'clean.io'
]

/**
Expand Down
15 changes: 7 additions & 8 deletions test/spec/modules/cleanioRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js';
import * as utils from '../../../src/utils.js';
import * as hook from '../../../src/hook.js'
import * as events from '../../../src/events.js';
Expand Down Expand Up @@ -68,10 +69,8 @@ describe('clean.io RTD module', function () {
it('pageInitStepProtectPage() should insert script element', function() {
pageInitStepProtectPage(fakeScriptURL);

sinon.assert.calledOnce(insertElementStub);
sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'SCRIPT'));
sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.type === 'text/javascript'));
sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.src === fakeScriptURL));
sinon.assert.calledOnce(loadExternalScriptStub);
sinon.assert.calledWith(loadExternalScriptStub, fakeScriptURL, 'clean.io');
});
});

Expand Down Expand Up @@ -133,14 +132,14 @@ describe('clean.io RTD module', function () {
it('should refuse initialization with incorrect parameters', function () {
const { init } = getModule();
expect(init({ params: { cdnUrl: 'abc', protectionMode: 'full' } }, {})).to.equal(false); // too short distribution name
sinon.assert.notCalled(insertElementStub);
sinon.assert.notCalled(loadExternalScriptStub);
});

it('should iniitalize in full (page) protection mode', function () {
it('should initialize in full (page) protection mode', function () {
const { init, onBidResponseEvent } = getModule();
expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } }, {})).to.equal(true);
sinon.assert.calledOnce(insertElementStub);
sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'SCRIPT'));
sinon.assert.calledOnce(loadExternalScriptStub);
sinon.assert.calledWith(loadExternalScriptStub, 'https://abc1234567890.cloudfront.net/script.js', 'clean.io');

const fakeBidResponse = makeFakeBidResponse();
onBidResponseEvent(fakeBidResponse, {}, {});
Expand Down

0 comments on commit ce9c164

Please sign in to comment.