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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/constructor/audiobuffersource.html

Issue 2834493004: Convert constructor/audiobuffersource.html to use new Audit (Closed)
Patch Set: Rebase 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Test Constructor: AudioBufferSource</title> 4 <title>Test Constructor: AudioBufferSource</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/audit-util.js"></script> 7 <script src="../resources/audit-util.js"></script>
8 <script src="../resources/audio-testing.js"></script> 8 <script src="../resources/audit.js"></script>
9 <script src="audionodeoptions.js"></script> 9 <script src="new-audionodeoptions.js"></script>
10 </head> 10 </head>
11 11
12 <body> 12 <body>
13 <script> 13 <script>
14 var context; 14 var context;
hongchan 2017/04/21 20:48:51 Please change all var to let.
Raymond Toy 2017/04/21 20:54:56 Done.
15 15
16 var audit = Audit.createTaskRunner(); 16 var audit = Audit.createTaskRunner();
17 17
18 audit.defineTask("initialize", function (taskDone) { 18 audit.define('initialize', (task, should) => {
19 Should("context = new OfflineAudioContext(...)", function () { 19 context = initializeContext(should);
20 context = new OfflineAudioContext(1, 1, 48000); 20 task.done();
21 }).notThrow();
22
23 taskDone();
24 }); 21 });
25 22
26 audit.defineTask("invalid constructor", function (taskDone) { 23 audit.define('invalid constructor', (task, should) => {
27 var node; 24 testInvalidConstructor(should, 'AudioBufferSourceNode', context);
28 var success = true; 25 task.done();
29
30 success = Should("new AudioBufferSourceNode()", function () {
31 node = new AudioBufferSourceNode();
32 }).throw("TypeError");
33 success = Should("new AudioBufferSourceNode(1)", function () {
34 node = new AudioBufferSourceNode(1) && success;
35 }).throw("TypeError");
36 success = Should("new AudioBufferSourceNode(c, 42)", function () {
37 node = new AudioBufferSourceNode(context, 42) && success;
38 }).throw("TypeError");
39
40 Should("Invalid constructors", success)
41 .summarize(
42 "correctly threw errors",
43 "did not throw errors in all cases");
44
45 taskDone();
46 }); 26 });
47 27
48 audit.defineTask("default constructor", function (taskDone) { 28 audit.define('default constructor', (task, should) => {
49 var node; 29 let prefix = 'node0';
50 var success = true; 30 let node =
31 testDefaultConstructor(should, 'AudioBufferSourceNode', context, {
32 prefix: prefix,
33 numberOfInputs: 0,
34 numberOfOutputs: 1,
35 channelCount: 2,
36 channelCountMode: 'max',
37 channelInterpretation: 'speakers'
38 });
51 39
52 success = Should("node = new AudioBufferSourceNode(c)", function () { 40 testDefaultAttributes(should, node, prefix, [
53 node = new AudioBufferSourceNode(context); 41 {name: 'buffer', value: null},
54 }).notThrow() && success; 42 {name: 'detune', value: 0},
43 {name: 'loop', value: false},
44 {name: 'loopEnd', value: 0.0},
45 {name: 'loopStart', value: 0.0},
46 {name: 'playbackRate', value: 1.0},
47 ]);
55 48
56 success = Should("node instanceof AudioBufferSourceNode", 49 task.done();
57 node instanceof AudioBufferSourceNode).beEqualTo(true) && success;
58
59 success = Should("node0.buffer === null", node.buffer === null)
60 .beEqualTo(true) && success;
61
62 // This node using the factory method is used as a reference for the
63 // defautl values.
64 var factoryNode = context.createBufferSource();
65
66 var testAttributes = ["buffer", "detune", "loop", "loopEnd", "loopStart" ,
67 "playbackRate"];
68
69 for (var index in testAttributes) {
70 var name = testAttributes[index];
71
72 if (node[name] instanceof AudioParam) {
73 success = Should("node0." + name + ".value", node[name].value)
74 .beEqualTo(factoryNode[name].value) && success;
75 } else {
76 success = Should("node0." + name, node[name])
77 .beEqualTo(factoryNode[name]) && success;
78 }
79 }
80
81 Should("AudioBufferSourceNode constructed", success)
82 .summarize("correctly", "incorrectly");
83
84 taskDone();
85 }); 50 });
86 51
87 audit.defineTask("nullable buffer", function (taskDone) { 52 audit.define('nullable buffer', (task, should) => {
88 var node; 53 var node;
89 var success = true; 54 var options = {buffer: null};
90 55
91 var options = { buffer: null }; 56 should(
92 57 () => {
93 success = Should("node1 = new AudioBufferSourceNode(c, " + JSON.stringif y(options), function () { 58 node = new AudioBufferSourceNode(context, options);
94 node = new AudioBufferSourceNode(context, options); 59 },
95 }).notThrow(); 60 'node1 = new AudioBufferSourceNode(c, ' + JSON.stringify(options))
61 .notThrow();
96 62
97 success = Should("node1.buffer", node.buffer) 63 should(node.buffer, 'node1.buffer').beEqualTo(null);
98 .beEqualTo(null);
99 64
100 Should("Null buffer in constructor handled", success) 65 task.done();
101 .summarize(
102 "correctly",
103 "incorrectly");
104
105 taskDone();
106 }); 66 });
107 67
108 audit.defineTask("constructor options", function (taskDone) { 68 audit.define('constructor options', (task, should) => {
109 var node; 69 var node;
110 var success = true;
111
112 var buffer = context.createBuffer(2, 1000, context.sampleRate); 70 var buffer = context.createBuffer(2, 1000, context.sampleRate);
113 71
114 var options = { 72 var options = {
115 buffer: buffer, 73 buffer: buffer,
116 detune: .5, 74 detune: .5,
117 loop: true, 75 loop: true,
118 loopEnd: (buffer.length / 2) / context.sampleRate, 76 loopEnd: (buffer.length / 2) / context.sampleRate,
119 loopStart: 5 / context.sampleRate, 77 loopStart: 5 / context.sampleRate,
120 playbackRate: .75 78 playbackRate: .75
121 }; 79 };
122 80
123 message = "node = new AudioBufferSourceNode(c, " + JSON.stringify(option s) + ")"; 81 message = 'node = new AudioBufferSourceNode(c, ' +
hongchan 2017/04/21 20:48:51 Add let. Otherwise this will be a global.
Raymond Toy 2017/04/21 20:54:56 Done.
82 JSON.stringify(options) + ')';
124 83
125 success = Should(message, function () { 84 should(() => {
126 node = new AudioBufferSourceNode(context, options); 85 node = new AudioBufferSourceNode(context, options);
127 }).notThrow(); 86 }, message).notThrow();
128 87
129 // Use the factory method to create an equivalent node and compare the 88 // Use the factory method to create an equivalent node and compare the
130 // results from the constructor against this node. 89 // results from the constructor against this node.
131 var factoryNode = context.createBufferSource(); 90 var factoryNode = context.createBufferSource();
132 factoryNode.buffer = options.buffer; 91 factoryNode.buffer = options.buffer;
133 factoryNode.detune.value = options.detune; 92 factoryNode.detune.value = options.detune;
134 factoryNode.loop = options.loop; 93 factoryNode.loop = options.loop;
135 factoryNode.loopEnd = options.loopEnd; 94 factoryNode.loopEnd = options.loopEnd;
136 factoryNode.loopStart = options.loopStart; 95 factoryNode.loopStart = options.loopStart;
137 factoryNode.playbackRate.value = options.playbackRate; 96 factoryNode.playbackRate.value = options.playbackRate;
138 97
139 success = Should("node2.buffer === buffer", node.buffer === buffer) 98 should(node.buffer === buffer, 'node2.buffer === buffer')
140 .beEqualTo(true) && success; 99 .beEqualTo(true);
141 success = Should("node2.detune.value", node.detune.value) 100 should(node.detune.value, 'node2.detune.value')
142 .beEqualTo(factoryNode.detune.value) && success; 101 .beEqualTo(factoryNode.detune.value);
143 success = Should("node2.loop", node.loop) 102 should(node.loop, 'node2.loop').beEqualTo(factoryNode.loop);
144 .beEqualTo(factoryNode.loop) && success; 103 should(node.loopEnd, 'node2.loopEnd').beEqualTo(factoryNode.loopEnd);
145 success = Should("node2.loopEnd", node.loopEnd) 104 should(node.loopStart, 'node2.loopStart')
146 .beEqualTo(factoryNode.loopEnd) && success; 105 .beEqualTo(factoryNode.loopStart);
147 success = Should("node2.loopStart", node.loopStart) 106 should(node.playbackRate.value, 'node2.playbackRate.value')
148 .beEqualTo(factoryNode.loopStart) && success; 107 .beEqualTo(factoryNode.playbackRate.value);
149 success = Should("node2.playbackRate.value", node.playbackRate.value)
150 .beEqualTo(factoryNode.playbackRate.value) && success;
151 108
152 Should("AudioBufferSource with options cosntructed", success) 109 task.done();
153 .summarize("correctly", "incorrectly");
154
155 taskDone();
156 }); 110 });
157 111
158 audit.runTasks(); 112 audit.run();
159 </script> 113 </script>
160 </body> 114 </body>
161 </html> 115 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698