Bug 899939 - Fix some tests that still use prefBranch instead of SpecialPowers.pushPrefEnv. r=jmaher
authorMartijn Wargers <mwargers@mozilla.com>
Wed, 31 Jul 2013 11:30:54 +0200
changeset 153089 33600eab273edec69da64c8fa97fb012279c5f78
parent 153088 83e77ea05fd2e498b8db09b75df0f93257125bcc
child 153090 612a421df3aee4a8a6e3f29306443b735c98aa81
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs899939
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 899939 - Fix some tests that still use prefBranch instead of SpecialPowers.pushPrefEnv. r=jmaher
content/svg/content/test/test_switch.xhtml
layout/generic/test/test_movement_by_words.html
testing/mochitest/b2g.json
--- a/content/svg/content/test/test_switch.xhtml
+++ b/content/svg/content/test/test_switch.xhtml
@@ -40,24 +40,22 @@ function checkWidth(element, x, y, w, h)
   var name = element.nodeName;
 
   is(bbox.width, w, test + " " + name + ".getBBox().width");
   ++test;
 }
 
 function run()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   // Set accept_languages to something we know
-  var prefService = Components.classes["@mozilla.org/preferences-service;1"]
-                               .getService(Components.interfaces.nsIPrefService);
-  var branch = prefService.getBranch("intl.");
-  var oldAcceptLanguages = branch.getCharPref("accept_languages");
-  branch.setCharPref("accept_languages", "en-gb,en,it");
+  SpecialPowers.pushPrefEnv({"set": [["intl.accept_languages", "en-gb,en,it"]]}, run1);
+}
 
+function run1()
+{
   try {
     var doc = $("svg").contentDocument;
     var s = doc.getElementById("s");
     var first = doc.getElementById("first");
     var second = doc.getElementById("second");
   
     /* test for an exact match */
     second.setAttribute("systemLanguage", "en-gb");
@@ -88,17 +86,16 @@ function run()
     checkWidth(s, 75, 100, 50, 50);
 
     /* test that we pick the best match */
     first.setAttribute("systemLanguage", "en");
     second.setAttribute("systemLanguage", "en-gb");
     checkWidth(s, 75, 100, 50, 50);
 
   } finally {
-    branch.setCharPref("accept_languages", oldAcceptLanguages);
     SimpleTest.finish();
   }
 }
 
 window.addEventListener("load", run, false);
 
 ]]>
 </script>
--- a/layout/generic/test/test_movement_by_words.html
+++ b/layout/generic/test/test_movement_by_words.html
@@ -22,64 +22,55 @@ setTimeout(focusing, 0);
 
 function focusing() {
   document.getElementById("editor").focus();
   // This seems to be necessary because the selection is not set up properly otherwise
   setTimeout(test, 0);
 }
 
 var eatSpace;
+var wordModifiers =
+    (navigator.platform.indexOf("Mac") >= 0) ? {altKey:true} : {ctrlKey:true};
+var sel = window.getSelection();
+var editor = document.getElementById("editor");
 
-function getPrefs() {
-  const prefSvcContractID = "@mozilla.org/preferences-service;1";
-  const prefSvcIID = Components.interfaces.nsIPrefService;
-  return Components.classes[prefSvcContractID].getService(prefSvcIID)
-                                               .getBranch("layout.word_select.");
+function setPrefs(eat_space, stop_at_punctuation, callback) {
+  SpecialPowers.pushPrefEnv({"set": [["layout.word_select.eat_space_to_next_word", eat_space], ["layout.word_select.stop_at_punctuation", stop_at_punctuation]]}, callback);
+}
+
+function errString(dir) {
+  return dir + " movement broken with eatSpace=" + eatSpace + " in \"" + editor.innerHTML +
+    "\"; sel.anchorNode.parentNode=" + sel.anchorNode.parentNode;
 }
 
-function setPrefs(eat_space, stop_at_punctuation) {
-  getPrefs().setBoolPref("eat_space_to_next_word", eat_space);
-  getPrefs().setBoolPref("stop_at_punctuation", stop_at_punctuation);
-  eatSpace = eat_space;
+function testRight(node, offset) {
+  synthesizeKey("VK_RIGHT", wordModifiers);
+  is(sel.anchorNode, node, errString("Right"));
+  is(sel.anchorOffset, offset, errString("Right"));
 }
 
-function restorePrefs() {
-  getPrefs().clearUserPref("eat_space_to_next_word");
-  getPrefs().clearUserPref("stop_at_punctuation");
+function testLeft(node, offset) {
+  synthesizeKey("VK_LEFT", wordModifiers);
+  is(sel.anchorNode, node, errString("Left"));
+  is(sel.anchorOffset, offset, errString("Left"));
 }
 
+var afterEditorNode = document.getElementById("catch").firstChild;
+
+var ChineseChars = "&#x6F22;&#x5B57;";
+var HiraganaChars = "&#x3072;&#x3089;&#x304C;&#x306A;";
+var KatakanaChars = "&#x30AB;&#x30BF;&#x30AB;&#x30CA;";
+var JapaneseFullStop = "&#x3002;";
+var JapaneseComma = "&#x3001";
+
 function test() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-  var wordModifiers =
-      (navigator.platform.indexOf("Mac") >= 0) ? {altKey:true} : {ctrlKey:true};
-  var sel = window.getSelection();
-  var editor = document.getElementById("editor");
-
-  function errString(dir) {
-    return dir + " movement broken with eatSpace=" + eatSpace + " in \"" + editor.innerHTML +
-      "\"; sel.anchorNode.parentNode=" + sel.anchorNode.parentNode;
-  }
+  setPrefs(false, true, test1);
+}
 
-  function testRight(node, offset) {
-    synthesizeKey("VK_RIGHT", wordModifiers);
-    is(sel.anchorNode, node, errString("Right"));
-    is(sel.anchorOffset, offset, errString("Right"));
-  }
-
-  function testLeft(node, offset) {
-    synthesizeKey("VK_LEFT", wordModifiers);
-    is(sel.anchorNode, node, errString("Left"));
-    is(sel.anchorOffset, offset, errString("Left"));
-  }
-
-  var afterEditorNode = document.getElementById("catch").firstChild;
-
-  setPrefs(false, true);
-
+function test1() {
   editor.innerHTML = "Hello Kitty";
   sel.collapse(editor.firstChild, 0);
   testRight(editor.firstChild, 5);
   testRight(editor.firstChild, 11);
   testLeft(editor.firstChild, 6);
   testLeft(editor.firstChild, 0);
 
   editor.innerHTML = "<b>Hello</b> Kitty";
@@ -122,22 +113,16 @@ function test() {
   testRight(editor.firstChild, 7);
   testRight(editor.firstChild, 10);
   testRight(editor.firstChild.nextSibling.nextSibling, 5);
   testLeft(editor.firstChild.nextSibling.firstChild, 1);
   testLeft(editor.firstChild, 8);
   testLeft(editor.firstChild, 5);
   testLeft(editor.firstChild, 0);
 
-  var ChineseChars = "&#x6F22;&#x5B57;";
-  var HiraganaChars = "&#x3072;&#x3089;&#x304C;&#x306A;";
-  var KatakanaChars = "&#x30AB;&#x30BF;&#x30AB;&#x30CA;";
-  var JapaneseFullStop = "&#x3002;";
-  var JapaneseComma = "&#x3001";
-
   editor.innerHTML = ChineseChars + HiraganaChars + ChineseChars;
   sel.collapse(editor.firstChild, 0);
   testRight(editor.firstChild, 2);
   testRight(editor.firstChild, 6);
   testRight(editor.firstChild, 8);
   testLeft(editor.firstChild, 6);
   testLeft(editor.firstChild, 2);
   testLeft(editor.firstChild, 0);
@@ -182,20 +167,21 @@ function test() {
   sel.collapse(editor.firstChild, 0);
   testRight(editor.firstChild, 3);
   testRight(editor.firstChild, 6);
   testRight(editor.firstChild, 8);
   testLeft(editor.firstChild, 6);
   testLeft(editor.firstChild, 3);
   testLeft(editor.firstChild, 0);
 
-  setPrefs(true, true);
+  // test basic word movement with eat_space_next_to_word true.
+  setPrefs(true, true, test2);
+}
 
-  // test basic word movement with eat_space_next_to_word true.
-
+function test2() {
   editor.innerHTML = "Hello Kitty";
   sel.collapse(editor.firstChild, 0);
   testRight(editor.firstChild, 6);
   testRight(editor.firstChild, 11);
   testLeft(editor.firstChild, 6);
   testLeft(editor.firstChild, 0);
 
   editor.innerHTML = "<b>Hello</b> Kitty";
@@ -290,17 +276,15 @@ function test() {
   sel.collapse(editor.firstChild, 0);
   testRight(editor.firstChild, 3);
   testRight(editor.firstChild, 6);
   testRight(editor.firstChild, 8);
   testLeft(editor.firstChild, 6);
   testLeft(editor.firstChild, 3);
   testLeft(editor.firstChild, 0);
 
-  restorePrefs();
-
   SimpleTest.finish();
 }
 
 
 </script></pre>
 </body>
 </html>
--- a/testing/mochitest/b2g.json
+++ b/testing/mochitest/b2g.json
@@ -204,17 +204,16 @@
     "content/events/test/test_bug574663.html":"",
     "content/events/test/test_bug607464.html":"",
     "content/events/test/test_dragstart.html":"",
     "content/events/test/test_wheel_default_action.html":"",
     "content/base/test/test_bug682592.html":"",	
     "content/html/document/test/test_bug369370.html":"",
     "content/html/document/test/test_bug391777.html":"",
     "content/svg/content/test/test_SVGAnimatedImageSMILDisabled.html":"",
-    "content/svg/content/test/test_switch.xhtml":"",
     "content/xml/document/test/test_bug392338.html":"",
     "content/xslt/tests/mochitest/test_bug319374.xhtml":"",
     "content/base/test/test_bothCSPheaders.html":"",
     "content/base/test/test_bug383430.html":"",
     "content/base/test/test_bug422403-2.xhtml":"",
     "content/base/test/test_bug424359-1.html":"",
     "content/base/test/test_bug424359-2.html":"",
     "content/base/test/test_bug426308.html":"",
@@ -427,17 +426,16 @@
     "layout/generic/test/test_bug633762.html":"",
     "layout/generic/test/test_bug666225.html":"",
     "layout/generic/test/test_bug735641.html":"",
     "layout/generic/test/test_bug784410.html":"",
     "layout/generic/test/test_bug791616.html":"",
     "layout/generic/test/test_image_selection_2.html":"",
     "layout/generic/test/test_invalidate_during_plugin_paint.html":"",
     "layout/generic/test/test_movement_by_characters.html":"",
-    "layout/generic/test/test_movement_by_words.html":"",
     "layout/generic/test/test_page_scroll_with_fixed_pos.html":"",
     "layout/generic/test/test_plugin_clipping.xhtml":"",
     "layout/generic/test/test_plugin_clipping2.xhtml":"",
     "layout/generic/test/test_plugin_clipping_table.xhtml":"",
     "layout/generic/test/test_plugin_clipping_transformed.xhtml":"",
     "layout/generic/test/test_plugin_focus.html":"",
     "layout/generic/test/test_plugin_mouse_coords.html":"",
     "layout/generic/test/test_plugin_position.xhtml":"",