Bug 1034337: Test deletion on direction-change boundaries with the pref bidi.edit.delete_immediately set to both true and false, r=ehsan
authorSimon Montagu <smontagu@smontagu.org>
Fri, 19 Sep 2014 00:18:47 -0700
changeset 206200 434e148f58c1932530d49ed1abe247c6f80c4e08
parent 206199 81a9009a5c1d6d025bed6a34f10b38adab7e1900
child 206201 8c737d160d5cac292571cdd2a22a036c10bfc742
push id27516
push userryanvm@gmail.com
push dateFri, 19 Sep 2014 17:54:48 +0000
treeherdermozilla-central@b00bdb144e06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1034337
milestone35.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 1034337: Test deletion on direction-change boundaries with the pref bidi.edit.delete_immediately set to both true and false, r=ehsan
layout/generic/test/test_backspace_delete.xul
--- a/layout/generic/test/test_backspace_delete.xul
+++ b/layout/generic/test/test_backspace_delete.xul
@@ -28,33 +28,50 @@ function execTests() {
     var n = editor.firstChild;
     if (node) {
       n = node();
     }
     sel.collapse(n, firstChildOffsetForCaret);
   }
 
   var eatSpace;
+  var deleteImmediately;
 
-  function getPrefs() {
+  function getPrefs(branch) {
     const prefSvcContractID = "@mozilla.org/preferences-service;1";
     const prefSvcIID = Components.interfaces.nsIPrefService;
     return Components.classes[prefSvcContractID].getService(prefSvcIID)
-                                                 .getBranch("layout.word_select.");
+                                                 .getBranch(branch);
+  }
+
+  function setPref(branch, pref, newValue) {
+    getPrefs(branch).setBoolPref(pref, newValue);
+    return newValue;
+  }
+
+  function restorePref(branch, pref, newValue) {
+    try {
+      getPrefs(branch).clearUserPref(pref);
+    } catch(ex) {}
   }
 
   function setEatSpace(newValue) {
-    getPrefs().setBoolPref("eat_space_to_next_word", newValue);
-    eatSpace = newValue;
+    eatSpace = setPref("layout.word_select.", "eat_space_to_next_word", newValue);
   }
 
   function restoreEatSpace() {
-    try {
-      getPrefs().clearUserPref("eat_space_to_next_word");
-    } catch(ex) {}
+    restorePref("layout.word_select.", "eat_space_to_next_word");
+  }
+
+  function setDeleteImmediately(newValue) {
+    deleteImmediately = setPref("bidi.edit.", "delete_immediately", newValue);
+  }
+
+  function restoreDeleteImmediately() {
+    restorePref("bidi.edit.", "delete_immediately");
   }
 
   function doCommand(cmd) {
     var controller = document.commandDispatcher.getControllerForCommand(cmd);
     if (controller) {
       try {
         controller.doCommand(cmd);
         ok(true, 'doCommand(' + cmd + ') succeeded');
@@ -81,30 +98,30 @@ function execTests() {
     is(selRange.startContainer, startNode, selErrString("Word right"));
     is(selRange.startOffset, startOffset, selErrString("Word right"));
     is(selRange.endContainer, endNode, selErrString("Word right"));
     is(selRange.endOffset, endOffset, selErrString("Word right"));
   }
 
   function testDelete(node, offset, text, richtext) {
     doCommand("cmd_deleteCharForward");
-    var msg = "Delete broken in \"" + editor.innerHTML + "\", offset " + offset;
+    var msg = "Delete broken in \"" + editor.innerHTML + "\", offset " + offset + " with deleteImmediately=" + deleteImmediately;
     if(typeof node == 'function'){
       node = node();
     }
     is(sel.anchorNode, node, msg);
 
     is(sel.anchorOffset, offset, msg);
     let text_result = richtext ? editor.innerHTML : editor.textContent;
     is(text_result, text, msg);
   }
 
   function testBackspace(node, offset, text) {
     doCommand("cmd_deleteCharBackward");
-    var msg = "Backspace broken in \"" + editor.innerHTML + "\", offset " + offset;
+    var msg = "Backspace broken in \"" + editor.innerHTML + "\", offset " + offset + " with deleteImmediately=" + deleteImmediately;
     is(sel.anchorNode, node, msg);
 
     is(sel.anchorOffset, offset, msg);
     is(editor.textContent, text, msg);
   }
 
   function testDeletePrevWord(node, offset, text) {
     doCommand("cmd_deleteWordBackward");
@@ -190,20 +207,48 @@ function execTests() {
 
   // Tests for Bug 419217
 
   setupTest("foo<div>bar</div>", 3);
   testDelete(function(){return editor.firstChild;}, 3, "foobar", true);
 
   // Tests for Bug 419406
   var s = "helloשלום";
+
+  setDeleteImmediately(true);
+
+  setupTest(s, 4);
+  testRight(editor.firstChild, 5);
+  testDelete(editor.firstChild, 5, "helloלום");
+
+  setDeleteImmediately(false);
+
   setupTest(s, 4);
   testRight(editor.firstChild, 5);
   testDelete(editor.firstChild, 5, "helloשלום");
 
+  // Tests for bug 1034337
+  s = "اهلاhello";
+
+  setDeleteImmediately(true);
+
+  setupTest(s, 4);
+  // first delete an ltr character to make sure that the caret is ltr
+  testDelete(editor.firstChild, 4, "اهلاello");
+  testBackspace(editor.firstChild, 3, "اهلello");
+
+  setDeleteImmediately(false);
+
+  setupTest(s, 4);
+  // first delete an ltr character to make sure that the caret is ltr
+  testDelete(editor.firstChild, 4, "اهلاello");
+  testBackspace(editor.firstChild, 4, "اهلاello");
+
+  restoreDeleteImmediately();
+
   // Tests for Bug 462188
   setupTest("You should not see this text.", 29);
   testDeletePrevWord(editor.firstChild, 24, "You should not see this ");
   testDeletePrevWord(editor.firstChild, 19, "You should not see ");
   testDeletePrevWord(editor.firstChild, 15, "You should not ");
   testDeletePrevWord(editor.firstChild, 11, "You should ");
   testDeletePrevWord(editor.firstChild,  4, "You ");
   testDeletePrevWord(editor,  0, "");