Bug 719518 - Selection.extend() with no ranges should throw standard exception type; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Wed, 14 Mar 2012 14:27:30 -0400
changeset 89495 895c2f5035539931d4279cf88a7d326f87e21b51
parent 89494 d0dbd91f956f6fed8af80fdf811bf36da64cf47c
child 89496 c9024bcb8da0f79cfcefa887df1c52f37865f922
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersehsan
bugs719518
milestone14.0a1
Bug 719518 - Selection.extend() with no ranges should throw standard exception type; r=ehsan
layout/generic/nsSelection.cpp
layout/generic/test/Makefile.in
layout/generic/test/test_bug719518.html
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -5076,17 +5076,17 @@ nsTypedSelection::Extend(nsIDOMNode* aPa
 nsresult
 nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset)
 {
   if (!aParentNode)
     return NS_ERROR_INVALID_ARG;
 
   // First, find the range containing the old focus point:
   if (!mAnchorFocusRange)
-    return NS_ERROR_NOT_INITIALIZED;
+    return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   if (!mFrameSelection)
     return NS_ERROR_NOT_INITIALIZED; // Can't do selection
 
   nsresult res;
   if (!IsValidSelectionPoint(mFrameSelection, aParentNode))
     return NS_ERROR_FAILURE;
 
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -123,16 +123,17 @@ include $(topsrcdir)/config/rules.mk
   test_bug589623.html \
   test_bug633762.html \
   bug633762_iframe.html \
   $(srcdir)/../../reftests/backgrounds/blue-32x32.png \
   $(srcdir)/../../reftests/backgrounds/fuchsia-32x32.png \
   test_selection_splitText-normalize.html \
   test_bug524925.html \
   test_bug719503.html \
+  test_bug719518.html \
   $(NULL)
 
 _CHROME_FILES = \
   test_bug632379.xul \
   test_bug508115.xul \
   test_bug469613.xul \
   test_bug469774.xul \
   test_backspace_delete.xul \
new file mode 100644
--- /dev/null
+++ b/layout/generic/test/test_bug719518.html
@@ -0,0 +1,24 @@
+<!doctype html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=719518
+-->
+<title>Test for Bug 719518</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=719518">Mozilla Bug 719518</a>
+<p id="display"></p>
+<div id="content" style="display: none"></div>
+<pre id="test">
+<script>
+var thrown = false;
+try {
+  getSelection().extend(document.body, 0);
+} catch(e) {
+  thrown = true;
+  ok(e instanceof DOMException,
+     "Need to throw DOMException for extend() with no ranges");
+  is(e.code, DOMException.INVALID_STATE_ERR,
+     "Need to throw INVALID_STATE_ERR for extend() with no ranges");
+}
+ok(thrown, "Need to throw exception for extend() with no ranges");
+</script>