forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Payments] Add a substring search method in WebNode
This patch adds a WebNode method that searches text in descendant elements to determine whether there is a matching substring in one of them. If there is a match, then the method returns the text content of the element that contains the substring. Otherwise, the method returns an empty string. Bug: 1475426 Change-Id: I7c2883c1f474006455fbf0c88c7606658d4b2061 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4951976 Reviewed-by: David Baron <dbaron@chromium.org> Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1232844}
- Loading branch information
1 parent
d190de3
commit 77b04b9
Showing
7 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
third_party/blink/renderer/core/dom/container_node_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/core/dom/container_node.h" | ||
|
||
#include "third_party/blink/renderer/core/editing/testing/editing_test_base.h" | ||
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" | ||
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" | ||
|
||
namespace blink { | ||
|
||
using ContainerNodeTest = EditingTestBase; | ||
|
||
TEST_F(ContainerNodeTest, HasOnlyTextReturnsFalseForEmptySpan) { | ||
SetBodyContent(R"HTML(<body><span id="id"><span><body>)HTML"); | ||
|
||
EXPECT_FALSE(GetDocument().getElementById(AtomicString("id"))->HasOnlyText()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, HasOnlyTextReturnsFalseForNonTextChild) { | ||
SetBodyContent(R"HTML(<body><div id="id"><div>Nested</div><div><body>)HTML"); | ||
|
||
EXPECT_FALSE(GetDocument().getElementById(AtomicString("id"))->HasOnlyText()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, HasOnlyTextReturnsTrueForSomeText) { | ||
SetBodyContent(R"HTML(<body><p id="id"> Here is some text <p><body>)HTML"); | ||
|
||
EXPECT_TRUE(GetDocument().getElementById(AtomicString("id"))->HasOnlyText()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, HasOnlyTextIgnoresComments) { | ||
SetBodyContent(R"HTML( | ||
<body> | ||
<p id="id"> Here is some text | ||
<!-- This is a comment that should be ignored. --> | ||
<p> | ||
<body> | ||
)HTML"); | ||
|
||
EXPECT_TRUE(GetDocument().getElementById(AtomicString("id"))->HasOnlyText()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, CannotFindTextInElementWithoutDescendants) { | ||
SetBodyContent(R"HTML(<body><span id="id"></span></body>)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString("anything")); | ||
|
||
EXPECT_TRUE(text.empty()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, CannotFindTextInElementWithNonTextDescendants) { | ||
SetBodyContent(R"HTML(<body><span id="id"> Hello | ||
<span></span> world! </span></body>)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString("anything")); | ||
|
||
EXPECT_TRUE(text.empty()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, CannotFindTextInElementWithoutMatchingSubtring) { | ||
SetBodyContent(R"HTML(<body><span id="id"> Hello </span></body>)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString("Goodbye")); | ||
|
||
EXPECT_TRUE(text.empty()); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, CanFindTextInElementWithOnlyTextDescendants) { | ||
SetBodyContent( | ||
R"HTML(<body><span id="id"> Find me please </span></body>)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString("me")); | ||
|
||
EXPECT_EQ(String(" Find me please "), text); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, CanFindTextInElementWithManyDescendants) { | ||
SetBodyContent(R"HTML( | ||
<body> | ||
<div id="id"> | ||
<div> | ||
No need to find this | ||
</div> | ||
<div> | ||
Something something here | ||
<div> Find me please </div> | ||
also over here | ||
</div> | ||
<div> | ||
And more information here | ||
</div> | ||
</div> | ||
<div> | ||
Hi | ||
</div> | ||
</body> | ||
)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString(" me ")); | ||
|
||
EXPECT_EQ(String(" Find me please "), text); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, FindTextInElementWithFirstMatch) { | ||
SetBodyContent(R"HTML( | ||
<body><div id="id"> | ||
<div> Text match #1 </div> | ||
<div> Text match #2 </div> | ||
</div></body> | ||
)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString(" match ")); | ||
|
||
EXPECT_EQ(String(" Text match #1 "), text); | ||
} | ||
|
||
TEST_F(ContainerNodeTest, FindTextInElementWithSubstringIgnoresComments) { | ||
SetBodyContent(R"HTML( | ||
<body> | ||
<p id="id"> Before comment, <!-- The comment. --> after comment. <p> | ||
<body> | ||
)HTML"); | ||
|
||
String text = GetDocument().FindTextInElementWith(AtomicString("comment")); | ||
|
||
EXPECT_EQ(String(" Before comment, after comment. "), text); | ||
} | ||
|
||
} // namespace blink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters