Bug 589623 - Raise INVALID_STATE_ERR exceptions from Selection.collapseTo{Start|End}; r+a=jst
authorMs2ger <ms2ger@gmail.com>
Sat, 06 Nov 2010 10:40:13 +0100
changeset 56999 2b612890113be82998312799bb8da9c2b335cfe7
parent 56998 5af66e2b201cfffb550171ec733130814edfc45d
child 57000 15409ec3bf08282f95fb4dc3216df2c57fa69c81
push id16753
push userdgottwald@mozilla.com
push dateSat, 06 Nov 2010 09:40:57 +0000
treeherdermozilla-central@2b612890113b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs589623
milestone2.0b8pre
first release with
nightly linux32
2b612890113b / 4.0b8pre / 20101106025958 / files
nightly linux64
2b612890113b / 4.0b8pre / 20101106031112 / files
nightly mac
2b612890113b / 4.0b8pre / 20101106030745 / files
nightly win32
2b612890113b / 4.0b8pre / 20101106042135 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 589623 - Raise INVALID_STATE_ERR exceptions from Selection.collapseTo{Start|End}; r+a=jst
layout/generic/nsSelection.cpp
layout/generic/test/Makefile.in
layout/generic/test/test_bug589623.html
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -4974,17 +4974,17 @@ nsTypedSelection::Collapse(nsINode* aPar
  * at the start of the current selection
  */
 NS_IMETHODIMP
 nsTypedSelection::CollapseToStart()
 {
   PRInt32 cnt;
   nsresult rv = GetRangeCount(&cnt);
   if (NS_FAILED(rv) || cnt <= 0)
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   // Get the first range
   nsIRange* firstRange = mRanges[0].mRange;
   if (!firstRange)
     return NS_ERROR_FAILURE;
 
   return Collapse(firstRange->GetStartParent(), firstRange->StartOffset());
 }
@@ -4994,17 +4994,17 @@ nsTypedSelection::CollapseToStart()
  * at the end of the current selection
  */
 NS_IMETHODIMP
 nsTypedSelection::CollapseToEnd()
 {
   PRInt32 cnt;
   nsresult rv = GetRangeCount(&cnt);
   if (NS_FAILED(rv) || cnt <= 0)
-    return NS_ERROR_FAILURE;
+    return NS_ERROR_DOM_INVALID_STATE_ERR;
 
   // Get the last range
   nsIRange* lastRange = mRanges[cnt-1].mRange;
   if (!lastRange)
     return NS_ERROR_FAILURE;
 
   return Collapse(lastRange->GetEndParent(), lastRange->EndOffset());
 }
--- a/layout/generic/test/Makefile.in
+++ b/layout/generic/test/Makefile.in
@@ -115,16 +115,17 @@ include $(topsrcdir)/config/rules.mk
 		file_BrokenImageReference.png \
 		file_Dolske.png \
 		file_IconTestServer.sjs \
 		file_LoadingImageReference.png \
 		file_bug514732_1.html \
 		file_bug514732_helper.html \
 		test_bug522632.html \
 		test_bug589621.html \
+		test_bug589623.html \
 		$(srcdir)/../../reftests/backgrounds/blue-32x32.png \
 		$(srcdir)/../../reftests/backgrounds/fuchsia-32x32.png \
 		$(NULL)
 
 _CHROME_FILES = \
 		test_bug514732-2.xul \
 		file_bug514732_window.xul \
 		$(NULL)
new file mode 100644
--- /dev/null
+++ b/layout/generic/test/test_bug589623.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=589623
+-->
+<head>
+  <title>Test for Bug 589623</title>
+  <script src="/MochiKit/packed.js"></script>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=589623">Mozilla Bug 589623</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script>
+/** Test for Bug 589623 **/
+var sel = getSelection();
+sel.removeAllRanges();
+function t(m) {
+  try {
+    sel[m]();
+    ok(false, "Should not be here");
+  } catch(e) {
+    ok(e instanceof DOMException, "Should be a DOMException");
+    is(e.code, DOMException.INVALID_STATE_ERR, "Should be an INVALID_STATE_ERR");
+  }
+}
+t("collapseToStart");
+t("collapseToEnd");
+</script>
+</pre>
+</body>
+</html>