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

Side by Side 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, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/text/Hyphenation.h" 5 #include "platform/text/Hyphenation.h"
6 6
7 #include "platform/LayoutLocale.h" 7 #include "platform/LayoutLocale.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #if OS(ANDROID)
11 #include "base/files/file_path.h"
12 #include "platform/text/hyphenation/HyphenationMinikin.h"
13 #endif
14
10 namespace blink { 15 namespace blink {
11 16
12 class NoHyphenation : public Hyphenation { 17 class NoHyphenation : public Hyphenation {
13 public: 18 public:
14 size_t lastHyphenLocation(const StringView&, 19 size_t lastHyphenLocation(const StringView&,
15 size_t beforeIndex) const override { 20 size_t beforeIndex) const override {
16 return 0; 21 return 0;
17 } 22 }
18 }; 23 };
19 24
20 TEST(HyphenationTest, Get) { 25 TEST(HyphenationTest, Get) {
21 RefPtr<Hyphenation> hyphenation = adoptRef(new NoHyphenation); 26 RefPtr<Hyphenation> hyphenation = adoptRef(new NoHyphenation);
22 LayoutLocale::setHyphenationForTesting("en-US", hyphenation); 27 LayoutLocale::setHyphenationForTesting("en-US", hyphenation);
23 EXPECT_EQ(hyphenation.get(), LayoutLocale::get("en-US")->getHyphenation()); 28 EXPECT_EQ(hyphenation.get(), LayoutLocale::get("en-US")->getHyphenation());
24 29
25 LayoutLocale::setHyphenationForTesting("en-UK", nullptr); 30 LayoutLocale::setHyphenationForTesting("en-UK", nullptr);
26 EXPECT_EQ(nullptr, LayoutLocale::get("en-UK")->getHyphenation()); 31 EXPECT_EQ(nullptr, LayoutLocale::get("en-UK")->getHyphenation());
27 32
28 LayoutLocale::clearForTesting(); 33 LayoutLocale::clearForTesting();
29 } 34 }
30 35
36 #if OS(ANDROID) || OS(MACOSX)
37 TEST(HyphenationTest, LastHyphenLocation) {
38 #if OS(ANDROID)
39 // Because the mojo service to open hyphenation dictionaries is not accessible
40 // from the unit test, open the dictionary file directly for testing.
41 base::FilePath path("/system/usr/hyphen-data/hyph-en-us.hyb");
42 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
43 if (!file.IsValid()) {
44 // Ignore this test on platforms without hyphenation dictionaries.
45 return;
46 }
47 RefPtr<Hyphenation> hyphenation =
48 HyphenationMinikin::fromFileForTesting(std::move(file));
49 #else
50 const LayoutLocale* locale = LayoutLocale::get("en-us");
51 ASSERT_TRUE(locale);
52 Hyphenation* hyphenation = locale->getHyphenation();
53 #endif
54 ASSERT_TRUE(hyphenation) << "Cannot find the hyphenation engine";
55
56 // Get all hyphenation points by |hyphenLocations|.
57 const String word("hyphenation");
58 Vector<size_t, 8> locations = hyphenation->hyphenLocations(word);
59 for (unsigned i = 1; i < locations.size(); i++) {
60 ASSERT_GT(locations[i - 1], locations[i])
61 << "hyphenLocations must return locations in the descending order";
62 }
63
64 // Test |lastHyphenLocation| returns all hyphenation points.
65 locations.push_back(0);
66 size_t locationIndex = locations.size() - 1;
67 for (size_t beforeIndex = 0; beforeIndex < word.length(); beforeIndex++) {
68 size_t location = hyphenation->lastHyphenLocation(word, beforeIndex);
69
70 if (location)
71 EXPECT_LT(location, beforeIndex);
72
73 if (locationIndex > 0 && location == locations[locationIndex - 1])
74 locationIndex--;
75 EXPECT_EQ(locations[locationIndex], location) << String::format(
76 "lastHyphenLocation(%s, %zd)", word.utf8().data(), beforeIndex);
77 }
78
79 EXPECT_EQ(locationIndex, 0u)
80 << "Not all locations are found by lastHyphenLocation";
81 }
82 #endif
83
31 } // namespace blink 84 } // namespace blink
OLDNEW
« 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