Skip to content

Commit

Permalink
Add test case for snapshot restore with blocked ads
Browse files Browse the repository at this point in the history
Clean up some distracting error messages during the ad tests. Add a test that checks to make sure the src attribute is restored if currentSrc never gets changed. Worked around an issue with error events and bad poster images in video.js error handling (videojs/video.js#1465).
  • Loading branch information
dmlap committed Aug 30, 2014
1 parent ca0c14b commit 61c76a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
3 changes: 1 addition & 2 deletions test/ads.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>ads Test Suite</title>
<!-- Load local video.js -->
<link rel="stylesheet" href="../node_modules/video.js/dist/video-js.min.css" media="screen">
<link rel="stylesheet" href="../node_modules/video.js/dist/video-js/video-js.min.css" media="screen">
<script src="../node_modules/video.js/dist/video-js/video.js"></script>
<!-- Load local QUnit. -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
Expand All @@ -16,7 +16,6 @@
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<video src="http://vjs.zencdn.net/v/oceans.mp4" controls></video>
</div>
</body>
</html>
45 changes: 40 additions & 5 deletions test/videojs.ads.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
var
video,
oldSetTimeout,
oldSetImmediate,
oldClearImmediate,
player;

test('the environment is sane', function() {
ok(true, 'true is ok');
});

module('Ad Framework', {
setup: function() {
// fake out Html5 support
Expand All @@ -12,7 +17,6 @@ module('Ad Framework', {
};

video = document.createElement('video');
video.poster = '//example.com/poster.jpg';
video.load = function() {};
video.play = function() {};

Expand All @@ -25,13 +29,15 @@ module('Ad Framework', {

document.getElementById('qunit-fixture').appendChild(video);
player = videojs(video);

player.buffered = function() {
return videojs.createTimeRange(0, 0);
};
video = player.el().querySelector('.vjs-tech');
player.ads();

// make setImmediate synchronous
oldSetImmediate = window.setImmediate;
window.setImmediate = function(callback) {
callback.call(window);
};
Expand All @@ -40,14 +46,11 @@ module('Ad Framework', {
oldClearImmediate = window.clearImmediate;
},
teardown: function() {
window.setImmediate = oldSetImmediate;
window.clearImmediate = oldClearImmediate;
}
});

test('the environment is sane', function() {
ok(true, 'true is ok');
});

test('begins in content-set', function() {
equal(player.ads.state, 'content-set');
});
Expand Down Expand Up @@ -234,6 +237,7 @@ test('starts the content video if there is no preroll', function() {
});

test('removes the poster attribute so it does not flash between videos', function() {
video.poster = 'http://www.videojs.com/img/poster.jpg'
ok(video.poster, 'the poster is present initially');

player.trigger('adsready');
Expand All @@ -244,6 +248,7 @@ test('removes the poster attribute so it does not flash between videos', functio
});

test('restores the poster attribute after ads have ended', function() {
video.poster = 'http://www.videojs.com/img/poster.jpg';
player.trigger('adsready');
player.trigger('play');
player.trigger('adstart');
Expand Down Expand Up @@ -623,3 +628,33 @@ test('changing the source and then timing out does not restore a snapshot', func
player.currentSrc(),
'playing the second video');
});

// changing the src attribute to a URL that AdBlocker is intercepting
// doesn't update currentSrc, so when restoring the snapshot we
// should check for src attribute modifications as well
test('checks for a src attribute change that isn\'t reflected in currentSrc', function() {
var updatedSrc;
player.currentSrc = function() {
return 'content.mp4';
};
player.currentType = function() {
return 'video/mp4';
};

player.trigger('adsready');
player.trigger('play');
player.trigger('adstart');

player.src = function(source) {
if (source === undefined) {
return 'ad.mp4';
}
updatedSrc = source;
};
player.trigger('adend');

deepEqual(updatedSrc, {
src: 'content.mp4',
type: 'video/mp4'
}, 'restored src attribute');
});

0 comments on commit 61c76a5

Please # to comment.