Commit 224f96bc authored by Gayane Petrosyan's avatar Gayane Petrosyan Committed by Commit Bot

[Sh-Blink] Variable used for range selector should be reset

Bug: 1136464
Change-Id: Ibfae772d5d289a74b1cffdb83f74ba8a370c08b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461118Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815373}
parent f9bf5b10
......@@ -238,6 +238,8 @@ void TextFragmentSelectorGenerator::GenerateSelector(
step_ = kExact;
max_available_prefix_ = "";
max_available_suffix_ = "";
max_available_range_start_ = "";
max_available_range_end_ = "";
num_prefix_words_ = 0;
num_suffix_words_ = 0;
iteration_ = 0;
......@@ -417,7 +419,6 @@ void TextFragmentSelectorGenerator::GenerateExactSelector() {
void TextFragmentSelectorGenerator::ExtendRangeSelector() {
DCHECK_EQ(kRange, step_);
DCHECK_EQ(kNeedsNewCandidate, state_);
// Give up if range is already too long.
if (num_range_start_words_ == kMaxRangeWords ||
num_range_end_words_ == kMaxRangeWords) {
......
......@@ -495,6 +495,54 @@ text text text text text text text text text and last text",
"First%20paragraph,last%20text");
}
// It should be more than 300 characters selected from the same node so that
// ranges are used.
TEST_F(TextFragmentSelectorGeneratorTest,
RangeSelector_SameNode_MultipleSelections) {
SimRequest request("https://example.com/test.html", "text/html");
LoadURL("https://example.com/test.html");
request.Complete(R"HTML(
<!DOCTYPE html>
<div>Test page</div>
<p id='first'>First paragraph text text text text text text text
text text text text text text text text text text text text text
text text text text text text text text text text text text text
text text text text text text text text text text text text text
text text text text text text text text text text and last text</p>
)HTML");
Node* first_paragraph = GetDocument().getElementById("first")->firstChild();
const auto& selected_start = Position(first_paragraph, 0);
const auto& selected_end = Position(first_paragraph, 325);
ASSERT_EQ(
"First paragraph text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text and last text",
PlainText(EphemeralRange(selected_start, selected_end)));
ASSERT_EQ(309u,
PlainText(EphemeralRange(selected_start, selected_end)).length());
GenerateAndVerifySelector(selected_start, selected_end,
"First%20paragraph,last%20text");
const auto& second_selected_start = Position(first_paragraph, 6);
const auto& second_selected_end = Position(first_paragraph, 325);
ASSERT_EQ(
"paragraph text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text text text text \
text text text text text text text text text text and last text",
PlainText(EphemeralRange(second_selected_start, second_selected_end)));
ASSERT_EQ(303u, PlainText(EphemeralRange(second_selected_start,
second_selected_end))
.length());
GenerateAndVerifySelector(second_selected_start, second_selected_end,
"paragraph%20text%20text,and%20last%20text");
}
// When using all the selected text for the range is not enough for unique
// match, context should be added.
TEST_F(TextFragmentSelectorGeneratorTest, RangeSelector_RangeNotUnique) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment