| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/hyphenator/hyphenator.h" | 5 #include "content/renderer/hyphenator/hyphenator.h" |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "content/common/hyphenator_messages.h" | 10 #include "content/common/hyphenator_messages.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // are internal messages and unit tests cannot access its member functions, | 37 // are internal messages and unit tests cannot access its member functions, |
| 38 // i.e. unit tests cannot call the HyphenatorHostMsg_OpenDictionary::Read | 38 // i.e. unit tests cannot call the HyphenatorHostMsg_OpenDictionary::Read |
| 39 // function. | 39 // function. |
| 40 PickleIterator iter(message); | 40 PickleIterator iter(message); |
| 41 string16 locale; | 41 string16 locale; |
| 42 EXPECT_TRUE(message.ReadString16(&iter, &locale)); | 42 EXPECT_TRUE(message.ReadString16(&iter, &locale)); |
| 43 EXPECT_EQ(locale_, locale); | 43 EXPECT_EQ(locale_, locale); |
| 44 | 44 |
| 45 // Open the default dictionary and call the OnControllMessageReceived | 45 // Open the default dictionary and call the OnControllMessageReceived |
| 46 // function with a HyphenatorMsg_SetDictionary message. | 46 // function with a HyphenatorMsg_SetDictionary message. |
| 47 FilePath dictionary_path; | 47 base::FilePath dictionary_path; |
| 48 if (!PathService::Get(base::DIR_SOURCE_ROOT, &dictionary_path)) | 48 if (!PathService::Get(base::DIR_SOURCE_ROOT, &dictionary_path)) |
| 49 return false; | 49 return false; |
| 50 dictionary_path = dictionary_path.AppendASCII("third_party"); | 50 dictionary_path = dictionary_path.AppendASCII("third_party"); |
| 51 dictionary_path = dictionary_path.AppendASCII("hyphen"); | 51 dictionary_path = dictionary_path.AppendASCII("hyphen"); |
| 52 dictionary_path = dictionary_path.AppendASCII("hyph_en_US.dic"); | 52 dictionary_path = dictionary_path.AppendASCII("hyph_en_US.dic"); |
| 53 base::PlatformFile file = base::CreatePlatformFile( | 53 base::PlatformFile file = base::CreatePlatformFile( |
| 54 dictionary_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 54 dictionary_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 55 NULL, NULL); | 55 NULL, NULL); |
| 56 EXPECT_NE(base::kInvalidPlatformFileValue, file); | 56 EXPECT_NE(base::kInvalidPlatformFileValue, file); |
| 57 | 57 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 // A unit test for our hyphenator. This class loads a sample hyphenation | 79 // A unit test for our hyphenator. This class loads a sample hyphenation |
| 80 // dictionary and hyphenates words. | 80 // dictionary and hyphenates words. |
| 81 class HyphenatorTest : public testing::Test { | 81 class HyphenatorTest : public testing::Test { |
| 82 public: | 82 public: |
| 83 HyphenatorTest() { | 83 HyphenatorTest() { |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool Initialize() { | 86 bool Initialize() { |
| 87 FilePath dictionary_path; | 87 base::FilePath dictionary_path; |
| 88 if (!PathService::Get(base::DIR_SOURCE_ROOT, &dictionary_path)) | 88 if (!PathService::Get(base::DIR_SOURCE_ROOT, &dictionary_path)) |
| 89 return false; | 89 return false; |
| 90 dictionary_path = dictionary_path.AppendASCII("third_party"); | 90 dictionary_path = dictionary_path.AppendASCII("third_party"); |
| 91 dictionary_path = dictionary_path.AppendASCII("hyphen"); | 91 dictionary_path = dictionary_path.AppendASCII("hyphen"); |
| 92 dictionary_path = dictionary_path.AppendASCII("hyph_en_US.dic"); | 92 dictionary_path = dictionary_path.AppendASCII("hyph_en_US.dic"); |
| 93 base::PlatformFile file = base::CreatePlatformFile( | 93 base::PlatformFile file = base::CreatePlatformFile( |
| 94 dictionary_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | 94 dictionary_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 95 NULL, NULL); | 95 NULL, NULL); |
| 96 hyphenator_.reset(new Hyphenator(file)); | 96 hyphenator_.reset(new Hyphenator(file)); |
| 97 return hyphenator_->Initialize(); | 97 return hyphenator_->Initialize(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Verify that we can now hyphenate words. When the MockListener class | 182 // Verify that we can now hyphenate words. When the MockListener class |
| 183 // receives a HyphenatorHostMsg_OpenDictionary message, it calls the | 183 // receives a HyphenatorHostMsg_OpenDictionary message, it calls the |
| 184 // OnControlMessageReceived function with a HyphenatorMsg_SetDictionary | 184 // OnControlMessageReceived function with a HyphenatorMsg_SetDictionary |
| 185 // message. So, the Hyphenate function should be able to hyphenate words now. | 185 // message. So, the Hyphenate function should be able to hyphenate words now. |
| 186 string16 input = ASCIIToUTF16("hyphenation"); | 186 string16 input = ASCIIToUTF16("hyphenation"); |
| 187 string16 expected = ASCIIToUTF16("hy-phen-ation"); | 187 string16 expected = ASCIIToUTF16("hy-phen-ation"); |
| 188 EXPECT_EQ(expected, Hyphenate(input)); | 188 EXPECT_EQ(expected, Hyphenate(input)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace content | 191 } // namespace content |
| OLD | NEW |