summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_WebAudioMemoryReporting.html
blob: 693e558304e5a149bd4a7bc75b2435589b959cc7 (plain)
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
<!DOCTYPE HTML>
<html>
<head>
  <title>Web Audio memory reporting</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

var ac = new AudioContext();
var sp = ac.createScriptProcessor(4096, 1, 1);
sp.connect(ac.destination);

// Not started so as to test
// https://bugzilla.mozilla.org/show_bug.cgi?id=1225003#c2
var oac = new OfflineAudioContext(1, 1, 48000);

var nodeTypes = ["ScriptProcessorNode", "AudioDestinationNode"];
var objectTypes = ["dom-nodes", "engine-objects", "track-objects"];

var usages = { "explicit/webaudio/audiocontext": 0 };

for (var i = 0; i < nodeTypes.length; ++i) {
  for (var j = 0; j < objectTypes.length; ++j) {
    usages["explicit/webaudio/audio-node/" +
           nodeTypes[i] + "/" + objectTypes[j]] = 0;
  }
}

var handleReport = function(aProcess, aPath, aKind, aUnits, aAmount, aDesc) {
  if (aPath in usages) {
    usages[aPath] += aAmount;
  }
}

var finished = function () {
  ok(true, "Yay didn't crash!");
  for (var resource in usages) {
    ok(usages[resource] > 0, "Non-zero usage for " + resource);
  };
  SimpleTest.finish();
}

SpecialPowers.Cc["@mozilla.org/memory-reporter-manager;1"].
  getService(SpecialPowers.Ci.nsIMemoryReporterManager).
  getReports(handleReport, null, finished, null, /* anonymized = */ false);

// To test bug 1225003, run a failing decodeAudioData() job over a time when
// the tasks from getReports() are expected to run.
ac.decodeAudioData(new ArrayBuffer(4), function(){}, function(){});
</script>
</html>