Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1557)

Side by Side Diff: components/translate/common/translate_util_unittest.cc

Issue 25531002: Move language detection to a component (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Run translate unittests on iOS Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/common/translate/translate_util.h" 5 #include "components/translate/common/translate_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "components/translate/common/translate_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 typedef testing::Test TranslateUtilTest; 12 typedef testing::Test TranslateUtilTest;
13 13
14 // Tests that synonym language code is converted to one used in supporting list. 14 // Tests that synonym language code is converted to one used in supporting list.
15 TEST_F(TranslateUtilTest, ToTranslateLanguageSynonym) { 15 TEST_F(TranslateUtilTest, ToTranslateLanguageSynonym) {
16 std::string language; 16 std::string language;
17 17
18 language = std::string("nb"); 18 language = std::string("nb");
19 TranslateUtil::ToTranslateLanguageSynonym(&language); 19 translate::ToTranslateLanguageSynonym(&language);
20 EXPECT_EQ("no", language); 20 EXPECT_EQ("no", language);
21 21
22 language = std::string("he"); 22 language = std::string("he");
23 TranslateUtil::ToTranslateLanguageSynonym(&language); 23 translate::ToTranslateLanguageSynonym(&language);
24 EXPECT_EQ("iw", language); 24 EXPECT_EQ("iw", language);
25 25
26 language = std::string("jv"); 26 language = std::string("jv");
27 TranslateUtil::ToTranslateLanguageSynonym(&language); 27 translate::ToTranslateLanguageSynonym(&language);
28 EXPECT_EQ("jw", language); 28 EXPECT_EQ("jw", language);
29 29
30 language = std::string("fil"); 30 language = std::string("fil");
31 TranslateUtil::ToTranslateLanguageSynonym(&language); 31 translate::ToTranslateLanguageSynonym(&language);
32 EXPECT_EQ("tl", language); 32 EXPECT_EQ("tl", language);
33 33
34 // Preserve a sub code if the language has a synonym. 34 // Preserve a sub code if the language has a synonym.
35 language = std::string("he-IL"); 35 language = std::string("he-IL");
36 TranslateUtil::ToTranslateLanguageSynonym(&language); 36 translate::ToTranslateLanguageSynonym(&language);
37 EXPECT_EQ("iw-IL", language); 37 EXPECT_EQ("iw-IL", language);
38 38
39 // Don't preserve a sub code if the language has just a similitude. 39 // Don't preserve a sub code if the language has just a similitude.
40 language = std::string("nb-NO"); 40 language = std::string("nb-NO");
41 TranslateUtil::ToTranslateLanguageSynonym(&language); 41 translate::ToTranslateLanguageSynonym(&language);
42 EXPECT_EQ("nb-NO", language); 42 EXPECT_EQ("nb-NO", language);
43 43
44 // Preserve the argument if it doesn't have its synonym. 44 // Preserve the argument if it doesn't have its synonym.
45 language = std::string("en"); 45 language = std::string("en");
46 TranslateUtil::ToTranslateLanguageSynonym(&language); 46 translate::ToTranslateLanguageSynonym(&language);
47 EXPECT_EQ("en", language); 47 EXPECT_EQ("en", language);
48 } 48 }
49 49
50 // Tests that synonym language code is converted to one used in Chrome internal. 50 // Tests that synonym language code is converted to one used in Chrome internal.
51 TEST_F(TranslateUtilTest, ToChromeLanguageSynonym) { 51 TEST_F(TranslateUtilTest, ToChromeLanguageSynonym) {
52 std::string language; 52 std::string language;
53 53
54 language = std::string("no"); 54 language = std::string("no");
55 TranslateUtil::ToChromeLanguageSynonym(&language); 55 translate::ToChromeLanguageSynonym(&language);
56 EXPECT_EQ("nb", language); 56 EXPECT_EQ("nb", language);
57 57
58 language = std::string("iw"); 58 language = std::string("iw");
59 TranslateUtil::ToChromeLanguageSynonym(&language); 59 translate::ToChromeLanguageSynonym(&language);
60 EXPECT_EQ("he", language); 60 EXPECT_EQ("he", language);
61 61
62 language = std::string("jw"); 62 language = std::string("jw");
63 TranslateUtil::ToChromeLanguageSynonym(&language); 63 translate::ToChromeLanguageSynonym(&language);
64 EXPECT_EQ("jv", language); 64 EXPECT_EQ("jv", language);
65 65
66 language = std::string("tl"); 66 language = std::string("tl");
67 TranslateUtil::ToChromeLanguageSynonym(&language); 67 translate::ToChromeLanguageSynonym(&language);
68 EXPECT_EQ("fil", language); 68 EXPECT_EQ("fil", language);
69 69
70 // Preserve a sub code if the language has a synonym. 70 // Preserve a sub code if the language has a synonym.
71 language = std::string("iw-IL"); 71 language = std::string("iw-IL");
72 TranslateUtil::ToChromeLanguageSynonym(&language); 72 translate::ToChromeLanguageSynonym(&language);
73 EXPECT_EQ("he-IL", language); 73 EXPECT_EQ("he-IL", language);
74 74
75 // Don't preserve a sub code if the language has just a similitude. 75 // Don't preserve a sub code if the language has just a similitude.
76 language = std::string("no-NO"); 76 language = std::string("no-NO");
77 TranslateUtil::ToChromeLanguageSynonym(&language); 77 translate::ToChromeLanguageSynonym(&language);
78 EXPECT_EQ("no-NO", language); 78 EXPECT_EQ("no-NO", language);
79 79
80 // Preserve the argument if it doesn't have its synonym. 80 // Preserve the argument if it doesn't have its synonym.
81 language = std::string("en"); 81 language = std::string("en");
82 TranslateUtil::ToChromeLanguageSynonym(&language); 82 translate::ToChromeLanguageSynonym(&language);
83 EXPECT_EQ("en", language); 83 EXPECT_EQ("en", language);
84 } 84 }
85 85
86 TEST_F(TranslateUtilTest, SecurityOrigin) { 86 TEST_F(TranslateUtilTest, SecurityOrigin) {
87 GURL origin = TranslateUtil::GetTranslateSecurityOrigin(); 87 GURL origin = translate::GetTranslateSecurityOrigin();
88 EXPECT_EQ(std::string(TranslateUtil::kSecurityOrigin), origin.spec()); 88 EXPECT_EQ(std::string(translate::kSecurityOrigin), origin.spec());
89 89
90 const std::string running_origin("http://www.tamurayukari.com/"); 90 const std::string running_origin("http://www.tamurayukari.com/");
91 CommandLine* command_line = CommandLine::ForCurrentProcess(); 91 CommandLine* command_line = CommandLine::ForCurrentProcess();
92 command_line->AppendSwitchASCII(switches::kTranslateSecurityOrigin, 92 command_line->AppendSwitchASCII(translate::switches::kTranslateSecurityOrigin,
93 running_origin); 93 running_origin);
94 GURL modified_origin = TranslateUtil::GetTranslateSecurityOrigin(); 94 GURL modified_origin = translate::GetTranslateSecurityOrigin();
95 EXPECT_EQ(running_origin, modified_origin.spec()); 95 EXPECT_EQ(running_origin, modified_origin.spec());
96 } 96 }
OLDNEW
« no previous file with comments | « components/translate/common/translate_util.cc ('k') | components/translate/language_detection/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698