Bug 1030002 - Part 2: Test cases for mobileconnection/mobilenetwork permission. r=hsinyi,khuey
authorEdgar Chen <echen@mozilla.com>
Tue, 01 Jul 2014 14:40:37 +0800
changeset 192746 2c0347b195387506cfb74bf30253681b5bdc6d8c
parent 192745 6a3b870e4341ecdc5803f9f9c3c041af1fe9e734
child 192747 92411b3dc302e3646512cf667ce6e81ac86dd7cc
push id7651
push usercbook@mozilla.com
push dateTue, 08 Jul 2014 13:28:32 +0000
treeherderfx-team@05cfda67b9db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi, khuey
bugs1030002
milestone33.0a1
Bug 1030002 - Part 2: Test cases for mobileconnection/mobilenetwork permission. r=hsinyi,khuey
dom/mobileconnection/moz.build
dom/mobileconnection/tests/marionette/test_mobile_last_known_network.js
dom/mobileconnection/tests/mochitest/mochitest.ini
dom/mobileconnection/tests/mochitest/test_mobileconnection_permission.html
dom/mobileconnection/tests/mochitest/test_mobilenetwork_permission.html
dom/mobileconnection/tests/moz.build
--- a/dom/mobileconnection/moz.build
+++ b/dom/mobileconnection/moz.build
@@ -1,7 +1,8 @@
 # -*- 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/.
 
 PARALLEL_DIRS += ['interfaces', 'src']
+TEST_DIRS += ['tests']
--- a/dom/mobileconnection/tests/marionette/test_mobile_last_known_network.js
+++ b/dom/mobileconnection/tests/marionette/test_mobile_last_known_network.js
@@ -5,9 +5,9 @@ MARIONETTE_TIMEOUT = 60000;
 MARIONETTE_HEAD_JS = "head.js";
 
 // Start tests
 startTestCommon(function() {
   // The emulator's hard coded operatoer's mcc and mnc codes.
   is(mobileConnection.lastKnownNetwork, "310-260");
   // The emulator's hard coded icc's mcc, mnc codes and spn.
   is(mobileConnection.lastKnownHomeNetwork, "310-260-Android");
-});
+}, ["mobilenetwork"]);
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/mochitest/mochitest.ini
@@ -0,0 +1,5 @@
+[DEFAULT]
+skip-if = toolkit != "gonk"
+
+[test_mobileconnection_permission.html]
+[test_mobilenetwork_permission.html]
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/mochitest/test_mobileconnection_permission.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/mochitest/test_mobilenetwork_permission.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/dom/mobileconnection/tests/moz.build
@@ -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']