Skip to content

Commit d03468a

Browse files
committed
Add methods to handle video of tests
- createVideo method will create a video from tests - getEmbedVideoPlayer method will create a html5 player for a video.
1 parent 092d69b commit d03468a

9 files changed

Lines changed: 198 additions & 2 deletions

File tree

lib/webpagetest.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ var paths = {
2828
har: 'export.php',
2929
waterfall: 'waterfall.php',
3030
thumbnail: 'thumbnail.php',
31-
cancel: 'cancelTest.php'
31+
cancel: 'cancelTest.php',
32+
videoCreation: 'video/create.php',
33+
videoView: 'video/view.php'
3234
};
3335

3436
var filenames = {
@@ -577,6 +579,35 @@ function listen(local, callback) {
577579
return server.listen.call(this, local, callback);
578580
}
579581

582+
function getEmbedVideoPlayer(id, options, callback) {
583+
var params = {
584+
embed: 1,
585+
id: id
586+
};
587+
588+
options.args = options.args || {
589+
type: 'text/html',
590+
encoding: options.dataURI ? 'utf8' : options.encoding
591+
};
592+
593+
options.parser = function (data) {
594+
return data.toString();
595+
};
596+
597+
api.call(this, paths.videoView, callback, params, options);
598+
}
599+
600+
function createVideo(tests, options, callback) {
601+
//prefer the json format because the xml format is buggy with wpt 2.11
602+
var params = {
603+
tests: tests,
604+
f: 'json',
605+
end: options.end || 'visual'
606+
};
607+
608+
api.call(this, paths.videoCreation, callback, params, options);
609+
}
610+
580611
// WPT constructor
581612
function WebPageTest(server, key) {
582613
if (!(this instanceof WebPageTest)) {
@@ -620,6 +651,8 @@ WebPageTest.prototype = {
620651
getTestInfo: getTestInfo,
621652
getWaterfallImage: getWaterfallImage,
622653
getScreenshotImage: getScreenshotImage,
654+
getEmbedVideoPlayer: getEmbedVideoPlayer,
655+
createVideo: createVideo,
623656
scriptToString: WebPageTest.scriptToString,
624657
listen: listen,
625658

test/dryrun-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,5 +356,20 @@ describe('Dry Run', function() {
356356
});
357357
});
358358

359+
it('create a video', function (done) {
360+
wpt.createVideo('130416_YS_KD4-r:3-c:1,130416_W6_KEE-r:8-c:1', {dryRun: true}, function (err, data) {
361+
if (err) throw err;
362+
assert.equal(data.url, wptServer + 'video/create.php?tests=130416_YS_KD4-r%3A3-c%3A1%2C130416_W6_KEE-r%3A8-c%3A1&f=json&end=visual');
363+
done();
364+
});
365+
});
366+
367+
it('get the url of an embedded video', function (done) {
368+
wpt.getEmbedVideoPlayer('130416_36ed6e37013655a14b2b857cdccec99db72adcaa', {dryRun: true}, function (err, data) {
369+
if (err) throw err;
370+
assert.equal(data.url, wptServer + 'video/view.php?embed=1&id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa');
371+
done();
372+
});
373+
});
359374
});
360375
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"statusCode":200,
3+
"statusText":"Ok",
4+
"data":{
5+
"videoId":"130416_36ed6e37013655a14b2b857cdccec99db72adcaa",
6+
"jsonUrl":"http:\/\/www.webpagetest.org\/video\/view.php?f=json&id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa",
7+
"userUrl":"http:\/\/www.webpagetest.org\/video\/view.php?id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa"
8+
}
9+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
5+
<title>WebPagetest - Visual Comparison - Apr 30, 2013 : , </title>
6+
<link rel="stylesheet" href="/video/video-js.3.2.0/video-js.min.css" type="text/css">
7+
<style type="text/css">
8+
div.content
9+
{
10+
text-align:center;
11+
background-color: black;
12+
color: white;
13+
font-family: arial,sans-serif
14+
}
15+
.link
16+
{
17+
text-decoration: none;
18+
color: white;
19+
}
20+
#player
21+
{
22+
margin-left: auto;
23+
margin-right: auto;
24+
}
25+
#location {
26+
text-align: left;
27+
padding: 5px;
28+
width: 100%;
29+
}
30+
.vjs-default-skin .vjs-controls {height: 0;}
31+
.vjs-default-skin .vjs-mute-control {display: none;}
32+
.vjs-default-skin .vjs-volume-control {display: none;}
33+
body {background-color: black; margin:0; padding: 0;} </style>
34+
<script type="text/javascript" src="/video/video-js.3.2.0/video.min.js"></script>
35+
</head>
36+
<body>
37+
<div class="page">
38+
<script>
39+
_V_.options.techOrder = ['flash', 'html5'];
40+
_V_.options.flash.swf = '/video/player/flowplayer-3.2.16.swf';
41+
_V_.options.flash.flashVars = {config:"{'clip':{'scaling':'fit'},'plugins':{'controls':{'volume':false,'mute':false,'stop':true,'tooltips':{'buttons':true,'fullscreen':'Enter fullscreen mode'}}},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'playlist':[{'url':'/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.png'},{'url':'/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.mp4','autoPlay':false,'autoBuffering':false}]}"};
42+
_V_.options.flash.params = {
43+
allowfullscreen: 'true',
44+
wmode: 'transparent',
45+
allowscriptaccess: 'always'
46+
};
47+
_V_.options.flash.attributes={};
48+
</script>
49+
<video id="player" class="video-js vjs-default-skin" controls
50+
preload="auto" width="816" height="384" poster="/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.png"data-setup="{}">
51+
<source src="/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.mp4" type='video/mp4'>
52+
</video>
53+
</div>
54+
<script type="text/javascript">if(!NREUMQ.f){NREUMQ.f=function(){NREUMQ.push(["load",new Date().getTime()]);var e=document.createElement("script");e.type="text/javascript";e.src=(("http:"===document.location.protocol)?"http:":"https:")+"//"+"d1ros97qkrwjf5.cloudfront.net/42/eum/rum.js";document.body.appendChild(e);if(NREUMQ.a)NREUMQ.a();};NREUMQ.a=window.onload;window.onload=NREUMQ.f;};NREUMQ.push(["nrfj","beacon-1.newrelic.com","5b0327a758","2035125","NFBXZUNRW0ADAkRbCQ0aYENYH0NaBgRfHRAKUEIfQVhF",0,5,new Date().getTime(),"","","","",""]);</script>
55+
</body>
56+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"statusCode":200,
3+
"statusText":"Ok",
4+
"data":{
5+
"videoId":"130416_36ed6e37013655a14b2b857cdccec99db72adcaa",
6+
"jsonUrl":"http:\/\/www.webpagetest.org\/video\/view.php?f=json&id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa",
7+
"userUrl":"http:\/\/www.webpagetest.org\/video\/view.php?id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa"
8+
}
9+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
5+
<title>WebPagetest - Visual Comparison - Apr 30, 2013 : , </title>
6+
<link rel="stylesheet" href="/video/video-js.3.2.0/video-js.min.css" type="text/css">
7+
<style type="text/css">
8+
div.content
9+
{
10+
text-align:center;
11+
background-color: black;
12+
color: white;
13+
font-family: arial,sans-serif
14+
}
15+
.link
16+
{
17+
text-decoration: none;
18+
color: white;
19+
}
20+
#player
21+
{
22+
margin-left: auto;
23+
margin-right: auto;
24+
}
25+
#location {
26+
text-align: left;
27+
padding: 5px;
28+
width: 100%;
29+
}
30+
.vjs-default-skin .vjs-controls {height: 0;}
31+
.vjs-default-skin .vjs-mute-control {display: none;}
32+
.vjs-default-skin .vjs-volume-control {display: none;}
33+
body {background-color: black; margin:0; padding: 0;} </style>
34+
<script type="text/javascript" src="/video/video-js.3.2.0/video.min.js"></script>
35+
</head>
36+
<body>
37+
<div class="page">
38+
<script>
39+
_V_.options.techOrder = ['flash', 'html5'];
40+
_V_.options.flash.swf = '/video/player/flowplayer-3.2.16.swf';
41+
_V_.options.flash.flashVars = {config:"{'clip':{'scaling':'fit'},'plugins':{'controls':{'volume':false,'mute':false,'stop':true,'tooltips':{'buttons':true,'fullscreen':'Enter fullscreen mode'}}},'canvas':{'backgroundColor':'#000000','backgroundGradient':'none'},'playlist':[{'url':'/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.png'},{'url':'/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.mp4','autoPlay':false,'autoBuffering':false}]}"};
42+
_V_.options.flash.params = {
43+
allowfullscreen: 'true',
44+
wmode: 'transparent',
45+
allowscriptaccess: 'always'
46+
};
47+
_V_.options.flash.attributes={};
48+
</script>
49+
<video id="player" class="video-js vjs-default-skin" controls
50+
preload="auto" width="816" height="384" poster="/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.png"data-setup="{}">
51+
<source src="/results/video/13/04/16/36ed6e37013655a14b2b857cdccec99db72adcaa/video.mp4" type='video/mp4'>
52+
</video>
53+
</div>
54+
<script type="text/javascript">if(!NREUMQ.f){NREUMQ.f=function(){NREUMQ.push(["load",new Date().getTime()]);var e=document.createElement("script");e.type="text/javascript";e.src=(("http:"===document.location.protocol)?"http:":"https:")+"//"+"d1ros97qkrwjf5.cloudfront.net/42/eum/rum.js";document.body.appendChild(e);if(NREUMQ.a)NREUMQ.a();};NREUMQ.a=window.onload;window.onload=NREUMQ.f;};NREUMQ.push(["nrfj","beacon-1.newrelic.com","5b0327a758","2035125","NFBXZUNRW0ADAkRbCQ0aYENYH0NaBgRfHRAKUEIfQVhF",0,5,new Date().getTime(),"","","","",""]);</script>
55+
</body>
56+
</html>

