@@ -118,6 +118,16 @@ describe('Adloox Ad Server Video', function () {
118
118
} ) ;
119
119
120
120
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
+
121
131
describe ( 'invalid arguments' , function ( ) {
122
132
it ( 'should require callback' , function ( done ) {
123
133
const ret = buildVideoUrl ( ) ;
@@ -235,7 +245,6 @@ describe('Adloox Ad Server Video', function () {
235
245
it ( 'should fetch, retry on withoutCredentials, follow and return a wrapped blob that expires' , function ( done ) {
236
246
BID . responseTimestamp = utils . timestamp ( ) ;
237
247
BID . ttl = 30 ;
238
- this . timeout ( 5000 )
239
248
240
249
const clock = sandbox . useFakeTimers ( BID . responseTimestamp ) ;
241
250
@@ -244,42 +253,16 @@ describe('Adloox Ad Server Video', function () {
244
253
url : wrapperUrl ,
245
254
bid : BID
246
255
} ;
256
+
257
+ URL . createObjectURL . callsFake ( ( ) => 'mock-blob-url' ) ;
258
+
247
259
const ret = buildVideoUrl ( options , function ( url ) {
248
260
expect ( url . substr ( 0 , options . url_vast . length ) ) . is . equal ( options . url_vast ) ;
249
-
250
- const match = url . match ( / [ ? & ] v a s t = ( b l o b % 3 A [ ^ & ] + ) / ) ;
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 ( / [ ? & ] v a s t = m o c k - b l o b - u r l / ) ;
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 ( ) ;
283
266
} ) ;
284
267
expect ( ret ) . is . true ;
285
268
0 commit comments