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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/automatic-pull-node.html

Issue 2591923002: Convert to use testharness.js (Closed)
Patch Set: Fix typo. Created 3 years, 12 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 2
3 <html> 3 <html>
4 <head> 4 <head>
5 <script src="../../resources/js-test.js"></script> 5 <script src="../../resources/testharness.js"></script>
6 <script src="../resources/compatibility.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 </head> 9 </head>
10 10
11 <body> 11 <body>
12 12
13 <div id="description"></div> 13 <script>
14 <div id="console"></div> 14 //description("This test verifies that the AudioBasicInspectorNode based nodes w ork correctly.");
hongchan 2016/12/22 17:41:07 A plain comment would be better since we're not us
Raymond Toy 2016/12/22 17:57:57 Oops. I meant to remove this. But a comment is bet
15 15
16 <script> 16 var audit = Audit.createTaskRunner();
17 description("This test verifies that the AudioBasicInspectorNode based nodes wor k correctly.");
18 17
19 var sampleRate = 44100.0; 18 var sampleRate = 44100.0;
20 // We carefully arrange the renderLengthInFrames to be a multiple of the AudioNo de rendering quantum (AudioNode::ProcessingSizeInFrames) 19 // We carefully arrange the renderLengthInFrames to be a multiple of the AudioNo de rendering quantum (AudioNode::ProcessingSizeInFrames)
21 // so that AudioSourceNode will not feed tailing zeroes into the context and fai l this test. 20 // so that AudioSourceNode will not feed tailing zeroes into the context and fai l this test.
22 var renderLengthInFrames = 256; 21 var renderLengthInFrames = 256;
23 var fftSize = 64; 22 var fftSize = 64;
24 23
25 var audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255. 24 var audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255.
26 var audioDataZero = 128; // Audio data 0 in Uint8 format will be 128. 25 var audioDataZero = 128; // Audio data 0 in Uint8 format will be 128.
27 26
28 var context; 27 var context;
29 var constantBuffer; 28 var constantBuffer;
30 var bufferSource; 29 var bufferSource;
31 var analyser; 30 var analyser;
32 31
33 function constructCommonGraph() { 32 function constructCommonGraph() {
34 // Create offline audio context. 33 // Create offline audio context.
35 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate); 34 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate);
36 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1); 35 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1);
37 36
38 bufferSource = context.createBufferSource(); 37 bufferSource = context.createBufferSource();
39 bufferSource.buffer = constantBuffer; 38 bufferSource.buffer = constantBuffer;
40 39
41 analyser = context.createAnalyser(); 40 analyser = context.createAnalyser();
42 analyser.fftSize = fftSize; 41 analyser.fftSize = fftSize;
43 42
44 bufferSource.connect(analyser); 43 bufferSource.connect(analyser);
45 } 44 }
46 45
47 function test1Finished() { 46 function test1Finished(should) {
48 var timeDomainData = new Uint8Array(fftSize); 47 var timeDomainData = new Uint8Array(fftSize);
49 analyser.getByteTimeDomainData(timeDomainData); 48 analyser.getByteTimeDomainData(timeDomainData);
50 49
51 if (timeDomainData[0] >= audioDataOne) 50 should(timeDomainData[0] >= audioDataOne,
52 testPassed("RealtimeAnalyserNode got pulled when connected from upstream node but not to downstream node."); 51 "RealtimeAnalyserNode got pulled when connected from upstream node but not to downstream node")
53 else 52 .beTrue();
54 testFailed("RealtimeAnalyserNode failed to get pulled when connected fro m upstream node but not to downstream node.");
55
56 test2();
57 } 53 }
58 54
59 // To verify the realtimeAnalyser can pull data when there is an upstream node c onnected to it 55 // To verify the realtimeAnalyser can pull data when there is an upstream node c onnected to it
60 // but it's not connected to a downstream node. 56 // but it's not connected to a downstream node.
61 function test1() { 57 audit.define("test1", function (task, should) {
62 constructCommonGraph(); 58 constructCommonGraph();
63 59
64 bufferSource.start(0); 60 bufferSource.start(0);
65 61
66 context.oncomplete = test1Finished; 62 context.startRendering()
67 context.startRendering(); 63 .then(test1Finished(should))
68 } 64 .then(task.done.bind(task));
65 });
69 66
70 function test2Finished() { 67 function test2Finished(should) {
71 var timeDomainData = new Uint8Array(fftSize); 68 var timeDomainData = new Uint8Array(fftSize);
72 analyser.getByteTimeDomainData(timeDomainData); 69 analyser.getByteTimeDomainData(timeDomainData);
73 70
74 if (timeDomainData[0] >= audioDataOne) 71 should(timeDomainData[0] >= audioDataOne,
75 testPassed("RealtimeAnalyserNode got pulled when connected from upstream node and to destination node."); 72 "RealtimeAnalyserNode got pulled when connected from upstream node and to destination node")
76 else 73 .beTrue();
77 testFailed("RealtimeAnalyserNode failed to be pulled when connected by u pstream node and to destination node.");
78
79 test3();
80 } 74 }
81 75
82 // To verify the realtimeAnalyser can process normally when there is an upstream node connected to it 76 // To verify the realtimeAnalyser can process normally when there is an upstream node connected to it
83 // and it's also connected to a downstream node which ultimately connect to audi o destination. 77 // and it's also connected to a downstream node which ultimately connect to audi o destination.
84 function test2() { 78 audit.define("test2", function (task, should) {
85 constructCommonGraph(); 79 constructCommonGraph();
86 80
87 analyser.connect(context.destination); 81 analyser.connect(context.destination);
88 82
89 bufferSource.start(0); 83 bufferSource.start(0);
90 84
91 context.oncomplete = test2Finished; 85 context.startRendering()
92 context.startRendering(); 86 .then(test2Finished(should))
93 } 87 .then(task.done.bind(task));
88 });
94 89
95 function test3Finished() { 90 function test3Finished(should) {
96 var timeDomainData = new Uint8Array(fftSize); 91 var timeDomainData = new Uint8Array(fftSize);
97 analyser.getByteTimeDomainData(timeDomainData); 92 analyser.getByteTimeDomainData(timeDomainData);
98 93
99 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0. 94 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0.
100 if (timeDomainData[0] == audioDataZero) 95 should(timeDomainData[0] == audioDataZero,
101 testPassed("RealtimeAnalyserNode didn't get pulled when it should not.") ; 96 "RealtimeAnalyserNode didn't get pulled when it should not")
102 else 97 .beTrue();;
103 testFailed("RealtimeAnalyserNode been pulled when it should not.");
104
105 finishJSTest();
106 } 98 }
107 99
108 // To verify the realtimeAnalyser will stop pulling if it is connected to a down stream node 100 // To verify the realtimeAnalyser will stop pulling if it is connected to a down stream node
109 // which is not ultimatly connected to any audio destination. 101 // which is not ultimatly connected to any audio destination.
110 function test3() { 102 audit.define("test3", function (task, should) {
111 constructCommonGraph(); 103 constructCommonGraph();
112 104
113 var gain = context.createGain(); 105 var gain = context.createGain();
114 analyser.connect(gain); 106 analyser.connect(gain);
115 107
116 bufferSource.start(0); 108 bufferSource.start(0);
117 109
118 context.oncomplete = test3Finished; 110 context.startRendering()
119 context.startRendering(); 111 .then(test3Finished(should))
120 } 112 .then(task.done.bind(task));
113 });
121 114
122 function runTest() { 115 audit.run();
123 if (window.testRunner) {
124 testRunner.dumpAsText();
125 testRunner.waitUntilDone();
126 }
127
128 window.jsTestIsAsync = true;
129
130 test1();
131 }
132
133 runTest();
134 116
135 </script> 117 </script>
136 118
137 </body> 119 </body>
138 </html> 120 </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