test/helpers/nock-server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ var reqResMap = {
3232
'/getgzip.php?test=120816_V2_2&file=1_screen.png': 'screenshotFullResolution.png',
3333
'/cancelTest.php?test=120816_V2_2': 'cancel.html',
3434
'/cancelTest.php?test=120816_V2_3': 'cancelNotCancelled.html',
35+
'/video/create.php?tests=130416_YS_KD4-r%3A3-c%3A1%2C130416_W6_KEE-r%3A8-c%3A1&f=json&end=visual': 'createVideo.json',
36+
'/video/view.php?embed=1&id=130416_36ed6e37013655a14b2b857cdccec99db72adcaa': 'embeddedVideoPlayer.html',
3537

3638
// test results for multi runs with/without custom median metric
3739
'/xmlResult.php?test=130619_KK_6A2': 'testResultsMultiRunsDefaultMedianMetric.xml',

test/helpers/response-objects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var fs = require('fs'),
99

1010
var PATH_OBJECTS = path.join(__dirname, '../fixtures/objects');
1111

12-
var reExtensions = /^\.(?:json|txt)$/i,
12+
var reExtensions = /^\.(?:json|txt|html)$/i,
1313
reJSONExt = /^\.json$/i,
1414
reEOFNewLine = /\s+$/;
1515

test/nock-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,22 @@ describe('Example WebPageTest', function() {
246246
});
247247
});
248248

249+
it('creates a video', function (done) {
250+
wpt.createVideo('130416_YS_KD4-r:3-c:1,130416_W6_KEE-r:8-c:1', {}, function (err, data) {
251+
if (err) throw err;
252+
assert.deepEqual(data, ResponseObjects.createVideo);
253+
done();
254+
});
255+
});
256+
257+
it('get the url of an embedded video', function (done){
258+
wpt.getEmbedVideoPlayer('130416_36ed6e37013655a14b2b857cdccec99db72adcaa', {}, function (err, data) {
259+
if (err) throw err;
260+
assert.equal(data, ResponseObjects.embeddedVideoPlayer + "\n");
261+
done();
262+
});
263+
});
264+
249265
// not found / invalid
250266

251267
it('gets an invalid test status request then returns a not found test status object', function(done) {

0 commit comments

Comments
 (0)