Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / translate / translate_prefs_unittest.cc
blob98ba9e4956edf16c8831f80d62b687133f1af7f2
1 // Copyright 2013 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 "chrome/browser/translate/translate_prefs.h"
7 #include <algorithm>
8 #include <string>
9 #include <vector>
11 #include "chrome/test/base/scoped_browser_locale.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(TranslatePrefsTest, CreateBlockedLanguages) {
15 std::vector<std::string> blacklisted_languages;
16 blacklisted_languages.push_back("en");
17 blacklisted_languages.push_back("fr");
18 // Hebrew: synonym to 'he'
19 blacklisted_languages.push_back("iw");
20 // Haitian is not used as Accept-Language
21 blacklisted_languages.push_back("ht");
23 std::vector<std::string> accept_languages;
24 accept_languages.push_back("en");
25 // The subcode (IT) will be ignored when merging, except for Chinese.
26 accept_languages.push_back("it-IT");
27 accept_languages.push_back("ja");
28 // Filippino: synonym to 'tl'
29 accept_languages.push_back("fil");
30 // General Chinese is not used as Translate language, but not filtered
31 // when merging.
32 accept_languages.push_back("zh");
33 // Chinese with a sub code is acceptable for the blocked-language list.
34 accept_languages.push_back("zh-TW");
36 std::vector<std::string> blocked_languages;
38 TranslatePrefs::CreateBlockedLanguages(&blocked_languages,
39 blacklisted_languages,
40 accept_languages);
42 // The order of the elements cannot be determined.
43 std::vector<std::string> expected;
44 expected.push_back("en");
45 expected.push_back("fr");
46 expected.push_back("iw");
47 expected.push_back("ht");
48 expected.push_back("it");
49 expected.push_back("ja");
50 expected.push_back("tl");
51 expected.push_back("zh");
52 expected.push_back("zh-TW");
54 EXPECT_EQ(expected.size(), blocked_languages.size());
55 for (std::vector<std::string>::const_iterator it = expected.begin();
56 it != expected.end(); ++it) {
57 EXPECT_NE(blocked_languages.end(),
58 std::find(blocked_languages.begin(),
59 blocked_languages.end(),
60 *it));
64 TEST(TranslatePrefsTest, CreateBlockedLanguagesNonEnglishUI) {
65 std::vector<std::string> blacklisted_languages;
66 blacklisted_languages.push_back("fr");
68 std::vector<std::string> accept_languages;
69 accept_languages.push_back("en");
70 accept_languages.push_back("ja");
71 accept_languages.push_back("zh");
73 // Run in an English locale.
75 ScopedBrowserLocale scoped_browser_locale("en");
76 std::vector<std::string> blocked_languages;
77 TranslatePrefs::CreateBlockedLanguages(&blocked_languages,
78 blacklisted_languages,
79 accept_languages);
80 std::vector<std::string> expected;
81 expected.push_back("en");
82 expected.push_back("fr");
83 expected.push_back("ja");
84 expected.push_back("zh");
86 EXPECT_EQ(expected.size(), blocked_languages.size());
87 for (std::vector<std::string>::const_iterator it = expected.begin();
88 it != expected.end(); ++it) {
89 EXPECT_NE(blocked_languages.end(),
90 std::find(blocked_languages.begin(),
91 blocked_languages.end(),
92 *it));
96 // Run in a Japanese locale.
97 // English should not be included in the result even though Accept Languages
98 // has English because the UI is not English.
100 ScopedBrowserLocale scoped_browser_locale("ja");
101 std::vector<std::string> blocked_languages;
102 TranslatePrefs::CreateBlockedLanguages(&blocked_languages,
103 blacklisted_languages,
104 accept_languages);
105 std::vector<std::string> expected;
106 expected.push_back("fr");
107 expected.push_back("ja");
108 expected.push_back("zh");
110 EXPECT_EQ(expected.size(), blocked_languages.size());
111 for (std::vector<std::string>::const_iterator it = expected.begin();
112 it != expected.end(); ++it) {
113 EXPECT_NE(blocked_languages.end(),
114 std::find(blocked_languages.begin(),
115 blocked_languages.end(),
116 *it));