Bug 440590 - Text selection information is not updated when HTML and XUL entries lose focus, r=tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Mon, 22 Apr 2013 17:10:09 +0900
changeset 129469 58fa28d2b7bbd5f37135478962952fab2512057b
parent 129462 ea3ffdbddc53a5f82d9f96fd9c1af7d127c32c10
child 129470 ebb2d369bad2044b742fc54251fb985efbbc5e46
push idunknown
push userunknown
push dateunknown
reviewerstbsaunde
bugs440590
milestone23.0a1
Bug 440590 - Text selection information is not updated when HTML and XUL entries lose focus, r=tbsaunde
accessible/src/generic/HyperTextAccessible.cpp
accessible/tests/mochitest/textselection/Makefile.in
accessible/tests/mochitest/textselection/test_userinput.html
--- a/accessible/src/generic/HyperTextAccessible.cpp
+++ b/accessible/src/generic/HyperTextAccessible.cpp
@@ -1824,18 +1824,20 @@ HyperTextAccessible::FrameSelection()
   nsIFrame* frame = GetFrame();
   return frame ? frame->GetFrameSelection() : nullptr;
 }
 
 void
 HyperTextAccessible::GetSelectionDOMRanges(int16_t aType,
                                            nsTArray<nsRange*>* aRanges)
 {
+  // Ignore selection if it is not visible.
   nsRefPtr<nsFrameSelection> frameSelection = FrameSelection();
-  if (!frameSelection)
+  if (!frameSelection ||
+      frameSelection->GetDisplaySelection() <= nsISelectionController::SELECTION_HIDDEN)
     return;
 
   Selection* domSel = frameSelection->GetSelection(aType);
   if (!domSel)
     return;
 
   nsCOMPtr<nsINode> startNode = GetNode();
 
--- a/accessible/tests/mochitest/textselection/Makefile.in
+++ b/accessible/tests/mochitest/textselection/Makefile.in
@@ -8,11 +8,12 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_A11Y_FILES = \
 		test_general.html \
+		test_userinput.html \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/textselection/test_userinput.html
@@ -0,0 +1,95 @@
+<html>
+
+<head>
+  <title>Text selection by user input</title>
+
+  <link rel="stylesheet" type="text/css"
+        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+
+  <script type="application/javascript"
+          src="../common.js"></script>
+  <script type="application/javascript"
+          src="../role.js"></script>
+  <script type="application/javascript"
+          src="../states.js"></script>
+  <script type="application/javascript"
+          src="../events.js"></script>
+
+  <script type="application/javascript">
+    /**
+     * Invokers
+     */
+    function synthTabAndCheckPrevTabbed(aID, aPrevID)
+    {
+      this.__proto__ = new synthTab(aID, new focusChecker(aID));
+
+      this.finalCheck = function changeSelection_finalCheck()
+      {
+        var prevTabbed = getAccessible(aPrevID, [ nsIAccessibleText ]);
+        is(prevTabbed.selectionCount, 0,
+           "Wrong selection count for " + aPrevID);
+
+        var exceptionCaught = false;
+        try {
+          var startOffsetObj = {}, endOffsetObj = {};
+          prevTabbed.getSelectionBounds(0, startOffsetObj, endOffsetObj);
+        } catch (e) {
+          exceptionCaught = true;
+        }
+
+        ok(exceptionCaught, "No selection was expected for " + aPrevID);
+      }
+
+      this.getID = function changeSelection_getID()
+      {
+        return "Hidden selection check for " + aPrevID;
+      }
+    }
+
+    /**
+     * Do tests
+     */
+
+    //gA11yEventDumpToConsole = true; // debug stuff
+
+    var gQueue = null;
+    function doTests()
+    {
+      gQueue = new eventQueue();
+
+      // Tab to 't2' and then tab out it: it must has no selection.
+      gQueue.push(new synthFocus("t1"));
+      gQueue.push(new synthTab("t2", new focusChecker("t2")));
+      gQueue.push(new synthTabAndCheckPrevTabbed("t3", "t2"));
+
+      gQueue.invoke(); // Will call SimpleTest.finish();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTests);
+  </script>
+</head>
+
+<body>
+
+  <a target="_blank"
+     href="https://bugzilla.mozilla.org/show_bug.cgi?id=440590"
+     title="Text selection information is not updated when HTML and XUL entries lose focus">
+    Bug 440590
+  </a>
+  <p id="display"></p>
+  <div id="content" style="display: none"></div>
+  <pre id="test">
+  </pre>
+
+  <input type="text" id="t1" maxlength="3" size="3" value="1">
+  <input type="text" id="t2" maxlength="3" size="3" value="1">
+  <input type="text" id="t3" maxlength="3" size="3" value="1">
+
+</body>
+</html>