Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean.io RTD Module: Use loadExternalScript function instead of insertElement() method #9991

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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