| OLD | NEW |
| 1 <!doctype html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test AudioContextOptions</title> | 4 <title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 Test AudioContextOptions |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 </title> |
| 7 <script src="../resources/audit.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
| 8 </head> | 8 <script src="../../resources/testharnessreport.js"></script> |
| 9 <script src="../resources/audit.js"></script> |
| 10 </head> |
| 11 <body> |
| 12 <script id="layout-test-code"> |
| 13 let context; |
| 14 let defaultLatency; |
| 15 let interactiveLatency; |
| 16 let balancedLatency; |
| 17 let playbackLatency; |
| 9 | 18 |
| 10 <body> | 19 let audit = Audit.createTaskRunner(); |
| 11 <script> | |
| 12 let context; | |
| 13 let defaultLatency; | |
| 14 let interactiveLatency; | |
| 15 let balancedLatency; | |
| 16 let playbackLatency; | |
| 17 | 20 |
| 18 let audit = Audit.createTaskRunner(); | 21 audit.define( |
| 22 { |
| 23 label: 'test-audiocontextoptions-latencyHint-basic', |
| 24 description: 'Test creating contexts with basic latencyHint types.' |
| 25 }, |
| 26 function(task, should) { |
| 27 let closingPromises = []; |
| 19 | 28 |
| 20 audit.define( | 29 // Verify that an AudioContext can be created with default options. |
| 21 { | 30 should(function() { |
| 22 label : "test-audiocontextoptions-latencyHint-basic", | 31 context = new AudioContext() |
| 23 description : "Test creating contexts with basic latencyHint types." | 32 }, 'context = new AudioContext()').notThrow(); |
| 24 }, | |
| 25 function(task, should) { | |
| 26 let closingPromises = []; | |
| 27 | 33 |
| 28 // Verify that an AudioContext can be created with default options. | 34 defaultLatency = context.baseLatency; |
| 29 should(function(){context = new AudioContext()}, | 35 should(defaultLatency, 'default baseLatency').beGreaterThan(0); |
| 30 "context = new AudioContext()") | |
| 31 .notThrow(); | |
| 32 | 36 |
| 33 defaultLatency = context.baseLatency; | 37 // Verify that an AudioContext can be created with the expected |
| 34 should(defaultLatency, "default baseLatency").beGreaterThan(0); | 38 // latency types. |
| 39 should( |
| 40 function() { |
| 41 context = new AudioContext({'latencyHint': 'interactive'}) |
| 42 }, |
| 43 'context = new AudioContext({\'latencyHint\': \'interactive\'})'
) |
| 44 .notThrow(); |
| 35 | 45 |
| 36 // Verify that an AudioContext can be created with the expected | 46 interactiveLatency = context.baseLatency; |
| 37 // latency types. | 47 should(interactiveLatency, 'interactive baseLatency') |
| 38 should(function(){context = new AudioContext( | 48 .beEqualTo(defaultLatency); |
| 39 {'latencyHint' : 'interactive'})}, | 49 closingPromises.push(context.close()); |
| 40 "context = new AudioContext({'latencyHint': 'interactive'})") | |
| 41 .notThrow(); | |
| 42 | 50 |
| 43 interactiveLatency = context.baseLatency; | 51 should( |
| 44 should(interactiveLatency, "interactive baseLatency") | 52 function() { |
| 45 .beEqualTo(defaultLatency); | 53 context = new AudioContext({'latencyHint': 'balanced'}) |
| 46 closingPromises.push(context.close()); | 54 }, |
| 55 'context = new AudioContext({\'latencyHint\': \'balanced\'})') |
| 56 .notThrow(); |
| 47 | 57 |
| 48 should(function(){context = | 58 balancedLatency = context.baseLatency; |
| 49 new AudioContext({'latencyHint' : 'balanced'})}, | 59 should(balancedLatency, 'balanced baseLatency') |
| 50 "context = new AudioContext({'latencyHint': 'balanced'})") | 60 .beGreaterThanOrEqualTo(interactiveLatency); |
| 51 .notThrow(); | 61 closingPromises.push(context.close()); |
| 52 | 62 |
| 53 balancedLatency = context.baseLatency; | 63 should( |
| 54 should(balancedLatency, "balanced baseLatency") | 64 function() { |
| 55 .beGreaterThanOrEqualTo(interactiveLatency); | 65 context = new AudioContext({'latencyHint': 'playback'}) |
| 56 closingPromises.push(context.close()); | 66 }, |
| 67 'context = new AudioContext({\'latencyHint\': \'playback\'})') |
| 68 .notThrow(); |
| 57 | 69 |
| 58 should(function(){context = | 70 playbackLatency = context.baseLatency; |
| 59 new AudioContext({'latencyHint' : 'playback'})}, | 71 should(playbackLatency, 'playback baseLatency') |
| 60 "context = new AudioContext({'latencyHint': 'playback'})") | 72 .beGreaterThanOrEqualTo(balancedLatency); |
| 61 .notThrow(); | 73 closingPromises.push(context.close()); |
| 62 | 74 |
| 63 playbackLatency = context.baseLatency; | 75 Promise.all(closingPromises).then(function() { |
| 64 should(playbackLatency, "playback baseLatency") | 76 task.done(); |
| 65 .beGreaterThanOrEqualTo(balancedLatency); | 77 }); |
| 66 closingPromises.push(context.close()); | 78 }); |
| 67 | 79 |
| 68 Promise.all(closingPromises).then(function() { task.done(); }); | 80 audit.define( |
| 69 }); | 81 { |
| 82 label: 'test-audiocontextoptions-latencyHint-double', |
| 83 description: |
| 84 'Test creating contexts with explicit latencyHint values.' |
| 85 }, |
| 86 function(task, should) { |
| 87 let closingPromises = []; |
| 70 | 88 |
| 71 audit.define( | 89 // Verify too small exact latency clamped to 'interactive' |
| 72 { | 90 should( |
| 73 label : "test-audiocontextoptions-latencyHint-double", | 91 function() { |
| 74 description : | 92 context = |
| 75 "Test creating contexts with explicit latencyHint values." | 93 new AudioContext({'latencyHint': interactiveLatency / 2}) |
| 76 }, | 94 }, |
| 77 function(task, should) { | 95 'context = new AudioContext({\'latencyHint\': ' + |
| 78 var closingPromises = []; | 96 'interactiveLatency/2})') |
| 97 .notThrow(); |
| 98 should(context.baseLatency, 'double-constructor baseLatency small') |
| 99 .beEqualTo(interactiveLatency); |
| 100 closingPromises.push(context.close()); |
| 79 | 101 |
| 80 // Verify too small exact latency clamped to 'interactive' | 102 // Verify that exact latency in range works as expected |
| 81 should(function(){context = new AudioContext( | 103 let validLatency = (interactiveLatency + playbackLatency) / 2; |
| 82 {'latencyHint' : interactiveLatency / 2})}, | 104 should( |
| 83 "context = new AudioContext({'latencyHint': " + | 105 function() { |
| 84 "interactiveLatency/2})") | 106 context = new AudioContext({'latencyHint': validLatency}) |
| 85 .notThrow(); | 107 }, |
| 86 should(context.baseLatency, "double-constructor baseLatency small") | 108 'context = new AudioContext({\'latencyHint\': validLatency})') |
| 87 .beEqualTo(interactiveLatency); | 109 .notThrow(); |
| 88 closingPromises.push(context.close()); | 110 should( |
| 111 context.baseLatency, 'double-constructor baseLatency inrange 1') |
| 112 .beGreaterThanOrEqualTo(interactiveLatency); |
| 113 should( |
| 114 context.baseLatency, 'double-constructor baseLatency inrange 2') |
| 115 .beLessThanOrEqualTo(playbackLatency); |
| 116 closingPromises.push(context.close()); |
| 89 | 117 |
| 90 // Verify that exact latency in range works as expected | 118 // Verify too big exact latency clamped to some value |
| 91 var validLatency = (interactiveLatency + playbackLatency) / 2; | 119 let context1; |
| 92 should(function(){context = new AudioContext( | 120 let context2; |
| 93 {'latencyHint' : validLatency})}, | 121 should(function() { |
| 94 "context = new AudioContext({'latencyHint': validLatency})") | 122 context1 = |
| 95 .notThrow(); | 123 new AudioContext({'latencyHint': playbackLatency * 10}); |
| 96 should(context.baseLatency, | 124 context2 = |
| 97 "double-constructor baseLatency inrange 1") | 125 new AudioContext({'latencyHint': playbackLatency * 20}); |
| 98 .beGreaterThanOrEqualTo(interactiveLatency); | 126 }, 'creating two high latency contexts').notThrow(); |
| 99 should(context.baseLatency, | 127 should(context1.baseLatency, 'high latency context baseLatency') |
| 100 "double-constructor baseLatency inrange 2") | 128 .beEqualTo(context2.baseLatency); |
| 101 .beLessThanOrEqualTo(playbackLatency); | 129 closingPromises.push(context1.close()); |
| 102 closingPromises.push(context.close()); | 130 closingPromises.push(context2.close()); |
| 103 | 131 |
| 104 // Verify too big exact latency clamped to some value | 132 // Verify that invalid latencyHint values are rejected. |
| 105 var context1; | 133 should( |
| 106 var context2; | 134 function() { |
| 107 should( | 135 context = new AudioContext({'latencyHint': 'foo'}) |
| 108 function() { | 136 }, |
| 109 context1 = | 137 'context = new AudioContext({\'latencyHint\': \'foo\'})') |
| 110 new AudioContext({'latencyHint' : playbackLatency * 10}); | 138 .throw('TypeError'); |
| 111 context2 = | |
| 112 new AudioContext({'latencyHint' : playbackLatency * 20}); | |
| 113 }, | |
| 114 "creating two high latency contexts") | |
| 115 .notThrow(); | |
| 116 should(context1.baseLatency, "high latency context baseLatency") | |
| 117 .beEqualTo(context2.baseLatency); | |
| 118 closingPromises.push(context1.close()); | |
| 119 closingPromises.push(context2.close()); | |
| 120 | 139 |
| 121 // Verify that invalid latencyHint values are rejected. | 140 // Verify that no extra options can be passed into the |
| 122 should( | 141 // AudioContextOptions. |
| 123 function(){context = new AudioContext({'latencyHint' : 'foo'})}, | 142 should( |
| 124 "context = new AudioContext({'latencyHint': 'foo'})") | 143 function() { |
| 125 .throw("TypeError"); | 144 context = new AudioContext('latencyHint') |
| 145 }, |
| 146 'context = new AudioContext(\'latencyHint\')') |
| 147 .throw('TypeError'); |
| 126 | 148 |
| 127 // Verify that no extra options can be passed into the | 149 Promise.all(closingPromises).then(function() { |
| 128 // AudioContextOptions. | 150 task.done(); |
| 129 should(function(){context = new AudioContext('latencyHint')}, | 151 }); |
| 130 "context = new AudioContext('latencyHint')") | 152 }); |
| 131 .throw("TypeError"); | |
| 132 | 153 |
| 133 Promise.all(closingPromises).then(function() { task.done(); }); | 154 audit.run(); |
| 134 }); | 155 </script> |
| 135 | 156 </body> |
| 136 audit.run(); | |
| 137 </script> | |
| 138 </body> | |
| 139 </html> | 157 </html> |
| OLD | NEW |