Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit b2c8b12

Browse files
Fix WebAudio init handling (#289)
* Fix WebAudio init handling * Add comment about resuming * Fix the test to work with newer chromedriver * 2nd try
1 parent 4eb734f commit b2c8b12

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/js/main.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@
66
* tree.
77
*/
88
'use strict';
9-
/* exported addExplicitTest, addTest, audioContext */
10-
11-
// Global WebAudio context that can be shared by all tests.
12-
// There is a very finite number of WebAudio contexts.
13-
try {
14-
window.AudioContext = window.AudioContext || window.webkitAudioContext;
15-
var audioContext = new AudioContext();
16-
} catch (e) {
17-
console.log('Failed to instantiate an audio context, error: ' + e);
18-
}
9+
/* exported addExplicitTest, addTest */
1910

2011
var enumeratedTestSuites = [];
2112
var enumeratedTestFilters = [];

src/js/mictest.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ function MicTest(test) {
4444
for (var i = 0; i < this.inputChannelCount; ++i) {
4545
this.collectedAudio[i] = [];
4646
}
47+
var AudioContext = window.AudioContext || window.webkitAudioContext;
48+
this.audioContext = new AudioContext();
4749
}
4850

4951
MicTest.prototype = {
5052
run: function() {
51-
if (typeof audioContext === 'undefined') {
52-
this.test.reportError('WebAudio is not supported, test cannot run.');
53+
// Resuming as per new spec after user interaction.
54+
this.audioContext.resume().then(function() {
55+
doGetUserMedia(this.constraints, this.gotStream.bind(this))
56+
}.bind(this))
57+
.catch(function(error) {
58+
this.test.reportError('WebAudio run failure: ' + error);
5359
this.test.done();
54-
} else {
55-
doGetUserMedia(this.constraints, this.gotStream.bind(this));
56-
}
60+
}.bind(this));
5761
},
5862

5963
gotStream: function(stream) {
@@ -77,11 +81,11 @@ MicTest.prototype = {
7781
},
7882

7983
createAudioBuffer: function() {
80-
this.audioSource = audioContext.createMediaStreamSource(this.stream);
81-
this.scriptNode = audioContext.createScriptProcessor(this.bufferSize,
84+
this.audioSource = this.audioContext.createMediaStreamSource(this.stream);
85+
this.scriptNode = this.audioContext.createScriptProcessor(this.bufferSize,
8286
this.inputChannelCount, this.outputChannelCount);
8387
this.audioSource.connect(this.scriptNode);
84-
this.scriptNode.connect(audioContext.destination);
88+
this.scriptNode.connect(this.audioContext.destination);
8589
this.scriptNode.onaudioprocess = this.collectAudio.bind(this);
8690
this.stopCollectingAudio = setTimeoutWithProgressBar(
8791
this.onStopCollectingAudio.bind(this), 5000);
@@ -124,7 +128,7 @@ MicTest.prototype = {
124128
onStopCollectingAudio: function() {
125129
this.stream.getAudioTracks()[0].stop();
126130
this.audioSource.disconnect(this.scriptNode);
127-
this.scriptNode.disconnect(audioContext.destination);
131+
this.scriptNode.disconnect(this.audioContext.destination);
128132
this.analyzeAudio(this.collectedAudio);
129133
this.test.done();
130134
},

src/ui/testrtc-main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ <h3>STUN</h3>
194194
onFail.apply(this, arguments);
195195
} else {
196196
reportFatal('Failed to get access to local media due to ' +
197-
'error: ' + error.name);
197+
'error: ' + error);
198198
}
199199
});
200200
} catch (e) {

test/sanity-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ test('Run TestRTC', function(t) {
2323
t.pass('Page loaded');
2424
})
2525
.then(function() {
26+
// Have to wait for the getUserMedia polymer element has been shown before clicking on the start button.
27+
driver.wait(webdriver.until.elementIsVisible(driver.findElement(
28+
webdriver.By.id('dialog'))))
29+
driver.wait(webdriver.until.elementIsNotVisible(driver.findElement(
30+
webdriver.By.id('dialog'))))
2631
return driver.wait(webdriver.until.elementLocated(
2732
webdriver.By.css('#startButton')), 10000,
2833
'Failed to locate startButton');

0 commit comments

Comments
 (0)