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

Unified Diff: third_party/WebKit/LayoutTests/editing/assert_selection.js

Issue 2016173002: Convert execCommand/unlink.html to use w3c test harness (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-05-27T18:50:31 Created 4 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/editing/execCommand/unlink.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/editing/execCommand/unlink.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698