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

Unified Diff: Source/core/editing/CompositionUnderlineRangeFilterTest.cpp

Issue 1330233003: Revert of Avoid style clobbering in setCompositionFromExistingText. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 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 | « Source/core/editing/CompositionUnderlineRangeFilter.cpp ('k') | Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/CompositionUnderlineRangeFilterTest.cpp
diff --git a/Source/core/editing/CompositionUnderlineRangeFilterTest.cpp b/Source/core/editing/CompositionUnderlineRangeFilterTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a179dda1ba7cc0deb55c0c8f7fb3f84af0f437e1
--- /dev/null
+++ b/Source/core/editing/CompositionUnderlineRangeFilterTest.cpp
@@ -0,0 +1,88 @@
+// Copyright 2014 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 "config.h"
+#include "core/editing/CompositionUnderlineRangeFilter.h"
+
+#include "core/editing/CompositionUnderline.h"
+#include "platform/graphics/Color.h"
+#include "wtf/Vector.h"
+#include "wtf/text/IntegerToStringConversion.h"
+#include "wtf/text/WTFString.h"
+#include <gtest/gtest.h>
+
+namespace blink {
+
+// Parses test case string and populate |underlines|.
+void initUnderlines(const String& testCase, Vector<CompositionUnderline>* underlines)
+{
+ ASSERT(underlines && underlines->size() == 0U);
+ Vector<String> rangeList;
+ testCase.split('|', rangeList);
+ // Intervals are named 'A', 'B', ..., 'Z', so ensure there aren't too many.
+ ASSERT_LE(rangeList.size(), static_cast<size_t>('Z' - 'A'));
+ for (unsigned i = 0; i < rangeList.size(); ++i) {
+ String range = rangeList[i];
+ Vector<String> toks;
+ rangeList[i].split(',', toks);
+ ASSERT_EQ(2U, toks.size());
+ int startOffset = toks[0].toInt();
+ int endOffset = toks[1].toInt();
+ ASSERT_LE(startOffset, endOffset);
+ // For testing: Store i in red component of |color|, so the intervals
+ // can be distinguished.
+ underlines->append(CompositionUnderline(startOffset, endOffset, Color(i, 0, 0), false, 0));
+ }
+}
+
+// Runs the filter and encodes the result into a string, with 'A' as first
+// elemnt, 'B' as second, etc.
+String filterUnderlines(const Vector<CompositionUnderline>& underlines, int indexLo, int indexHi)
+{
+ CompositionUnderlineRangeFilter filter(underlines, indexLo, indexHi);
+ String ret = "";
+ for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begin(); it != filter.end(); ++it) {
+ int code = (*it).color.red();
+ ret.append(static_cast<char>('A' + code));
+ }
+ return ret;
+}
+
+TEST(CompositionUnderlineRangeFilterTest, Empty)
+{
+ Vector<CompositionUnderline> underlines;
+ EXPECT_EQ("", filterUnderlines(underlines, 0, 10));
+ EXPECT_EQ("", filterUnderlines(underlines, 5, 5));
+}
+
+TEST(CompositionUnderlineRangeFilterTest, Single)
+{
+ String testCase = "10,20"; // Semi-closed interval: {10, 11, ..., 19}.
+ Vector<CompositionUnderline> underlines;
+ initUnderlines(testCase, &underlines);
+ // The query intervals are all closed, e.g., [0, 9] = {0, ..., 9}.
+ EXPECT_EQ("", filterUnderlines(underlines, 0, 9));
+ EXPECT_EQ("A", filterUnderlines(underlines, 5, 10));
+ EXPECT_EQ("A", filterUnderlines(underlines, 10, 20));
+ EXPECT_EQ("A", filterUnderlines(underlines, 15, 25));
+ EXPECT_EQ("A", filterUnderlines(underlines, 19, 30));
+ EXPECT_EQ("", filterUnderlines(underlines, 20, 25));
+ EXPECT_EQ("A", filterUnderlines(underlines, 5, 25));
+}
+
+TEST(CompositionUnderlineRangeFilterTest, Multi)
+{
+ String testCase = "0,2|0,5|1,3|1,10|3,5|5,8|7,8|8,10";
+ Vector<CompositionUnderline> underlines;
+ initUnderlines(testCase, &underlines);
+ EXPECT_EQ("", filterUnderlines(underlines, 11, 11));
+ EXPECT_EQ("ABCDEFGH", filterUnderlines(underlines, 0, 9));
+ EXPECT_EQ("BDEF", filterUnderlines(underlines, 4, 5));
+ EXPECT_EQ("AB", filterUnderlines(underlines, 0, 0));
+ EXPECT_EQ("BDE", filterUnderlines(underlines, 3, 3));
+ EXPECT_EQ("DF", filterUnderlines(underlines, 5, 5));
+ EXPECT_EQ("DFG", filterUnderlines(underlines, 7, 7));
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/editing/CompositionUnderlineRangeFilter.cpp ('k') | Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698