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

Unified Diff: third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp

Issue 2725603002: createFragmentFromMarkupWithContext() should use EphemeralRange. (Closed)
Patch Set: Y Created 3 years, 10 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
Index: third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp b/third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp
index fe6bc1115e6861bef28187d856c7e06a0aeb23eb..79f7f4b6a06be2b026947e83cd32f919729fbeee 100644
--- a/third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp
+++ b/third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp
@@ -18,6 +18,10 @@ class EphemeralRangeTest : public EditingTestBase {
template <typename Strategy>
std::string traverseRange(const EphemeralRangeTemplate<Strategy>&) const;
+ template <typename Strategy>
+ std::string commonAncesstorNode(
+ const EphemeralRangeTemplate<Strategy>&) const;
+
Range* getBodyRange() const;
};
@@ -48,6 +52,16 @@ Range* EphemeralRangeTest::getBodyRange() const {
return range;
}
+template <typename Strategy>
+std::string EphemeralRangeTest::commonAncesstorNode(
+ const EphemeralRangeTemplate<Strategy>& range) const {
+ std::stringstream nodesContent;
+
+ nodesContent << "[" << *range.commonAncestorContainer() << "]";
+
+ return nodesContent.str();
+}
+
// Tests that |EphemeralRange::nodes()| will traverse the whole range exactly as
// |for (Node* n = firstNode(); n != pastLastNode(); n = Traversal::next(*n))|
// does.
@@ -148,4 +162,31 @@ TEST_F(EphemeralRangeTest, traversalEmptyRanges) {
singlePositionRange.endPosition().nodeAsRangePastLastNode());
}
+TEST_F(EphemeralRangeTest, commonAncesstor) {
Xiaocheng 2017/03/02 20:00:16 Each test case is supposed to be minimized. So, w
tanvir 2017/03/04 13:55:31 Separate test cases for DOM and Flat tree is added
+ const char* bodyContent =
+ "<p id='host'><b id='one'></b><input type='text' "
Xiaocheng 2017/03/02 20:00:16 Hmm... I don't like the existing test cases at all
tanvir 2017/03/04 13:55:31 New HTML used.
+ "value='some'><span "
+ "id='two'></p>";
+
+ setBodyContent(bodyContent);
+
+ Range* range = getBodyRange();
+ range->setStart(document().getElementById("one"), 0,
+ IGNORE_EXCEPTION_FOR_TESTING);
+
+ // Range* endPos = getBodyRange();
+ range->setEnd(document().getElementById("two"), 0,
+ IGNORE_EXCEPTION_FOR_TESTING);
+
+ const EphemeralRange ephemeralRange(range->startPosition(),
+ range->endPosition());
+ EXPECT_EQ("[P id=\"host\"]", commonAncesstorNode<>(ephemeralRange));
Xiaocheng 2017/03/02 20:00:16 There's no need to do string comparison, as there
tanvir 2017/03/04 13:55:31 Done!!
+
+ // CommonAncesstorCotainer for FlatTree
+ EXPECT_EQ("[P id=\"host\"]",
Xiaocheng 2017/03/02 20:00:16 For the test case for flat tree, to make the test
tanvir 2017/03/04 13:55:31 Taken care of this scenario. This tree is returnin
+ commonAncesstorNode(EphemeralRangeInFlatTree(
+ toPositionInFlatTree(range->startPosition()),
+ toPositionInFlatTree(range->endPosition()))));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698