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

Unified Diff: third_party/WebKit/Source/platform/text/HyphenationTest.cpp

Issue 2713553007: Merge 2987: Fix hyphenated words not to overflow on Android (Closed)
Patch Set: 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/platform/text/HyphenationTest.cpp
diff --git a/third_party/WebKit/Source/platform/text/HyphenationTest.cpp b/third_party/WebKit/Source/platform/text/HyphenationTest.cpp
index f4acfb61d5b20c918a046af4aae06fd8a23b74a7..aca243d1351a7d068c973e4a0ae97f776747fe44 100644
--- a/third_party/WebKit/Source/platform/text/HyphenationTest.cpp
+++ b/third_party/WebKit/Source/platform/text/HyphenationTest.cpp
@@ -7,6 +7,11 @@
#include "platform/LayoutLocale.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if OS(ANDROID)
+#include "base/files/file_path.h"
+#include "platform/text/hyphenation/HyphenationMinikin.h"
+#endif
+
namespace blink {
class NoHyphenation : public Hyphenation {
@@ -28,4 +33,52 @@ TEST(HyphenationTest, Get) {
LayoutLocale::clearForTesting();
}
+#if OS(ANDROID) || OS(MACOSX)
+TEST(HyphenationTest, LastHyphenLocation) {
+#if OS(ANDROID)
+ // Because the mojo service to open hyphenation dictionaries is not accessible
+ // from the unit test, open the dictionary file directly for testing.
+ base::FilePath path("/system/usr/hyphen-data/hyph-en-us.hyb");
+ base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ if (!file.IsValid()) {
+ // Ignore this test on platforms without hyphenation dictionaries.
+ return;
+ }
+ RefPtr<Hyphenation> hyphenation =
+ HyphenationMinikin::fromFileForTesting(std::move(file));
+#else
+ const LayoutLocale* locale = LayoutLocale::get("en-us");
+ ASSERT_TRUE(locale);
+ Hyphenation* hyphenation = locale->getHyphenation();
+#endif
+ ASSERT_TRUE(hyphenation) << "Cannot find the hyphenation engine";
+
+ // Get all hyphenation points by |hyphenLocations|.
+ const String word("hyphenation");
+ Vector<size_t, 8> locations = hyphenation->hyphenLocations(word);
+ for (unsigned i = 1; i < locations.size(); i++) {
+ ASSERT_GT(locations[i - 1], locations[i])
+ << "hyphenLocations must return locations in the descending order";
+ }
+
+ // Test |lastHyphenLocation| returns all hyphenation points.
+ locations.push_back(0);
+ size_t locationIndex = locations.size() - 1;
+ for (size_t beforeIndex = 0; beforeIndex < word.length(); beforeIndex++) {
+ size_t location = hyphenation->lastHyphenLocation(word, beforeIndex);
+
+ if (location)
+ EXPECT_LT(location, beforeIndex);
+
+ if (locationIndex > 0 && location == locations[locationIndex - 1])
+ locationIndex--;
+ EXPECT_EQ(locations[locationIndex], location) << String::format(
+ "lastHyphenLocation(%s, %zd)", word.utf8().data(), beforeIndex);
+ }
+
+ EXPECT_EQ(locationIndex, 0u)
+ << "Not all locations are found by lastHyphenLocation";
+}
+#endif
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/BUILD.gn ('k') | third_party/WebKit/Source/platform/text/hyphenation/HyphenationMinikin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698