1 // Copyright 2014 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.
5 #include "components/translate/core/browser/translate_prefs.h"
11 #include "components/translate/core/browser/translate_download_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 TEST(TranslatePrefsTest
, CreateBlockedLanguages
) {
17 TranslateDownloadManager::GetInstance()->set_application_locale("en");
18 std::vector
<std::string
> blacklisted_languages
;
19 blacklisted_languages
.push_back("en");
20 blacklisted_languages
.push_back("fr");
21 // Hebrew: synonym to 'he'
22 blacklisted_languages
.push_back("iw");
23 // Haitian is not used as Accept-Language
24 blacklisted_languages
.push_back("ht");
26 std::vector
<std::string
> accept_languages
;
27 accept_languages
.push_back("en");
28 // The subcode (IT) will be ignored when merging, except for Chinese.
29 accept_languages
.push_back("it-IT");
30 accept_languages
.push_back("ja");
31 // Filippino: synonym to 'tl'
32 accept_languages
.push_back("fil");
33 // General Chinese is not used as Translate language, but not filtered
35 accept_languages
.push_back("zh");
36 // Chinese with a sub code is acceptable for the blocked-language list.
37 accept_languages
.push_back("zh-TW");
39 std::vector
<std::string
> blocked_languages
;
41 TranslatePrefs::CreateBlockedLanguages(&blocked_languages
,
42 blacklisted_languages
,
45 // The order of the elements cannot be determined.
46 std::vector
<std::string
> expected
;
47 expected
.push_back("en");
48 expected
.push_back("fr");
49 expected
.push_back("iw");
50 expected
.push_back("ht");
51 expected
.push_back("it");
52 expected
.push_back("ja");
53 expected
.push_back("tl");
54 expected
.push_back("zh");
55 expected
.push_back("zh-TW");
57 EXPECT_EQ(expected
.size(), blocked_languages
.size());
58 for (std::vector
<std::string
>::const_iterator it
= expected
.begin();
59 it
!= expected
.end(); ++it
) {
60 EXPECT_NE(blocked_languages
.end(),
61 std::find(blocked_languages
.begin(),
62 blocked_languages
.end(),
67 TEST(TranslatePrefsTest
, CreateBlockedLanguagesNonEnglishUI
) {
68 std::vector
<std::string
> blacklisted_languages
;
69 blacklisted_languages
.push_back("fr");
71 std::vector
<std::string
> accept_languages
;
72 accept_languages
.push_back("en");
73 accept_languages
.push_back("ja");
74 accept_languages
.push_back("zh");
76 // Run in an English locale.
78 TranslateDownloadManager::GetInstance()->set_application_locale("en");
79 std::vector
<std::string
> blocked_languages
;
80 TranslatePrefs::CreateBlockedLanguages(&blocked_languages
,
81 blacklisted_languages
,
83 std::vector
<std::string
> expected
;
84 expected
.push_back("en");
85 expected
.push_back("fr");
86 expected
.push_back("ja");
87 expected
.push_back("zh");
89 EXPECT_EQ(expected
.size(), blocked_languages
.size());
90 for (std::vector
<std::string
>::const_iterator it
= expected
.begin();
91 it
!= expected
.end(); ++it
) {
92 EXPECT_NE(blocked_languages
.end(),
93 std::find(blocked_languages
.begin(),
94 blocked_languages
.end(),
99 // Run in a Japanese locale.
100 // English should not be included in the result even though Accept Languages
101 // has English because the UI is not English.
103 TranslateDownloadManager::GetInstance()->set_application_locale("ja");
104 std::vector
<std::string
> blocked_languages
;
105 TranslatePrefs::CreateBlockedLanguages(&blocked_languages
,
106 blacklisted_languages
,
108 std::vector
<std::string
> expected
;
109 expected
.push_back("fr");
110 expected
.push_back("ja");
111 expected
.push_back("zh");
113 EXPECT_EQ(expected
.size(), blocked_languages
.size());
114 for (std::vector
<std::string
>::const_iterator it
= expected
.begin();
115 it
!= expected
.end(); ++it
) {
116 EXPECT_NE(blocked_languages
.end(),
117 std::find(blocked_languages
.begin(),
118 blocked_languages
.end(),
124 } // namespace translate