| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test AudioContext.close() closes many contexts</title> | 4 <title>Test AudioContext.close() closes many contexts</title> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Test that closing a context releases the audio HW context"); | 13 let audit = Audit.createTaskRunner(); |
| 13 | 14 |
| 14 var context = null; | 15 let context = null; |
| 15 | 16 |
| 16 // The number of contexts we want to create and close. | 17 // The number of contexts we want to create and close. |
| 17 var MAX_ITERATION = 100; | 18 let MAX_ITERATION = 100; |
| 18 var counter = 0; | 19 let counter = 0; |
| 19 | 20 |
| 20 function createContextAndClose() { | 21 function createContextAndClose(task, should) { |
| 21 // Bypass the first iteration. | 22 // Bypass the first iteration. |
| 22 if (context) { | 23 if (context) { |
| 23 if (context.state != "closed") { | 24 should(context.state, "context.state for closed context " + counter) |
| 24 testFailed("Context " + counter + " was closed but state is not clos
ed: " + context.state); | 25 .beEqualTo("closed"); |
| 25 } | |
| 26 context = null; | 26 context = null; |
| 27 } | 27 } |
| 28 // Create new context and close. | 28 // Create new context and close. |
| 29 context = new AudioContext(); | 29 context = new AudioContext(); |
| 30 if (counter++ < MAX_ITERATION) { | 30 if (counter++ < MAX_ITERATION) { |
| 31 // Recursive promise resolution. | 31 // Recursive promise resolution. |
| 32 context.close().then(createContextAndClose, onFailure); | 32 context.close().then(function () { |
| 33 createContextAndClose(task, should); |
| 34 }, function () { |
| 35 onFailure(should); |
| 36 task.done(); |
| 37 }); |
| 33 } else { | 38 } else { |
| 34 context.close() | 39 context.close() |
| 35 .then(function () { | 40 .then(function () { |
| 36 testPassed("Successfully created and closed " + MAX_ITE
RATION + " contexts"); | 41 // |counter| is one more than MAX_ITERATION if we |
| 37 finishJSTest(); | 42 // succeeded. |
| 38 }); | 43 should(counter - 1, |
| 44 "Number of contexts successfully created and closed") |
| 45 .beEqualTo(MAX_ITERATION); |
| 46 task.done(); |
| 47 }); |
| 39 } | 48 } |
| 40 } | 49 } |
| 41 | 50 |
| 42 function onFailure(message) { | 51 function onFailure(should) { |
| 43 testFailed("Context " + counter + " failed to close"); | 52 should(context.state, "Context " + counter + "failed to close") |
| 44 finishJSTest(); | 53 .beEqualTo("closed"); |
| 45 } | 54 } |
| 46 | 55 |
| 47 // Initiate iteration. | 56 audit.define("test", function (task, should) { |
| 48 function runTest() { | 57 task.describe("Test that closing a context releases the audio HW context
"); |
| 49 window.jsTestIsAsync = true; | 58 createContextAndClose(task, should); |
| 50 createContextAndClose(); | 59 }); |
| 51 } | |
| 52 | 60 |
| 53 runTest(); | 61 audit.run(); |
| 54 </script> | 62 </script> |
| 55 </body> | 63 </body> |
| 56 </html> | 64 </html> |
| OLD | NEW |