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 qsParams
= getQueryStrings();
49 var type
= qsParams
['type'] || 'video';
50 var testElement
= document
.createElement(type
);
51 testElement
.preload
= 'none';
52 testElement
.controls
= true;
54 testElement
.id
= qsParams
['id'];
55 testElement
.src
= getMediaSRC();
56 document
.body
.appendChild(testElement
);