Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audiocontextoptions.html

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: Refactor audiocontextoptions LayoutTest. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Test AudioContextOptions</title> 4 <title>Test AudioContextOptions</title>
5 <script src="../resources/testharness.js"></script> 5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script> 6 <script src="../resources/testharnessreport.js"></script>
7 <script src="resources/audio-testing.js"></script> 7 <script src="resources/audit.js"></script>
8 </head> 8 </head>
9 9
10 <body> 10 <body>
11 <script> 11 <script>
12 var context; 12 let context;
13 var audit = Audit.createTaskRunner(); 13 let defaultLatency;
14 let interactiveLatency;
15 let balancedLatency;
16 let playbackLatency;
14 17
15 // Task: test AudioContextOptions (1). 18 let audit = Audit.createTaskRunner();
16 audit.defineTask('test-audiocontextoptions-1', function (done) {
17 19
18 // Verify that an AudioContext can be created with default options. 20 audit.define(
19 Should("context = new AudioContext()", function () { 21 {
20 context = new AudioContext(); 22 label : "test-audiocontextoptions-latencyHint-basic",
21 }).notThrow(); 23 description : "Test creating contexts with basic latencyHint types."
24 },
25 function(task, should) {
26 let closingPromises = [];
22 27
23 var defaultLatency = context.baseLatency; 28 // Verify that an AudioContext can be created with default options.
24 Should("default baseLatency", defaultLatency).beGreaterThan(0); 29 should(function(){context = new AudioContext()},
30 "context = new AudioContext()")
31 .notThrow();
25 32
26 // Verify that any double can be passed and that it results in interactive latency 33 defaultLatency = context.baseLatency;
27 Should("context = new AudioContext({'latencyHint': 0.05})", function () { 34 should(defaultLatency, "default baseLatency").beGreaterThan(0);
28 context = new AudioContext({'latencyHint': 0.05});
29 }).notThrow();
30 Should("double-constructor baseLatency", context.baseLatency).beEqualTo(de faultLatency);
31 35
32 // Verify that an AudioContext can be created with the expected latency ty pes. 36 // Verify that an AudioContext can be created with the expected
33 Should("context = new AudioContext({'latencyHint': 'interactive'})", funct ion () { 37 // latency types.
34 context = new AudioContext({'latencyHint': 'interactive'}); 38 should(function(){context = new AudioContext(
35 }).notThrow(); 39 {'latencyHint' : 'interactive'})},
40 "context = new AudioContext({'latencyHint': 'interactive'})")
41 .notThrow();
36 42
37 var interactiveLatency = context.baseLatency; 43 interactiveLatency = context.baseLatency;
38 Should("interactive baseLatency", interactiveLatency).beEqualTo(defaultLat ency); 44 should(interactiveLatency, "interactive baseLatency")
45 .beEqualTo(defaultLatency);
46 closingPromises.push(context.close());
39 47
40 Should("context = new AudioContext({'latencyHint': 'balanced'})", function () { 48 should(function(){context =
41 context = new AudioContext({'latencyHint': 'balanced'}); 49 new AudioContext({'latencyHint' : 'balanced'})},
42 }).notThrow(); 50 "context = new AudioContext({'latencyHint': 'balanced'})")
51 .notThrow();
43 52
44 var balancedLatency = context.baseLatency; 53 balancedLatency = context.baseLatency;
45 Should("balanced baseLatency", balancedLatency).beGreaterThanOrEqualTo(int eractiveLatency); 54 should(balancedLatency, "balanced baseLatency")
55 .beGreaterThanOrEqualTo(interactiveLatency);
56 closingPromises.push(context.close());
46 57
47 Should("context = new AudioContext({'latencyHint': 'playback'})", function () { 58 should(function(){context =
48 context = new AudioContext({'latencyHint': 'playback'}); 59 new AudioContext({'latencyHint' : 'playback'})},
49 }).notThrow(); 60 "context = new AudioContext({'latencyHint': 'playback'})")
61 .notThrow();
50 62
51 var playbackLatency = context.baseLatency; 63 playbackLatency = context.baseLatency;
52 Should("playback baseLatency", playbackLatency).beGreaterThanOrEqualTo(bal ancedLatency); 64 should(playbackLatency, "playback baseLatency")
65 .beGreaterThanOrEqualTo(balancedLatency);
66 closingPromises.push(context.close());
53 67
54 // Verify that invalid latencyHint values are rejected. 68 Promise.all(closingPromises).then(function() { task.done(); });
55 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { 69 });
56 context = new AudioContext({'latencyHint': 'foo'});
57 }).throw("TypeError");
58 70
59 // Verify that no extra options can be passed into the AudioContextOptions . 71 audit.define(
60 Should("context = new AudioContext('latencyHint')", function () { 72 {
61 context = new AudioContext('latencyHint'); 73 label : "test-audiocontextoptions-latencyHint-double",
62 }).throw("TypeError"); 74 description :
75 "Test creating contexts with explicit latencyHint values."
76 },
77 function(task, should) {
78 var closingPromises = [];
63 79
64 done(); 80 // Verify too small exact latency clamped to 'interactive'
65 }); 81 should(function(){context = new AudioContext(
82 {'latencyHint' : interactiveLatency / 2})},
83 "context = new AudioContext({'latencyHint': " +
84 "interactiveLatency/2})")
85 .notThrow();
86 should(context.baseLatency, "double-constructor baseLatency small")
87 .beEqualTo(interactiveLatency);
88 closingPromises.push(context.close());
66 89
67 audit.runTasks(); 90 // Verify that exact latency in range works as expected
91 var validLatency = (interactiveLatency + playbackLatency) / 2;
92 should(function(){context = new AudioContext(
93 {'latencyHint' : validLatency})},
94 "context = new AudioContext({'latencyHint': validLatency})")
95 .notThrow();
96 should(context.baseLatency,
97 "double-constructor baseLatency inrange 1")
98 .beGreaterThanOrEqualTo(interactiveLatency);
99 should(context.baseLatency,
100 "double-constructor baseLatency inrange 2")
101 .beLessThanOrEqualTo(playbackLatency);
102 closingPromises.push(context.close());
103
104 // Verify too big exact latency clamped to some value
105 var context1;
106 var context2;
107 should(
108 function() {
109 context1 =
110 new AudioContext({'latencyHint' : playbackLatency * 10});
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
121 // Verify that invalid latencyHint values are rejected.
122 should(
123 function(){context = new AudioContext({'latencyHint' : 'foo'})},
124 "context = new AudioContext({'latencyHint': 'foo'})")
125 .throw("TypeError");
126
127 // Verify that no extra options can be passed into the
128 // AudioContextOptions.
129 should(function(){context = new AudioContext('latencyHint')},
130 "context = new AudioContext('latencyHint')")
131 .throw("TypeError");
132
133 Promise.all(closingPromises).then(function() { task.done(); });
134 });
135
136 audit.run();
68 </script> 137 </script>
69 </body> 138 </body>
70 </html> 139 </html>
OLDNEW
« no previous file with comments | « media/base/audio_latency.cc ('k') | third_party/WebKit/Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698