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

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

Issue 2393403002: Introduce Selection class (Closed)
Patch Set: 2016-10-12T15:57:57 Created 4 years, 2 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/Source/core/editing/SelectionTemplate.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/SelectionTemplateTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/SelectionTemplateTest.cpp b/third_party/WebKit/Source/core/editing/SelectionTemplateTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e1f986475f2f13d8a97cbefb27421fa02eddf55d
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/SelectionTemplateTest.cpp
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/SelectionTemplate.h"
+
+#include "core/editing/EditingTestBase.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class SelectionTest : public EditingTestBase {};
+
+TEST_F(SelectionTest, defaultConstructor) {
+ SelectionInDOMTree selection;
+
+ EXPECT_EQ(TextAffinity::Downstream, selection.affinity());
+ EXPECT_EQ(CharacterGranularity, selection.granularity());
+ EXPECT_FALSE(selection.hasTrailingWhitespace());
+ EXPECT_FALSE(selection.isDirectional());
+ EXPECT_TRUE(selection.isNone());
+ EXPECT_EQ(Position(), selection.base());
+ EXPECT_EQ(Position(), selection.extent());
+}
+
+TEST_F(SelectionTest, caret) {
+ setBodyContent("<div id='sample'>abcdef</div>");
+
+ Element* sample = document().getElementById("sample");
+ Position position(Position(sample->firstChild(), 2));
+ SelectionInDOMTree::Builder builder;
+ builder.collapse(position);
+ const SelectionInDOMTree& selection = builder.build();
+
+ EXPECT_EQ(TextAffinity::Downstream, selection.affinity());
+ EXPECT_EQ(CharacterGranularity, selection.granularity());
+ EXPECT_FALSE(selection.hasTrailingWhitespace());
+ EXPECT_FALSE(selection.isDirectional());
+ EXPECT_FALSE(selection.isNone());
+ EXPECT_EQ(position, selection.base());
+ EXPECT_EQ(position, selection.extent());
+}
+
+TEST_F(SelectionTest, range) {
+ setBodyContent("<div id='sample'>abcdef</div>");
+
+ Element* sample = document().getElementById("sample");
+ Position base(Position(sample->firstChild(), 2));
+ Position extent(Position(sample->firstChild(), 4));
+ SelectionInDOMTree::Builder builder;
+ builder.collapse(base);
+ builder.extend(extent);
+ const SelectionInDOMTree& selection = builder.build();
+
+ EXPECT_EQ(TextAffinity::Downstream, selection.affinity());
+ EXPECT_EQ(CharacterGranularity, selection.granularity());
+ EXPECT_FALSE(selection.hasTrailingWhitespace());
+ EXPECT_FALSE(selection.isDirectional());
+ EXPECT_FALSE(selection.isNone());
+ EXPECT_EQ(base, selection.base());
+ EXPECT_EQ(extent, selection.extent());
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/editing/SelectionTemplate.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698