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

Side by Side Diff: chrome/common/translate/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
« no previous file with comments | « chrome/common/translate/translate_util.cc ('k') | chrome/renderer/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/common/translate/translate_util.h"
6
7 #include "base/command_line.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h"
11
12 typedef testing::Test TranslateUtilTest;
13
14 // Tests that synonym language code is converted to one used in supporting list.
15 TEST_F(TranslateUtilTest, ToTranslateLanguageSynonym) {
16 std::string language;
17
18 language = std::string("nb");
19 TranslateUtil::ToTranslateLanguageSynonym(&language);
20 EXPECT_EQ("no", language);
21
22 language = std::string("he");
23 TranslateUtil::ToTranslateLanguageSynonym(&language);
24 EXPECT_EQ("iw", language);
25
26 language = std::string("jv");
27 TranslateUtil::ToTranslateLanguageSynonym(&language);
28 EXPECT_EQ("jw", language);
29
30 language = std::string("fil");
31 TranslateUtil::ToTranslateLanguageSynonym(&language);
32 EXPECT_EQ("tl", language);
33
34 // Preserve a sub code if the language has a synonym.
35 language = std::string("he-IL");
36 TranslateUtil::ToTranslateLanguageSynonym(&language);
37 EXPECT_EQ("iw-IL", language);
38
39 // Don't preserve a sub code if the language has just a similitude.
40 language = std::string("nb-NO");
41 TranslateUtil::ToTranslateLanguageSynonym(&language);
42 EXPECT_EQ("nb-NO", language);
43
44 // Preserve the argument if it doesn't have its synonym.
45 language = std::string("en");
46 TranslateUtil::ToTranslateLanguageSynonym(&language);
47 EXPECT_EQ("en", language);
48 }
49
50 // Tests that synonym language code is converted to one used in Chrome internal.
51 TEST_F(TranslateUtilTest, ToChromeLanguageSynonym) {
52 std::string language;
53
54 language = std::string("no");
55 TranslateUtil::ToChromeLanguageSynonym(&language);
56 EXPECT_EQ("nb", language);
57
58 language = std::string("iw");
59 TranslateUtil::ToChromeLanguageSynonym(&language);
60 EXPECT_EQ("he", language);
61
62 language = std::string("jw");
63 TranslateUtil::ToChromeLanguageSynonym(&language);
64 EXPECT_EQ("jv", language);
65
66 language = std::string("tl");
67 TranslateUtil::ToChromeLanguageSynonym(&language);
68 EXPECT_EQ("fil", language);
69
70 // Preserve a sub code if the language has a synonym.
71 language = std::string("iw-IL");
72 TranslateUtil::ToChromeLanguageSynonym(&language);
73 EXPECT_EQ("he-IL", language);
74
75 // Don't preserve a sub code if the language has just a similitude.
76 language = std::string("no-NO");
77 TranslateUtil::ToChromeLanguageSynonym(&language);
78 EXPECT_EQ("no-NO", language);
79
80 // Preserve the argument if it doesn't have its synonym.
81 language = std::string("en");
82 TranslateUtil::ToChromeLanguageSynonym(&language);
83 EXPECT_EQ("en", language);
84 }
85
86 TEST_F(TranslateUtilTest, SecurityOrigin) {
87 GURL origin = TranslateUtil::GetTranslateSecurityOrigin();
88 EXPECT_EQ(std::string(TranslateUtil::kSecurityOrigin), origin.spec());
89
90 const std::string running_origin("http://www.tamurayukari.com/");
91 CommandLine* command_line = CommandLine::ForCurrentProcess();
92 command_line->AppendSwitchASCII(switches::kTranslateSecurityOrigin,
93 running_origin);
94 GURL modified_origin = TranslateUtil::GetTranslateSecurityOrigin();
95 EXPECT_EQ(running_origin, modified_origin.spec());
96 }
OLDNEW
« no previous file with comments | « chrome/common/translate/translate_util.cc ('k') | chrome/renderer/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698