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

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

Issue 2138653002: [Editing][CodeHealth] Improve result comparing in assert_selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 5 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 | « third_party/WebKit/LayoutTests/editing/assert_selection.html ('k') | no next file » | 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 2ee74145ff63043a2113562c4e58759055572bf4..0ecd886f8ad612cec465995f90a4a7e5126b59b0 100644
--- a/third_party/WebKit/LayoutTests/editing/assert_selection.js
+++ b/third_party/WebKit/LayoutTests/editing/assert_selection.js
@@ -580,8 +580,6 @@ class Sample {
}
function assembleDescription() {
- const RE_TEST_FUNCTION =
- new RegExp('at Object.test \\(.*?([^/]+?):(\\d+):(\\d+)\\)');
function getStack() {
let stack;
try {
@@ -591,11 +589,14 @@ function assembleDescription() {
}
return stack
}
+
+ const RE_IN_ASSERT_SELECTION = new RegExp('assert_selection\\.js');
for (const line of getStack()) {
- const match = RE_TEST_FUNCTION.exec(line);
- if (!match)
- continue;
- return `${match[1]}(${match[2]})`;
+ const match = RE_IN_ASSERT_SELECTION.exec(line);
+ if (!match) {
+ const RE_LAYOUTTESTS = new RegExp('LayoutTests.*');
+ return RE_LAYOUTTESTS.exec(line);
+ }
}
return '';
}
@@ -628,6 +629,19 @@ function checkExpectedText(expectedText) {
}
/**
+ * @param {string} str1
+ * @param {string} str2
+ * @return {string}
+ */
+function commonPrefixOf(str1, str2) {
+ for (let index = 0; index < str1.length; ++index) {
+ if (str1[index] !== str2[index])
+ return str1.substr(0, index);
+ }
+ return str1;
+}
+
+/**
* @param {string} inputText
* @param {function(!Selection)|string}
* @param {string} expectedText
@@ -652,9 +666,14 @@ function assertSelection(
const actualText = sample.serialize();
// We keep sample HTML when assertion is false for ease of debugging test
// case.
- if (actualText === expectedText)
+ if (actualText === expectedText) {
sample.remove();
- assert_equals(actualText, expectedText, description);
+ return;
+ }
+ throw new Error(`${description}\n` +
+ `\t expected ${expectedText},\n` +
+ `\t but got ${actualText},\n` +
+ `\t sameupto ${commonPrefixOf(expectedText, actualText)}`);
}
// Export symbols
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/assert_selection.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698