Bug 950317 - enable WebRTC mochitest on b2g emulator. r=jesup,vicamo,jsmith.

This commit is contained in:
Shih-Chiang Chien 2014-01-10 19:39:18 +08:00
parent bb032ae59d
commit f25ed71e97
6 changed files with 216 additions and 54 deletions

View File

@ -0,0 +1,65 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
const { Services } = Cu.import('resource://gre/modules/Services.jsm');
var browser = Services.wm.getMostRecentWindow('navigator:browser');
var connection = browser.navigator.mozMobileConnections[0];
// provide a fake APN and enable data connection.
function enableDataConnection() {
let setLock = browser.navigator.mozSettings.createLock();
setLock.set({
'ril.data.enabled': true,
'ril.data.apnSettings': [
[
{'carrier':'T-Mobile US',
'apn':'epc.tmobile.com',
'mmsc':'http://mms.msg.eng.t-mobile.com/mms/wapenc',
'types':['default','supl','mms']}
]
]
});
}
// enable 3G radio
function enableRadio() {
if (connection.radioState !== 'enabled') {
connection.setRadioEnabled(true);
}
}
// disable 3G radio
function disableRadio() {
if (connection.radioState === 'enabled') {
connection.setRadioEnabled(false);
}
}
addMessageListener('prepare-network', function(message) {
//RIL DOM events will be pending until RIL receiveing system-message-listener-ready event.
Services.obs.notifyObservers(null, 'system-message-listener-ready', null);
connection.addEventListener('datachange', function onDataChange() {
if (connection.data.connected) {
connection.removeEventListener('datachange', onDataChange);
Services.prefs.setIntPref('network.proxy.type', 2);
sendAsyncMessage('network-ready', true);
}
});
enableRadio();
enableDataConnection();
});
addMessageListener('network-cleanup', function(message) {
connection.addEventListener('datachange', function onDataChange() {
if (!connection.data.connected) {
connection.removeEventListener('datachange', onDataChange);
Services.prefs.setIntPref('network.proxy.type', 2);
sendAsyncMessage('network-disabled', true);
}
});
disableRadio();
});

View File

@ -4,6 +4,7 @@ support-files =
mediaStreamPlayback.js
pc.js
templates.js
NetworkPreparationChromeScript.js
[test_dataChannel_basicAudio.html]
[test_dataChannel_basicAudioVideo.html]
@ -52,3 +53,5 @@ skip-if = os == 'mac'
[test_peerConnection_setRemoteOfferInHaveLocalOffer.html]
[test_peerConnection_throwInCallbacks.html]
[test_peerConnection_toJSON.html]
# Bug950317: Hack for making a cleanup hook after finishing all WebRTC cases
[test_zmedia_cleanup.html]

View File

@ -323,6 +323,75 @@ MediaElementChecker.prototype = {
}
};
/**
* Query function for determining if any IP address is available for
* generating SDP.
*
* @return false if required additional network setup.
*/
function isNetworkReady() {
// for gonk platform
if ("nsINetworkInterfaceListService" in SpecialPowers.Ci) {
var listService = SpecialPowers.Cc["@mozilla.org/network/interface-list-service;1"]
.getService(SpecialPowers.Ci.nsINetworkInterfaceListService);
var itfList = listService.getDataInterfaceList(
SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_MMS_INTERFACES |
SpecialPowers.Ci.nsINetworkInterfaceListService.LIST_NOT_INCLUDE_SUPL_INTERFACES);
var num = itfList.getNumberOfInterface();
for (var i = 0; i < num; i++) {
if (itfList.getInterface(i).ip) {
info("Network interface is ready with address: " + itfList.getInterface(i).ip);
return true;
}
}
// ip address is not available
info("Network interface is not ready, required additional network setup");
return false;
}
info("Network setup is not required");
return true;
}
/**
* Network setup utils for Gonk
*
* @return {object} providing functions for setup/teardown data connection
*/
function getNetworkUtils() {
var url = SimpleTest.getTestFileURL("NetworkPreparationChromeScript.js");
var script = SpecialPowers.loadChromeScript(url);
var utils = {
/**
* Utility for setting up data connection.
*
* @param aCallback callback after data connection is ready.
*/
prepareNetwork: function(aCallback) {
script.addMessageListener('network-ready', function (message) {
info("Network interface is ready");
aCallback();
});
info("Setup network interface");
script.sendAsyncMessage("prepare-network", true);
},
/**
* Utility for tearing down data connection.
*
* @param aCallback callback after data connection is closed.
*/
tearDownNetwork: function(aCallback) {
script.addMessageListener('network-disabled', function (message) {
ok(true, 'network-disabled');
script.destroy();
aCallback();
});
script.sendAsyncMessage("network-cleanup", true);
}
};
return utils;
}
/**
* This class handles tests for peer connections.
@ -349,6 +418,27 @@ function PeerConnectionTest(options) {
options.is_local = "is_local" in options ? options.is_local : true;
options.is_remote = "is_remote" in options ? options.is_remote : true;
var netTeardownCommand = null;
if (!isNetworkReady()) {
var utils = getNetworkUtils();
// Trigger network setup to obtain IP address before creating any PeerConnection.
utils.prepareNetwork(function() {
ok(isNetworkReady(),'setup network connection successfully');
});
netTeardownCommand = [
[
'TEARDOWN_NETWORK',
function(test) {
utils.tearDownNetwork(function() {
info('teardown network connection');
test.next();
});
}
]
];
}
if (options.is_local)
this.pcLocal = new PeerConnectionWrapper('pcLocal', options.config_pc1);
else
@ -370,6 +460,11 @@ function PeerConnectionTest(options) {
this.chain.filterOut(/^PC_REMOTE/);
}
// Insert network teardown after testcase execution.
if (netTeardownCommand) {
this.chain.append(netTeardownCommand);
}
var self = this;
this.chain.onFinished = function () {
self.teardown();

View File

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
if ("nsINetworkInterfaceListService" in SpecialPowers.Ci) {
var url = SimpleTest.getTestFileURL("NetworkPreparationChromeScript.js");
var script = SpecialPowers.loadChromeScript(url);
script.addMessageListener('network-disabled', function (message) {
ok(true, 'network-disabled');
script.destroy();
SimpleTest.finish();
});
script.sendAsyncMessage("network-cleanup", true);
} else {
ok(true, 'no need to cleanup network interface');
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>

View File

@ -301,33 +301,19 @@
"dom/imptests/editing/conformancetest/test_runtest.html":"takes too long",
"dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"bug 908473",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"",
"dom/media/tests/mochitest/test_dataChannel_noOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug822674.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug825703.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug827843.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug834153.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug835370.html":"",
"dom/media/tests/mochitest/test_peerConnection_errorCallbacks.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"Bug 962984, test fail on b2g debug build",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_bug827843.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
"dom/network/tests/test_networkstats_basics.html":"Will be fixed in bug 858005",
"dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",

View File

@ -288,33 +288,17 @@
"dom/imptests/editing/conformancetest/test_runtest.html":"takes too long",
"dom/media/tests/mochitest/test_dataChannel_basicAudio.html":"bug 908473",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicDataOnly.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"",
"dom/media/tests/mochitest/test_dataChannel_noOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_addCandidateInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"",
"dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug822674.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug825703.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug827843.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug834153.html":"",
"dom/media/tests/mochitest/test_peerConnection_bug835370.html":"",
"dom/media/tests/mochitest/test_peerConnection_errorCallbacks.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalAnswerInStable.html":"",
"dom/media/tests/mochitest/test_peerConnection_setLocalOfferInHaveRemoteOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInHaveRemoteOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteAnswerInStable.html":"",
"dom/media/tests/mochitest/test_peerConnection_setRemoteOfferInHaveLocalOffer.html":"",
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_dataChannel_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_dataChannel_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicAudioVideoCombined.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_basicVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_bug827843.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideoAudio.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/mochitest/test_peerConnection_throwInCallbacks.html":"Bug 960442, video support for WebRTC is disabled on b2g",
"dom/media/tests/ipc/test_ipc.html":"nested ipc not working",
"dom/permission/tests/test_permission_basics.html":"https not working, bug 907770",