Bug 1030002 - Part 2: Test cases for mobileconnection/mobilenetwork permission. r=hsinyi,khuey

This commit is contained in:
Edgar Chen 2014-07-01 14:40:37 +08:00
parent 2158ea8ba4
commit 38083a1d29
6 changed files with 154 additions and 1 deletions

View File

@ -5,3 +5,4 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PARALLEL_DIRS += ['interfaces', 'src']
TEST_DIRS += ['tests']

View File

@ -10,4 +10,4 @@ startTestCommon(function() {
is(mobileConnection.lastKnownNetwork, "310-260");
// The emulator's hard coded icc's mcc, mnc codes and spn.
is(mobileConnection.lastKnownHomeNetwork, "310-260-Android");
});
}, ["mobilenetwork"]);

View File

@ -0,0 +1,5 @@
[DEFAULT]
skip-if = toolkit != "gonk"
[test_mobileconnection_permission.html]
[test_mobilenetwork_permission.html]

View File

@ -0,0 +1,70 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test to mobileconnection permission</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
"use strict";
if (!SpecialPowers.hasPermission("mobileconnection", document)) {
// Add "mobileconnection" permission and propagate it by reloading the page.
SpecialPowers.addPermission("mobileconnection", true, document);
window.location.reload();
} else if (SpecialPowers.hasPermission("mobilenetwork", document)) {
// Remove "mobilenetwork" permission and propagate it by reloading the page.
SpecialPowers.removePermission("mobilenetwork", document);
window.location.reload();
} else {
// Start test.
ok("mozMobileConnections" in navigator, "navigator.mozMobileConnections should be accessible for the content that has mobilenetwork permission.");
var mobileConnection = navigator.mozMobileConnections[0];
// Should not be accessible for the content that has mobileconnection permission.
is("lastKnownNetwork" in mobileConnection, false, "lastKnownNetwork");
is("lastKnownHomeNetwork" in mobileConnection, false, "lastKnownHomeNetwork");
// Should be accessible for the content that has mobileconnection permission.
is("voice" in mobileConnection, true, "voice");
is("data" in mobileConnection, true, "data");
is("iccId" in mobileConnection, true, "iccId");
is("networkSelectionMode" in mobileConnection, true, "networkSelectionMode");
is("radioState" in mobileConnection, true, "radioState");
is("supportedNetworkTypes" in mobileConnection, true, "supportedNetworkTypes");
is("getNetworks" in mobileConnection, true, "getNetworks");
is("selectNetwork" in mobileConnection, true, "selectNetwork");
is("selectNetworkAutomatically" in mobileConnection, true, "selectNetworkAutomatically");
is("setPreferredNetworkType" in mobileConnection, true, "setPreferredNetworkType");
is("getPreferredNetworkType" in mobileConnection, true, "getPreferredNetworkType");
is("setRoamingPreference" in mobileConnection, true, "setRoamingPreference");
is("getRoamingPreference" in mobileConnection, true, "getRoamingPreference");
is("setVoicePrivacyMode" in mobileConnection, true, "setVoicePrivacyMode");
is("getVoicePrivacyMode" in mobileConnection, true, "getVoicePrivacyMode");
is("sendMMI" in mobileConnection, true, "sendMMI");
is("cancelMMI" in mobileConnection, true, "cancelMMI");
is("setCallForwardingOption" in mobileConnection, true, "setCallForwardingOption");
is("getCallForwardingOption" in mobileConnection, true, "getCallForwardingOption");
is("setCallBarringOption" in mobileConnection, true, "setCallBarringOption");
is("getCallBarringOption" in mobileConnection, true, "getCallBarringOption");
is("changeCallBarringPassword" in mobileConnection, true, "changeCallBarringPassword");
is("setCallWaitingOption" in mobileConnection, true, "setCallWaitingOption");
is("getCallWaitingOption" in mobileConnection, true, "getCallWaitingOption");
is("setCallingLineIdRestriction" in mobileConnection, true, "setCallingLineIdRestriction");
is("getCallingLineIdRestriction" in mobileConnection, true, "getCallingLineIdRestriction");
is("exitEmergencyCbMode" in mobileConnection, true, "exitEmergencyCbMode");
is("setRadioEnabled" in mobileConnection, true, "setRadioEnabled");
}
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,70 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test to mobilenetwork permission</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
"use strict";
if (!SpecialPowers.hasPermission("mobilenetwork", document)) {
// Add "moiblenetwork" permission and propagate it by reloading the page.
SpecialPowers.addPermission("mobilenetwork", true, document);
window.location.reload();
} else if (SpecialPowers.hasPermission("mobileconnection", document)) {
// Remove "mobileconnection" permission and propagate it by reloading the page.
SpecialPowers.removePermission("mobileconnection", document);
window.location.reload();
} else {
// Start test.
ok("mozMobileConnections" in navigator, "navigator.mozMobileConnections should be accessible for the content that has mobilenetwork permission.");
var mobileConnection = navigator.mozMobileConnections[0];
// Should be accessible for the content that has mobilenetwork permission.
is("lastKnownNetwork" in mobileConnection, true, "lastKnownNetwork");
is("lastKnownHomeNetwork" in mobileConnection, true, "lastKnownHomeNetwork");
// Should not be accessible for the content that has mobilenetwork permission.
is("voice" in mobileConnection, false, "voice");
is("data" in mobileConnection, false, "data");
is("iccId" in mobileConnection, false, "iccId");
is("networkSelectionMode" in mobileConnection, false, "networkSelectionMode");
is("radioState" in mobileConnection, false, "radioState");
is("supportedNetworkTypes" in mobileConnection, false, "supportedNetworkTypes");
is("getNetworks" in mobileConnection, false, "getNetworks");
is("selectNetwork" in mobileConnection, false, "selectNetwork");
is("selectNetworkAutomatically" in mobileConnection, false, "selectNetworkAutomatically");
is("setPreferredNetworkType" in mobileConnection, false, "setPreferredNetworkType");
is("getPreferredNetworkType" in mobileConnection, false, "getPreferredNetworkType");
is("setRoamingPreference" in mobileConnection, false, "setRoamingPreference");
is("getRoamingPreference" in mobileConnection, false, "getRoamingPreference");
is("setVoicePrivacyMode" in mobileConnection, false, "setVoicePrivacyMode");
is("getVoicePrivacyMode" in mobileConnection, false, "getVoicePrivacyMode");
is("sendMMI" in mobileConnection, false, "sendMMI");
is("cancelMMI" in mobileConnection, false, "cancelMMI");
is("setCallForwardingOption" in mobileConnection, false, "setCallForwardingOption");
is("getCallForwardingOption" in mobileConnection, false, "getCallForwardingOption");
is("setCallBarringOption" in mobileConnection, false, "setCallBarringOption");
is("getCallBarringOption" in mobileConnection, false, "getCallBarringOption");
is("changeCallBarringPassword" in mobileConnection, false, "changeCallBarringPassword");
is("setCallWaitingOption" in mobileConnection, false, "setCallWaitingOption");
is("getCallWaitingOption" in mobileConnection, false, "getCallWaitingOption");
is("setCallingLineIdRestriction" in mobileConnection, false, "setCallingLineIdRestriction");
is("getCallingLineIdRestriction" in mobileConnection, false, "getCallingLineIdRestriction");
is("exitEmergencyCbMode" in mobileConnection, false, "exitEmergencyCbMode");
is("setRadioEnabled" in mobileConnection, false, "setRadioEnabled");
}
</script>
</pre>
</body>
</html>

View File

@ -0,0 +1,7 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
MOCHITEST_MANIFESTS += ['mochitest/mochitest.ini']