1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<!DOCTYPE HTML>
<html>
<head>
<title>Telemetry : test permanent probe MSE_SOURCE_BUFFER_TYPE</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/**
* This test is used for the permanent Telemetry probe MSE_SOURCE_BUFFER_TYPE.
* which is used to measure the usage of mime type used in MSE.
*/
const VIDEO_WEBM = "video/webm";
const AUDIO_WEBM = "audio/webm";
const VIDEO_MP4 = "video/mp4";
const AUDIO_MP4 = "audio/mp4";
const VIDEO_MP2T = "video/mp2t";
const AUDIO_MP2T = "audio/mp2t";
const AUDIO_MP3 = "audio/mpeg";
const AUDIO_AAC = "audio/aac";
// The order follows `MSE_SOURCE_BUFFER_TYPE` in `Histogram.json`.
const gLabelNames = [VIDEO_WEBM, AUDIO_WEBM, VIDEO_MP4, AUDIO_MP4,
VIDEO_MP2T, AUDIO_MP2T, AUDIO_MP3, AUDIO_AAC];
add_task(async function setTestPref() {
await SpecialPowers.pushPrefEnv({
set: [["media.testing-only-events", true]]});
});
add_task(async function testSourceBufferTypeProbe() {
for (let label of gLabelNames) {
info(`calling 'isTypeSupported()' should increase the probe value`);
MediaSource.isTypeSupported(label);
assertLabelValueEqualTo(label, 1);
info(`calling 'addSourceBuffer()' should increase the probe value`);
try {
const source = new MediaSource();
source.addSourceBuffer(label);
} catch (e) {
info(`ignore error for unsupported type ${label}`);
}
assertLabelValueEqualTo(label, 2);
}
});
/**
* Following are helper functions
*/
async function assertLabelValueEqualTo(labelName, value) {
const hist = SpecialPowers.Services.telemetry.getHistogramById("MSE_SOURCE_BUFFER_TYPE");
/**
* Histogram's snapshot looks like that
* {
* "bucket_count": X,
* "histogram_type": Y,
* "sum": Z,
* "range": [min, max],
* "values": { "value1" : "num1", "value2" : "num2", ...}
* }
*/
if (!gLabelNames.includes(labelName)) {
ok(false, `undefined label name=${labelName}`);
return;
}
const labelIdx = gLabelNames.indexOf(labelName);
is(hist.snapshot().values[labelIdx], value, `${labelName} equal to ${value}`);
}
</script>
</head>
<body>
</body>
</html>
|