| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "chrome/installer/util/language_selector.h" | 8 #include "chrome/installer/util/language_selector.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 L"en-AU", | 37 L"en-AU", |
| 38 #if defined(GOOGLE_CHROME_BUILD) | 38 #if defined(GOOGLE_CHROME_BUILD) |
| 39 L"es-CO", L"pt-AB", L"zh-SG" | 39 L"es-CO", L"pt-AB", L"zh-SG" |
| 40 #endif | 40 #endif |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // Test that a language is selected from the system. | 45 // Test that a language is selected from the system. |
| 46 TEST(LanguageSelectorTest, DefaultSelection) { | 46 TEST(LanguageSelectorTest, DefaultSelection) { |
| 47 installer_util::LanguageSelector instance; | 47 installer::LanguageSelector instance; |
| 48 EXPECT_FALSE(instance.matched_candidate().empty()); | 48 EXPECT_FALSE(instance.matched_candidate().empty()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Test some hypothetical candidate sets. | 51 // Test some hypothetical candidate sets. |
| 52 TEST(LanguageSelectorTest, AssortedSelections) { | 52 TEST(LanguageSelectorTest, AssortedSelections) { |
| 53 { | 53 { |
| 54 std::wstring candidates[] = { | 54 std::wstring candidates[] = { |
| 55 L"fr-BE", L"fr", L"en" | 55 L"fr-BE", L"fr", L"en" |
| 56 }; | 56 }; |
| 57 installer_util::LanguageSelector instance( | 57 installer::LanguageSelector instance( |
| 58 std::vector<std::wstring>(&candidates[0], | 58 std::vector<std::wstring>(&candidates[0], |
| 59 &candidates[arraysize(candidates)])); | 59 &candidates[arraysize(candidates)])); |
| 60 #if defined(GOOGLE_CHROME_BUILD) | 60 #if defined(GOOGLE_CHROME_BUILD) |
| 61 // Expect the exact match to win. | 61 // Expect the exact match to win. |
| 62 EXPECT_EQ(L"fr", instance.matched_candidate()); | 62 EXPECT_EQ(L"fr", instance.matched_candidate()); |
| 63 #else | 63 #else |
| 64 // Expect the exact match to win. | 64 // Expect the exact match to win. |
| 65 EXPECT_EQ(L"en", instance.matched_candidate()); | 65 EXPECT_EQ(L"en", instance.matched_candidate()); |
| 66 #endif | 66 #endif |
| 67 } | 67 } |
| 68 { | 68 { |
| 69 std::wstring candidates[] = { | 69 std::wstring candidates[] = { |
| 70 L"xx-YY", L"cc-Ssss-RR" | 70 L"xx-YY", L"cc-Ssss-RR" |
| 71 }; | 71 }; |
| 72 installer_util::LanguageSelector instance( | 72 installer::LanguageSelector instance( |
| 73 std::vector<std::wstring>(&candidates[0], | 73 std::vector<std::wstring>(&candidates[0], |
| 74 &candidates[arraysize(candidates)])); | 74 &candidates[arraysize(candidates)])); |
| 75 // Expect the fallback to win. | 75 // Expect the fallback to win. |
| 76 EXPECT_EQ(L"en-us", instance.matched_candidate()); | 76 EXPECT_EQ(L"en-us", instance.matched_candidate()); |
| 77 } | 77 } |
| 78 { | 78 { |
| 79 std::wstring candidates[] = { | 79 std::wstring candidates[] = { |
| 80 L"zh-SG", L"en-GB" | 80 L"zh-SG", L"en-GB" |
| 81 }; | 81 }; |
| 82 installer_util::LanguageSelector instance( | 82 installer::LanguageSelector instance( |
| 83 std::vector<std::wstring>(&candidates[0], | 83 std::vector<std::wstring>(&candidates[0], |
| 84 &candidates[arraysize(candidates)])); | 84 &candidates[arraysize(candidates)])); |
| 85 #if defined(GOOGLE_CHROME_BUILD) | 85 #if defined(GOOGLE_CHROME_BUILD) |
| 86 // Expect the alias match to win. | 86 // Expect the alias match to win. |
| 87 EXPECT_EQ(L"zh-SG", instance.matched_candidate()); | 87 EXPECT_EQ(L"zh-SG", instance.matched_candidate()); |
| 88 #else | 88 #else |
| 89 // Expect the exact match to win. | 89 // Expect the exact match to win. |
| 90 EXPECT_EQ(L"en-GB", instance.matched_candidate()); | 90 EXPECT_EQ(L"en-GB", instance.matched_candidate()); |
| 91 #endif | 91 #endif |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 // A fixture for testing sets of single-candidate selections. | 95 // A fixture for testing sets of single-candidate selections. |
| 96 class LanguageSelectorMatchCandidateTest | 96 class LanguageSelectorMatchCandidateTest |
| 97 : public ::testing::TestWithParam<const wchar_t*> { | 97 : public ::testing::TestWithParam<const wchar_t*> { |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 TEST_P(LanguageSelectorMatchCandidateTest, TestMatchCandidate) { | 100 TEST_P(LanguageSelectorMatchCandidateTest, TestMatchCandidate) { |
| 101 installer_util::LanguageSelector instance( | 101 installer::LanguageSelector instance( |
| 102 std::vector<std::wstring>(1, std::wstring(GetParam()))); | 102 std::vector<std::wstring>(1, std::wstring(GetParam()))); |
| 103 EXPECT_EQ(GetParam(), instance.matched_candidate()); | 103 EXPECT_EQ(GetParam(), instance.matched_candidate()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Test that all existing translations can be found by exact match. | 106 // Test that all existing translations can be found by exact match. |
| 107 INSTANTIATE_TEST_CASE_P( | 107 INSTANTIATE_TEST_CASE_P( |
| 108 TestExactMatches, | 108 TestExactMatches, |
| 109 LanguageSelectorMatchCandidateTest, | 109 LanguageSelectorMatchCandidateTest, |
| 110 ::testing::ValuesIn( | 110 ::testing::ValuesIn( |
| 111 &kExactMatchCandidates[0], | 111 &kExactMatchCandidates[0], |
| 112 &kExactMatchCandidates[arraysize(kExactMatchCandidates)])); | 112 &kExactMatchCandidates[arraysize(kExactMatchCandidates)])); |
| 113 | 113 |
| 114 // Test the alias matches. | 114 // Test the alias matches. |
| 115 INSTANTIATE_TEST_CASE_P( | 115 INSTANTIATE_TEST_CASE_P( |
| 116 TestAliasMatches, | 116 TestAliasMatches, |
| 117 LanguageSelectorMatchCandidateTest, | 117 LanguageSelectorMatchCandidateTest, |
| 118 ::testing::ValuesIn( | 118 ::testing::ValuesIn( |
| 119 &kAliasMatchCandidates[0], | 119 &kAliasMatchCandidates[0], |
| 120 &kAliasMatchCandidates[arraysize(kAliasMatchCandidates)])); | 120 &kAliasMatchCandidates[arraysize(kAliasMatchCandidates)])); |
| 121 | 121 |
| 122 // Test a few wildcard matches. | 122 // Test a few wildcard matches. |
| 123 INSTANTIATE_TEST_CASE_P( | 123 INSTANTIATE_TEST_CASE_P( |
| 124 TestWildcardMatches, | 124 TestWildcardMatches, |
| 125 LanguageSelectorMatchCandidateTest, | 125 LanguageSelectorMatchCandidateTest, |
| 126 ::testing::ValuesIn( | 126 ::testing::ValuesIn( |
| 127 &kWildcardMatchCandidates[0], | 127 &kWildcardMatchCandidates[0], |
| 128 &kWildcardMatchCandidates[arraysize(kWildcardMatchCandidates)])); | 128 &kWildcardMatchCandidates[arraysize(kWildcardMatchCandidates)])); |
| OLD | NEW |