Bug 707659 - Part 2: fix test scripts, r=philikon
authorVicamo Yang <vyang@mozilla.com>
Thu, 23 Aug 2012 01:30:40 +0800
changeset 105078 c5ca56e666683e5c96a1c89fc9e3d420200a9637
parent 105077 b87b0846c9137de02fdf9a0e8e1db19231cf3098
child 105079 c29869656f46a7c3dc14854b40294664d47687cb
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersphilikon
bugs707659
milestone17.0a1
Bug 707659 - Part 2: fix test scripts, r=philikon
dom/sms/tests/marionette/test_between_emulators.py
dom/sms/tests/marionette/test_incoming.js
dom/sms/tests/test_sms_basics.html
testing/marionette/client/marionette/marionette_test.py
--- a/dom/sms/tests/marionette/test_between_emulators.py
+++ b/dom/sms/tests/marionette/test_between_emulators.py
@@ -6,27 +6,27 @@ class SMSTest(MarionetteTestCase):
     @unittest.expectedFailure
     def test_sms_between_emulators(self):
         # Tests always have one emulator available as self.marionette; we'll
         # use this for the receiving emulator.  We'll also launch a second
         # emulator to use as the sender.
         sender = self.get_new_emulator()
         receiver = self.marionette
 
-        self.set_up_test_page(sender, "test.html", ["dom.sms.whitelist"])
-        self.set_up_test_page(receiver, "test.html", ["dom.sms.whitelist"])
+        self.set_up_test_page(sender, "test.html", ["sms"])
+        self.set_up_test_page(receiver, "test.html", ["sms"])
 
         # Setup the event listsener on the receiver, which should store
         # a global variable when an SMS is received.
         message = 'hello world!'
         self.assertTrue(receiver.execute_script("return window.navigator.mozSms != null;"))
         receiver.execute_script("""
 global.smsreceived = null;
 window.navigator.mozSms.addEventListener("received", function(e) {
-    global.smsreceived = e.message;
+    global.smsreceived = e.message.body;
 });
 """, new_sandbox=False)
 
         # Send the SMS from the sender.
         sender.execute_script("""
 window.navigator.mozSms.send("%d", "%s");
 """ % (receiver.emulator.port, message))
 
--- a/dom/sms/tests/marionette/test_incoming.js
+++ b/dom/sms/tests/marionette/test_incoming.js
@@ -1,16 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 MARIONETTE_TIMEOUT = 10000;
 
-const WHITELIST_PREF = "dom.sms.whitelist";
-let uriPrePath = window.location.protocol + "//" + window.location.host;
-SpecialPowers.setCharPref(WHITELIST_PREF, uriPrePath);
+SpecialPowers.setBoolPref("dom.sms.enabled", true);
+SpecialPowers.addPermission("sms", true, document);
 
 let sms = window.navigator.mozSms;
 let sender = "5555552368";
 let body = "Hello SMS world!";
 let now = Date.now();
 
 let completed = false;
 runEmulatorCmd("sms send " + sender + " " + body, function(result) {
@@ -37,11 +36,11 @@ sms.onreceived = function onreceived(eve
 };
 
 function cleanUp() {
   if (!completed) {
     window.setTimeout(cleanUp, 100);
     return;
   }
 
-  SpecialPowers.clearUserPref(WHITELIST_PREF);
+  SpecialPowers.removePermission("sms", document);
   finish();
 }
--- a/dom/sms/tests/test_sms_basics.html
+++ b/dom/sms/tests/test_sms_basics.html
@@ -12,21 +12,21 @@
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for WebSMS **/
 
 function checkSmsDisabled() {
   ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
-  is(navigator.mozSms, null, "navigator.mozSms should return null");
+  is(frames[0].navigator.mozSms, null, "navigator.mozSms should return null");
 }
 
 function checkSmsEnabled() {
-  // WebSms is disabled on all platforms except Android for the moment.
+  // Bug 784617: WebSms is disabled on all platforms except Android for the moment.
   if (navigator.appVersion.indexOf("Android") == -1) {
     checkSmsDisabled();
     return;
   }
 
   ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
   ok(frames[0].navigator.mozSms, "navigator.mozSms returns an object");
   ok(frames[0].navigator.mozSms instanceof MozSmsManager, "navigator.mozSms is an SmsManager object");
@@ -34,52 +34,43 @@ function checkSmsEnabled() {
 
 function checkInterface(aInterface) {
   ok(!(aInterface in window), aInterface + " should be prefixed");
   ok(("Moz" + aInterface) in window, aInterface + " should be prefixed");
 }
 
 function test() {
   var gSmsEnabled = SpecialPowers.getBoolPref("dom.sms.enabled");
-  var gSmsWhiteList = SpecialPowers.getCharPref("dom.sms.whitelist");
 
   checkInterface("SmsManager");
   checkInterface("NavigatorSms");
   checkInterface("SmsMessage");
   checkInterface("SmsEvent");
   checkInterface("SmsRequest");
   checkInterface("SmsFilter");
   checkInterface("SmsCursor");
 
-  // If sms are disabled and whitelist is empty, sms is disabled.
+  // If sms is disabled and permission is removed, sms is disabled.
   SpecialPowers.setBoolPref("dom.sms.enabled", false);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "");
-  checkSmsDisabled();
-
-  // If sms are enabled and whitelist is empty, sms are disabled.
-  SpecialPowers.setBoolPref("dom.sms.enabled", true);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "");
+  SpecialPowers.removePermission("sms", document);
   checkSmsDisabled();
 
-  // If sms are disabled and whitelist contains the current URL prepath,
-  // sms are disabled.
-  SpecialPowers.setBoolPref("dom.sms.enabled", false);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "http://mochi.test:8888");
+  // If sms is enabled and permission is removed, sms is disabled.
+  SpecialPowers.setBoolPref("dom.sms.enabled", true);
+  SpecialPowers.removePermission("sms", document);
   checkSmsDisabled();
 
-  // If sms are enabled and whitelist contains something else than the current
-  // URL prepath, sms are disabled.
-  SpecialPowers.setBoolPref("dom.sms.enabled", true);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "http://foo.mochi.test:8888");
+  // If sms is disabled and permission is granted, sms is disabled.
+  SpecialPowers.setBoolPref("dom.sms.enabled", false);
+  SpecialPowers.addPermission("sms", true, document);
   checkSmsDisabled();
 
-  // If sms are enabled and whitelist contains the current URL prepath,
-  // sms are enabled.
+  // If sms is enabled and permission is granted, sms is enabled.
   SpecialPowers.setBoolPref("dom.sms.enabled", true);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "http://mochi.test:8888");
