Bug 1271119 - Port test_bug1101392.html from chrome to plain; r?masayuki draft
authorAryeh Gregor <ayg@aryeh.name>
Tue, 30 Aug 2016 21:08:55 +0300
changeset 430257 08735488b9e61cc2a87e7e1ded752a5d39c496bd
parent 430256 951f83592036410b29cb89a08832b800c2423ec4
child 430258 a378994edab26d2d01a10d9a55fc58d6c0455188
push id33788
push userayg@aryeh.name
push dateThu, 27 Oct 2016 12:44:14 +0000
reviewersmasayuki
bugs1271119, 1101392
milestone52.0a1
Bug 1271119 - Port test_bug1101392.html from chrome to plain; r?masayuki MozReview-Commit-ID: F5Q8AWVtdjC
editor/libeditor/tests/chrome.ini
editor/libeditor/tests/mochitest.ini
editor/libeditor/tests/test_bug1101392.html
--- a/editor/libeditor/tests/chrome.ini
+++ b/editor/libeditor/tests/chrome.ini
@@ -17,18 +17,16 @@ skip-if = buildapp == 'mulet'
 [test_bug635636.html]
 [test_bug636465.xul]
 [test_bug780908.xul]
 [test_bug830600.html]
 subsuite = clipboard
 [test_bug1053048.html]
 [test_bug1100966.html]
 [test_bug1102906.html]
-[test_bug1101392.html]
-subsuite = clipboard
 [test_bug1140105.html]
 [test_bug1140617.xul]
 subsuite = clipboard
 [test_bug1153237.html]
 [test_bug1154791.html]
 [test_bug1248128.html]
 [test_bug1248185.html]
 [test_bug1250010.html]
--- a/editor/libeditor/tests/mochitest.ini
+++ b/editor/libeditor/tests/mochitest.ini
@@ -160,16 +160,18 @@ skip-if = toolkit == 'android'
 [test_bug966155.html]
 skip-if = os != "win"
 [test_bug966552.html]
 skip-if = os != "win"
 [test_bug998188.html]
 [test_bug1026397.html]
 [test_bug1067255.html]
 [test_bug1094000.html]
+[test_bug1101392.html]
+subsuite = clipboard
 [test_CF_HTML_clipboard.html]
 subsuite = clipboard
 [test_contenteditable_focus.html]
 [test_dom_input_event_on_htmleditor.html]
 skip-if = toolkit == 'android' # bug 1054087
 [test_dom_input_event_on_texteditor.html]
 [test_keypress_untrusted_event.html]
 [test_root_element_replacement.html]
--- a/editor/libeditor/tests/test_bug1101392.html
+++ b/editor/libeditor/tests/test_bug1101392.html
@@ -1,54 +1,55 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1101392
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1101392</title>
-  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
 
   /** Test for Bug 1101392 **/
   SimpleTest.waitForExplicitFinish();
   SimpleTest.waitForFocus(runTests);
 
   function runCopyCommand(element, compareText, nextTest)
   {
     element.focus();
-    if (element.editor) {
-      var sel = element.editor.selection;
+    var expectedEndpoint, sel;
+    if (element.localName == "textarea") {
       element.select();
+      expectedEndpoint = element.selectionEnd;
     } else {
-      var sel = window.getSelection();
+      sel = getSelection();
       sel.selectAllChildren(element.parentNode);
+      expectedEndpoint = [sel.getRangeAt(0).endContainer,
+                          sel.getRangeAt(0).endOffset];
     }
 
-    var expectedEndpoint = [
-      sel.getRangeAt(0).endContainer,
-      sel.getRangeAt(0).endOffset
-    ];
-
     function checkCollapse() {
-      is(sel.isCollapsed, true, "collapsed after cmd_copyAndCollapseToEnd");
-      is(sel.anchorNode, expectedEndpoint[0], "node after cmd_copyAndCollapseToEnd");
-      is(sel.anchorOffset, expectedEndpoint[1], "offset after cmd_copyAndCollapseToEnd");
+      var desc = " after cmd_copyAndCollapseToEnd for " +
+                 element.localName;
+      if (element.localName == "textarea") {
+        is(element.selectionStart, expectedEndpoint, "start offset" + desc);
+        is(element.selectionEnd, expectedEndpoint, "end offset" + desc);
+      } else {
+        is(sel.isCollapsed, true, "collapsed" + desc);
+        is(sel.anchorNode, expectedEndpoint[0], "node" + desc);
+        is(sel.anchorOffset, expectedEndpoint[1], "offset" + desc);
+      }
 
       nextTest();
     }
 
-    const kCmd = "cmd_copyAndCollapseToEnd";
-    var controller = top.document.commandDispatcher
-                     .getControllerForCommand(kCmd);
-    ok((controller && controller.isCommandEnabled(kCmd)), "have cmd_copyAndCollapseToEnd command");
     SimpleTest.waitForClipboard(compareText,
-        () => { controller.doCommand(kCmd); },
+        () => SpecialPowers.doCommand(window, "cmd_copyAndCollapseToEnd"),
         checkCollapse, checkCollapse);
   }
 
   function testDiv()
   {
     var content = document.getElementById("content");
     runCopyCommand(content, 'abc', testTextarea);
   }