Index: third_party/WebKit/LayoutTests/editing/assert_selection.js |
diff --git a/third_party/WebKit/LayoutTests/editing/assert_selection.js b/third_party/WebKit/LayoutTests/editing/assert_selection.js |
index 9599a1745076f392b7e4c0513afbe767a9f95734..ee7c22a88a6ef71d0f59ffc87dedc260f209d6f8 100644 |
--- a/third_party/WebKit/LayoutTests/editing/assert_selection.js |
+++ b/third_party/WebKit/LayoutTests/editing/assert_selection.js |
@@ -419,12 +419,11 @@ class Serializer { |
* @param {number} nodeIndex |
*/ |
handleElementNode(element, nodeIndex) { |
- if (element.parenNode === this.selection_.focusNode && |
yoichio
2016/05/30 02:08:36
The strict mode can't check this? Sad,,,
|
+ if (element.parentNode === this.selection_.focusNode && |
nodeIndex === this.selection_.focusOffset) { |
this.emit('|'); |
- } else if ( |
- element === this.selection_.anchorNode && |
- nodeIndex === this.selection_.anchorOffset) { |
+ } else if (element.parentNode === this.selection_.anchorNode && |
+ nodeIndex === this.selection_.anchorOffset) { |
this.emit('^'); |
} |
/** @type {string} */ |
@@ -451,6 +450,13 @@ class Serializer { |
this.serializeInternal(child, childIndex); |
++childIndex; |
} |
+ if (element === this.selection_.focusNode && |
+ childIndex === this.selection_.focusOffset) { |
+ this.emit('|'); |
+ } else if (element === this.selection_.anchorNode && |
+ childIndex === this.selection_.anchorOffset) { |
+ this.emit('^'); |
+ } |
this.emit(`</${tagName}>`); |
} |
@@ -570,6 +576,28 @@ function assembleDescription() { |
} |
/** |
+ * @param {string} expectedText |
+ */ |
+function checkExpectedText(expectedText) { |
yoichio
2016/05/30 02:08:36
Could you extract sanity check functions from this
|
+ /** @type {number} */ |
+ const anchorOffset = expectedText.indexOf('^'); |
+ /** @type {number} */ |
+ const focusOffset = expectedText.indexOf('|'); |
+ if (anchorOffset != expectedText.lastIndexOf('^')) { |
+ throw new Error( |
+ `You should have at most one anchor marker "^" in "${expectedText}".`); |
+ } |
+ if (focusOffset != expectedText.lastIndexOf('|')) { |
+ throw new Error( |
+ `You should have at most one focus marker "|" in "${expectedText}".`); |
+ } |
+ if (anchorOffset >= 0 && focusOffset < 0) { |
+ throw new Error( |
+ `You should have both anchor marker "^" and focus marker "|" in ${expectedText}`); |
+ } |
+} |
+ |
+/** |
* @param {string} inputText |
* @param {function(!Selection)|string} |
* @param {string} expectedText |
@@ -580,14 +608,7 @@ function assertSelection( |
/** @type {string} */ |
const description = |
opt_description === '' ? assembleDescription() : opt_description; |
- if (expectedText.indexOf('^') != expectedText.lastIndexOf('^')) { |
- throw new Error( |
- `You should have at most one anchor marker "^" in "${expectedText}".`); |
- } |
- if (expectedText.indexOf('|') != expectedText.lastIndexOf('|')) { |
- throw new Error( |
- `You should have at most one focus marker "|" in "${expectedText}".`); |
- } |
+ checkExpectedText(expectedText); |
const sample = new Sample(inputText); |
if (typeof(tester) === 'function') { |
tester.call(window, sample.selection); |