OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/file_locations.h" |
| 6 |
| 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" |
| 11 |
| 12 extern std::string GetLocalizedFileName(const std::string& base_name, |
| 13 const std::string& locale, |
| 14 const std::string& ext); |
| 15 |
| 16 extern std::string GetIOSLocaleMapping(const std::string& locale); |
| 17 |
| 18 namespace { |
| 19 |
| 20 class FileLocationsTest : public PlatformTest { |
| 21 protected: |
| 22 void SetUp() override { |
| 23 // These files must exist for this unit test to pass. |
| 24 termsBaseName_ = "terms"; |
| 25 extension_ = "html"; |
| 26 enFile_ = "terms_en.html"; |
| 27 frFile_ = "terms_fr.html"; |
| 28 } |
| 29 std::string termsBaseName_; |
| 30 std::string extension_; |
| 31 std::string enFile_; |
| 32 std::string frFile_; |
| 33 }; |
| 34 |
| 35 TEST_F(FileLocationsTest, TestTermsOfServiceUrl) { |
| 36 std::string filename(GetTermsOfServicePath()); |
| 37 EXPECT_FALSE(filename.empty()); |
| 38 } |
| 39 |
| 40 TEST_F(FileLocationsTest, TestIOSLocaleMapping) { |
| 41 EXPECT_EQ("en-US", GetIOSLocaleMapping("en-US")); |
| 42 EXPECT_EQ("es", GetIOSLocaleMapping("es")); |
| 43 EXPECT_EQ("es-419", GetIOSLocaleMapping("es-MX")); |
| 44 EXPECT_EQ("pt-BR", GetIOSLocaleMapping("pt")); |
| 45 EXPECT_EQ("pt-PT", GetIOSLocaleMapping("pt-PT")); |
| 46 EXPECT_EQ("zh-CN", GetIOSLocaleMapping("zh-Hans")); |
| 47 EXPECT_EQ("zh-TW", GetIOSLocaleMapping("zh-Hant")); |
| 48 } |
| 49 |
| 50 TEST_F(FileLocationsTest, TestFileNameLocaleWithExtension) { |
| 51 EXPECT_EQ(enFile_, GetLocalizedFileName(termsBaseName_, "en", extension_)); |
| 52 EXPECT_EQ(frFile_, GetLocalizedFileName(termsBaseName_, "fr", extension_)); |
| 53 EXPECT_EQ(frFile_, GetLocalizedFileName(termsBaseName_, "fr-XX", extension_)); |
| 54 |
| 55 // No ToS for "xx" locale so expect default "en" ToS. Unlikely, but this |
| 56 // test will fail once the ToS for "xx" locale is added. |
| 57 EXPECT_EQ(enFile_, GetLocalizedFileName(termsBaseName_, "xx", extension_)); |
| 58 } |
| 59 |
| 60 // Tests that locale/languages available on iOS are mapped to either a |
| 61 // translated Chrome Terms of Service or to English. |
| 62 TEST_F(FileLocationsTest, TestTermsOfServiceForSupportedLanguages) { |
| 63 // List of available localized terms_*.html files. Note that this list is |
| 64 // hardcoded and needs to be manually maintained as new locales are added |
| 65 // to Chrome. See http://crbug/522638 |
| 66 NSSet* localizedTermsHtml = |
| 67 [NSSet setWithObjects:@"ar", @"bg", @"ca", @"cs", @"da", @"de", @"el", |
| 68 @"en-GB", @"en", @"es-419", @"es", @"fa", @"fi", |
| 69 @"fr", @"he", @"hi", @"hr", @"hu", @"id", @"it", |
| 70 @"ja", @"ko", @"lt", @"nb", @"nl", @"pl", @"pt-BR", |
| 71 @"pt-PT", @"ro", @"ru", @"sk", @"sr", @"sv", @"th", |
| 72 @"tr", @"uk", @"vi", @"zh-CN", @"zh-TW", nil]; |
| 73 for (NSString* locale in [NSLocale availableLocaleIdentifiers]) { |
| 74 NSString* normalizedLocale = |
| 75 [locale stringByReplacingOccurrencesOfString:@"_" withString:@"-"]; |
| 76 NSArray* parts = [normalizedLocale componentsSeparatedByString:@"-"]; |
| 77 NSString* language = [parts objectAtIndex:0]; |
| 78 std::string filename = GetLocalizedFileName( |
| 79 termsBaseName_, |
| 80 GetIOSLocaleMapping(base::SysNSStringToUTF8(normalizedLocale)), |
| 81 extension_); |
| 82 if (filename == enFile_ && ![language isEqualToString:@"en"]) { |
| 83 NSLog(@"OK: Locale %@ using language %@ falls back to use English ToS", |
| 84 locale, language); |
| 85 EXPECT_FALSE([localizedTermsHtml containsObject:language]); |
| 86 } |
| 87 } |
| 88 } |
| 89 |
| 90 } // namespace |
OLD | NEW |