6 function getQueryStrings() {
7 // Gets query parameters from the URL; e.g., given a URL like:
9 // http://<url>/my.html?test=123&bob=456
11 // returns params["test"] = 123, params["bob"]=456, etc.
13 // RegEx to split out values by &.
14 var r
= /([^&=]+)=?([^&]*)/g;
15 // Lambda function for decoding extracted match values. Replaces '+' with
16 // space so decodeURIComponent functions properly.
17 function d(s
) { return decodeURIComponent(s
.replace(/\+/g, ' ')); }
19 while (match
= r
.exec(window
.location
.search
.substring(1)))
20 params
[d(match
[1])] = d(match
[2]);
23 // Each network config = [DOWNLOAD_BANDWIDTH_Kbit/s, LATENCY_MS]
24 // Numbers are chosen to be similar to webpagereplay/net_configs.py
26 netConfig
['cable'] = [5120, 28];
27 netConfig
['dsl'] = [1536, 50];
28 netConfig
['wifi'] = [1024, 60];
29 netConfig
['none'] = null;
30 // Constrained network server URL.
31 var CNS_BASE_URL
= 'http://cns.chrome:9000/ServeConstrained?';
33 function getNetsimURL(net
) {
36 return CNS_BASE_URL
+ 'bandwidth=' + netConfig
[net
][0] +
37 '&latency=' + netConfig
[net
][1]
40 function getMediaSRC() {
41 var mediaSRC
= qsParams
['src']
43 return getNetsimURL(qsParams
['net']) + '&new_port=True' + '&f=' +
48 function canvas2dAnimation() {
49 canvasContext
.drawImage(testElement
, 0, 0, canvasElement
.width
, canvasElement
.height
);
50 window
.requestAnimationFrame(canvas2dAnimation
);
53 qsParams
= getQueryStrings();
54 var type
= qsParams
['type'] || 'video';
55 var testElement
= document
.createElement(type
);
58 testElement
.preload
= 'none';
59 testElement
.controls
= true;
61 testElement
.id
= qsParams
['id'];
62 testElement
.src
= getMediaSRC();
63 if (qsParams
['canvas'] && type
== 'video') {
64 canvasElement
= document
.createElement('canvas');
65 canvasElement
.width
= 800;
66 canvasElement
.height
= 450;
67 document
.body
.appendChild(canvasElement
);
68 canvasContext
= canvasElement
.getContext('2d');
69 window
.requestAnimationFrame(canvas2dAnimation
);
71 document
.body
.appendChild(testElement
);