Chromium Code Reviews| 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..f73b475950ce20be77fb54ddd9e913471bb6dfb3 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,20 @@ function checkExpectedText(expectedText) { |
| } |
| /** |
| + * @param {string} str1 |
| + * @param {string} str2 |
| + */ |
|
yosin_UTC9
2016/07/12 01:58:36
Please add
@return {string}
yoichio
2016/07/12 04:12:30
Done.
|
| +function commonSubstr(str1, str2) { |
|
yosin_UTC9
2016/07/12 02:26:54
This function should be named |commonPrefixOf()| a
yoichio
2016/07/12 04:12:30
Done.
|
| + const comparedLength = Math.min(str1.length, str2.length); |
| + var i = 0; |
|
yosin_UTC9
2016/07/12 01:58:36
nit: Since out of bound access of Array returns |u
yoichio
2016/07/12 04:12:30
Done.
|
| + for (; i < comparedLength; ++i) { |
| + if (str1[i] !== str2[i]) |
| + break; |
| + } |
| + return str1.substr(0, i) |
| +} |
| + |
| +/** |
| * @param {string} inputText |
| * @param {function(!Selection)|string} |
| * @param {string} expectedText |
| @@ -652,9 +667,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); |
| + } else { |
| + throw new Error(`${description}\n` + |
| + `\t expected ${expectedText},\n` + |
| + `\t but got ${actualText},\n` + |
| + `\t sameupto ${commonSubstr(expectedText, actualText)}`); |
| + } |
| } |
| // Export symbols |