+  SpecialPowers.addPermission("sms", true, document);
   checkSmsEnabled();
 
   // Now, if sms are disabled with the pref, they will still be enabled.
   // The page has to be reloaded.
   SpecialPowers.setBoolPref("dom.sms.enabled", false);
   checkSmsEnabled();
 
   var iframeElt = document.getElementsByTagName('iframe')[0];
@@ -91,25 +82,23 @@ function test() {
     SpecialPowers.setBoolPref("dom.sms.enabled", false);
     iframeElt.addEventListener("load", function() {
       iframeElt.removeEventListener("load", arguments.callee);
 
       checkSmsDisabled();
 
       // Cleanup and quit.
       SpecialPowers.setBoolPref("dom.sms.enabled", gSmsEnabled);
-      SpecialPowers.setCharPref("dom.sms.whitelist", gSmsWhiteList);
+      SpecialPowers.removePermission("sms", document);
       SimpleTest.finish();
     });
     frames[0].location.reload();
   });
 
-  // Having more than one item in the whitelist should work.
   SpecialPowers.setBoolPref("dom.sms.enabled", true);
-  SpecialPowers.setCharPref("dom.sms.whitelist", "http://mochi.test:8888, http://foo.com");
   frames[0].location.reload();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(test);
 
 </script>
 </pre>
--- a/testing/marionette/client/marionette/marionette_test.py
+++ b/testing/marionette/client/marionette/marionette_test.py
@@ -48,49 +48,33 @@ window.addEventListener('message', funct
         marionetteScriptFinished(frame);
     }
 });
     """ % url)
 
         self.assertTrue(isinstance(frame, HTMLElement))
         return frame
 
-    def set_up_test_page(self, emulator, url="test.html", whitelist_prefs=None):
+    def set_up_test_page(self, emulator, url="test.html", permissions=None):
         emulator.set_context("content")
         url = emulator.absolute_url(url)
         emulator.navigate(url)
 
-        if not whitelist_prefs:
+        if not permissions:
             return
 
         emulator.set_context("chrome")
         emulator.execute_script("""
 Components.utils.import("resource://gre/modules/Services.jsm");
-let [url, whitelist_prefs] = arguments;
-let host = Services.io.newURI(url, null, null).prePath;
-whitelist_prefs.forEach(function (pref) {
-  let value;
-  try {
-    value = Services.prefs.getCharPref(pref);
-    log(pref + " has initial value " + value);
-  } catch(ex) {
-    log(pref + " has no initial value.");
-    // Ignore.
-  }
-  let list = value ? value.split(",") : [];
-  if (list.indexOf(host) != -1) {
-    return;
-  }
-  // Some whitelists expect scheme://host, some expect the full URI...
-  list.push(host);
-  list.push(url);
-  Services.prefs.setCharPref(pref, list.join(","))
-  log("Added " + host + " to " + pref);
+let [url, permissions] = arguments;
+let uri = Services.io.newURI(url, null, null);
+permissions.forEach(function (perm) {
+    Services.perms.add(uri, "sms", Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
 });
-        """, [url, whitelist_prefs])
+        """, [url, permissions])
         emulator.set_context("content")
 
     def setUp(self):
         if self.marionette.session is None:
             self.marionette.start_session()
 
     def tearDown(self):
         if self.marionette.session is not None: