Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: third_party/WebKit/LayoutTests/editing/selection/selection-update-range-after-addrange.html

Issue 2687273002: Selection API: Mutating a Range object after adding it to Selection should update Selection attribu… (Closed)
Patch Set: Handle diffrent root cases Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/editing/selection/selection-update-range-after-addrange.html
diff --git a/third_party/WebKit/LayoutTests/editing/selection/selection-update-range-after-addrange.html b/third_party/WebKit/LayoutTests/editing/selection/selection-update-range-after-addrange.html
new file mode 100644
index 0000000000000000000000000000000000000000..c85b1493363efc33ce85e8a52f388f10e7ce1f55
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/editing/selection/selection-update-range-after-addrange.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<p>abcdef</p>
+<script>
+test(() => {
+ let selection = getSelection();
+ selection.removeAllRanges();
+ let range = document.createRange();
+ let text = document.querySelector('p').firstChild;
+ range.setStart(text, 1);
+ range.setEnd(text, 2);
+
+ selection.addRange(range);
+ assert_equals(selection.anchorNode, text);
+ assert_equals(selection.anchorOffset, 1);
+ assert_equals(selection.focusNode, text);
+ assert_equals(selection.focusOffset, 2);
+
+ range.setStart(text, 0);
+ assert_equals(selection.anchorOffset, 0);
+}, 'Mutation of Range after adding it to Selection should update Selection attributes.');
+
+test(() => {
+ let selection = getSelection();
+ selection.removeAllRanges();
+ let range = document.createRange();
+ range.selectNode(document.body);
+ selection.addRange(range);
+ assert_equals(selection.rangeCount, 1);
+
+ let document2 = document.implementation.createHTMLDocument();
+ document2.innerHTML = '<html><body>abc</body></html>';
+ range.selectNode(document2.body);
+ // TODO(tkent): The specification says nothing about such case. For now, we
+ // unregister the Range from the Selection for ease of implementation
+ // though Firefox and Edge keep |selection.getRangeAt(0) == range|.
+ assert_equals(selection.rangeCount, 0);
+}, 'Switching Range document should clear registered Selection.');
+
+test(() => {
+ let selection = getSelection();
+ selection.removeAllRanges();
+ let range = document.createRange();
+ range.selectNode(document.body);
+ selection.addRange(range);
+ assert_equals(selection.rangeCount, 1);
+
+ let span = document.createElement('span');
+ span.innerHTML = 'text';
+ range.selectNode(span.firstChild);
+ // TODO(tkent): The specification says nothing about such case. For now, we
+ // unregister the Range from the Selection for ease of implementation
+ // though Firefox and Edge keep |selection.getRangeAt(0) == range|.
+ assert_equals(selection.rangeCount, 0);
+}, 'Updating Range for another root should clear registered Selection.');
+</script>

Powered by Google App Engine
This is Rietveld 408576698