https://bugs.webkit.org/show_bug.cgi?id=75799
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jan 2012 23:46:15 +0000 (23:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Jan 2012 23:46:15 +0000 (23:46 +0000)
Calling intersectsNode on a detached range should throw.

Source/WebCore:

INVALID_STATE_ERR exception should be thrown if intersectsNode is called on a detached Range.

Patch by Joe Thomas <joethomas@motorola.com> on 2012-01-23
Reviewed by Darin Adler.

Test: fast/dom/Range/range-intersectsNode-exception.html

* dom/Range.cpp:
(WebCore::Range::intersectsNode): Throwing INVALID_STATE_ERR exception if the range is detached.

LayoutTests:

Added test case to verify the exception thrown while calling intersectsNode on a detached range.

Patch by Joe Thomas <joethomas@motorola.com> on 2012-01-23
Reviewed by Darin Adler.

* fast/dom/Range/range-intersectsNode-exception-expected.txt: Added.
* fast/dom/Range/range-intersectsNode-exception.html: Added.
* fast/dom/Range/range-intersectsNode-expected.txt:
* fast/dom/Range/resources/intersectsNode.js:  Modified the test case to catch the exception.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@105649 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/Range/range-intersectsNode-exception-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Range/range-intersectsNode-exception.html [new file with mode: 0644]
LayoutTests/fast/dom/Range/range-intersectsNode-expected.txt
LayoutTests/fast/dom/Range/resources/intersectsNode.js
Source/WebCore/ChangeLog
Source/WebCore/dom/Range.cpp

index 415a41e..45dac48 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-23  Joe Thomas  <joethomas@motorola.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=75799
+        Calling intersectsNode on a detached range should throw.
+
+        Added test case to verify the exception thrown while calling intersectsNode on a detached range.
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/Range/range-intersectsNode-exception-expected.txt: Added.
+        * fast/dom/Range/range-intersectsNode-exception.html: Added.
+        * fast/dom/Range/range-intersectsNode-expected.txt:
+        * fast/dom/Range/resources/intersectsNode.js:  Modified the test case to catch the exception.
+
 2012-01-23  Mike Lawther  <mikelawther@chromium.org>
 
         getComputedStyle margin percentage test for CSS calc
diff --git a/LayoutTests/fast/dom/Range/range-intersectsNode-exception-expected.txt b/LayoutTests/fast/dom/Range/range-intersectsNode-exception-expected.txt
new file mode 100644 (file)
index 0000000..eea022d
--- /dev/null
@@ -0,0 +1,10 @@
+Test for Bug: 75799 - Calling intersectsNode on a detached range should throw
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS range.intersectsNode(document.getElementById('b1')) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/Range/range-intersectsNode-exception.html b/LayoutTests/fast/dom/Range/range-intersectsNode-exception.html
new file mode 100644 (file)
index 0000000..8f90652
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<!-- hidden area to create the ranges being tested -->
+<div  style="visibility: hidden">
+    <div id=a1>a1
+        <div id=b1>b1</div>
+    </div>
+</div>
+
+<script>
+description("Test for Bug: 75799 - Calling intersectsNode on a detached range should throw");
+var range = document.createRange();
+range.selectNode(document.getElementById("a1"));
+range.detach();
+shouldThrow("range.intersectsNode(document.getElementById('b1'))", '"Error: INVALID_STATE_ERR: DOM Exception 11"');
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 6413062..866f33f 100644 (file)
@@ -44,7 +44,7 @@ PASS intersects is true
 PASS intersects is true
 
 2.1 Detached Range, attached node
-PASS intersects is false
+PASS detachedRange.intersectsNode(document.getElementById('a1')) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
 
 2.2 attached range, detached node
 PASS intersects is false
index c10898a..5f279fb 100644 (file)
@@ -95,8 +95,7 @@ debug("");
 debug("2.1 Detached Range, attached node");
 var detachedRange = document.createRange();
 detachedRange.detach();
-intersects = detachedRange.intersectsNode(document.getElementById("a1"));
-shouldBeFalse("intersects");
+shouldThrow("detachedRange.intersectsNode(document.getElementById('a1'))", '"Error: INVALID_STATE_ERR: DOM Exception 11"');
 debug("");
 
 debug("2.2 attached range, detached node");
index ee973bf..fb93fc3 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-23  Joe Thomas  <joethomas@motorola.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=75799
+        Calling intersectsNode on a detached range should throw.
+
+        INVALID_STATE_ERR exception should be thrown if intersectsNode is called on a detached Range.
+
+        Reviewed by Darin Adler.
+
+        Test: fast/dom/Range/range-intersectsNode-exception.html
+
+        * dom/Range.cpp:
+        (WebCore::Range::intersectsNode): Throwing INVALID_STATE_ERR exception if the range is detached.
+
 2012-01-23  Daniel Cheng  <dcheng@chromium.org>
 
         Convert DataTransferItem/DataTransferItemList back into an interface class
index 298220e..9b569b3 100644 (file)
@@ -589,14 +589,17 @@ bool Range::intersectsNode(Node* refNode, ExceptionCode& ec)
     // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
     // Returns a bool if the node intersects the range.
 
+    // Throw exception if the range is already detached.
+    if (!m_start.container()) {
+        ec = INVALID_STATE_ERR;
+        return false;
+    }
     if (!refNode) {
         ec = NOT_FOUND_ERR;
         return false;
     }
-    
-    if ((!m_start.container() && refNode->attached())
-            || (m_start.container() && !refNode->attached())
-            || refNode->document() != m_ownerDocument) {
+
+    if (!refNode->attached() || refNode->document() != m_ownerDocument) {
         // Firefox doesn't throw an exception for these cases; it returns false.
         return false;
     }