Bug 1101392 - Part 4: Add mochitest. r=roc
authorMorris Tseng <mtseng@mozilla.com>
Thu, 27 Nov 2014 21:27:00 +0100
changeset 217968 1b10bab94f6e34a7835eb53ae5cb14a46ec19dcf
parent 217967 d59fef58d1ac2f336070602e7bfa50202a28eee3
child 217969 a5eaa2d643535bd52b353043fc7aa6cbd30f5a5c
push id10209
push usercbook@mozilla.com
push dateFri, 28 Nov 2014 13:27:18 +0000
treeherderfx-team@79b7c10e2c1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1101392
milestone36.0a1
Bug 1101392 - Part 4: Add mochitest. r=roc
editor/libeditor/tests/chrome.ini
editor/libeditor/tests/test_bug1101392.html
--- a/editor/libeditor/tests/chrome.ini
+++ b/editor/libeditor/tests/chrome.ini
@@ -15,16 +15,17 @@ skip-if = buildapp == 'mulet'
 [test_bug616590.xul]
 [test_bug635636.html]
 [test_bug636465.xul]
 [test_bug646194.xul]
 [test_bug780908.xul]
 [test_bug830600.html]
 [test_bug1053048.html]
 [test_bug1102906.html]
+[test_bug1101392.html]
 [test_composition_event_created_in_chrome.html]
 [test_contenteditable_text_input_handling.html]
 [test_dragdrop.html]
 skip-if = buildapp == 'mulet'
 [test_htmleditor_keyevent_handling.html]
 [test_selection_move_commands.xul]
 [test_texteditor_keyevent_handling.html]
 # disables the key handling test on gtk because gtk overrides some key events
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/tests/test_bug1101392.html
@@ -0,0 +1,77 @@
+<!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 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;
+      element.select();
+    } else {
+      var sel = window.getSelection();
+      sel.selectAllChildren(element.parentNode);
+    }
+
+    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");
+
+      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); },
+        checkCollapse, checkCollapse);
+  }
+
+  function testDiv()
+  {
+    var content = document.getElementById("content");
+    runCopyCommand(content, 'abc', testTextarea);
+  }
+
+  function testTextarea()
+  {
+    var textarea = document.getElementById("textarea");
+    runCopyCommand(textarea, 'def', SimpleTest.finish);
+  }
+
+  function runTests()
+  {
+    testDiv();
+  }
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1101392">Mozilla Bug 1101392</a>
+<div><div id="content">abc</div></div>
+
+<textarea id="textarea">def</textarea>
+
+<pre id="test">
+</pre>
+</body>
+</html>