Skip to content

Commit 5b4390f

Browse files
dgirardijorgeluisrocha
authored andcommitted
Adloox server video: mock out blob URLs in tests (prebid#9881)
1 parent 4cf73c5 commit 5b4390f

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

test/spec/modules/adlooxAdServerVideo_spec.js

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ describe('Adloox Ad Server Video', function () {
118118
});
119119

120120
describe('buildVideoUrl', function () {
121+
beforeEach(() => {
122+
sinon.stub(URL, 'createObjectURL');
123+
sinon.stub(URL, 'revokeObjectURL');
124+
});
125+
126+
afterEach(() => {
127+
URL.createObjectURL.restore()
128+
URL.revokeObjectURL.restore()
129+
});
130+
121131
describe('invalid arguments', function () {
122132
it('should require callback', function (done) {
123133
const ret = buildVideoUrl();
@@ -235,7 +245,6 @@ describe('Adloox Ad Server Video', function () {
235245
it('should fetch, retry on withoutCredentials, follow and return a wrapped blob that expires', function (done) {
236246
BID.responseTimestamp = utils.timestamp();
237247
BID.ttl = 30;
238-
this.timeout(5000)
239248

240249
const clock = sandbox.useFakeTimers(BID.responseTimestamp);
241250

@@ -244,42 +253,16 @@ describe('Adloox Ad Server Video', function () {
244253
url: wrapperUrl,
245254
bid: BID
246255
};
256+
257+
URL.createObjectURL.callsFake(() => 'mock-blob-url');
258+
247259
const ret = buildVideoUrl(options, function (url) {
248260
expect(url.substr(0, options.url_vast.length)).is.equal(options.url_vast);
249-
250-
const match = url.match(/[?&]vast=(blob%3A[^&]+)/);
251-
expect(match).is.not.null;
252-
253-
const blob = decodeURIComponent(match[1]);
254-
255-
const xfr = sandbox.useFakeXMLHttpRequest();
256-
xfr.useFilters = true;
257-
xfr.addFilter(x => true); // there is no network traffic for Blob URLs here
258-
259-
ajax(blob, {
260-
success: (responseText, q) => {
261-
expect(q.status).is.equal(200);
262-
expect(q.getResponseHeader('content-type')).is.equal(vastHeaders['content-type']);
263-
264-
clock.runAll();
265-
266-
ajax(blob, {
267-
success: (responseText, q) => {
268-
xfr.useFilters = false; // .restore() does not really work
269-
if (q.status == 0) return done();
270-
done(new Error('Blob should have expired'));
271-
},
272-
error: (statusText, q) => {
273-
xfr.useFilters = false;
274-
done();
275-
}
276-
});
277-
},
278-
error: (statusText, q) => {
279-
xfr.useFilters = false;
280-
done(new Error(statusText));
281-
}
282-
});
261+
expect(url).to.match(/[?&]vast=mock-blob-url/);
262+
sinon.assert.calledWith(URL.createObjectURL, sinon.match((val) => val.type === vastHeaders['content-type']));
263+
clock.runAll();
264+
sinon.assert.calledWith(URL.revokeObjectURL, 'mock-blob-url');
265+
done();
283266
});
284267
expect(ret).is.true;
285268

0 commit comments

Comments
 (0)