browser_webaudio-actor-destroy-node.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Test `destroy-node` event on WebAudioActor.
  5. */
  6. add_task(function* () {
  7. let { target, front } = yield initBackend(DESTROY_NODES_URL);
  8. let [, , created] = yield Promise.all([
  9. front.setup({ reload: true }),
  10. once(front, "start-context"),
  11. // Should create dest, gain, and oscillator node and 10
  12. // disposable buffer nodes
  13. getN(front, "create-node", 13)
  14. ]);
  15. let waitUntilDestroyed = getN(front, "destroy-node", 10);
  16. // Force CC so we can ensure it's run to clear out dead AudioNodes
  17. forceNodeCollection();
  18. let destroyed = yield waitUntilDestroyed;
  19. destroyed.forEach((node, i) => {
  20. ok(node.type, "AudioBufferSourceNode", "Only buffer nodes are destroyed");
  21. ok(actorIsInList(created, destroyed[i]),
  22. "`destroy-node` called only on AudioNodes in current document.");
  23. });
  24. yield removeTab(target.tab);
  25. });
  26. function actorIsInList(list, actor) {
  27. for (let i = 0; i < list.length; i++) {
  28. if (list[i].actorID === actor.actorID)
  29. return list[i];
  30. }
  31. return null;
  32. }