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/common/translate_util.h"
7 #include "base/command_line.h"
8 #include "components/translate/core/common/translate_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h"
12 typedef testing::Test TranslateUtilTest
;
14 // Tests that synonym language code is converted to one used in supporting list.
15 TEST_F(TranslateUtilTest
, ToTranslateLanguageSynonym
) {
18 language
= std::string("nb");
19 translate::ToTranslateLanguageSynonym(&language
);
20 EXPECT_EQ("no", language
);
22 language
= std::string("he");
23 translate::ToTranslateLanguageSynonym(&language
);
24 EXPECT_EQ("iw", language
);
26 language
= std::string("jv");
27 translate::ToTranslateLanguageSynonym(&language
);
28 EXPECT_EQ("jw", language
);
30 language
= std::string("fil");
31 translate::ToTranslateLanguageSynonym(&language
);
32 EXPECT_EQ("tl", language
);
34 // Preserve a sub code if the language has a synonym.
35 language
= std::string("he-IL");
36 translate::ToTranslateLanguageSynonym(&language
);
37 EXPECT_EQ("iw-IL", language
);
39 // Don't preserve a sub code if the language has just a similitude.
40 language
= std::string("nb-NO");
41 translate::ToTranslateLanguageSynonym(&language
);
42 EXPECT_EQ("nb-NO", language
);
44 // Preserve the argument if it doesn't have its synonym.
45 language
= std::string("en");
46 translate::ToTranslateLanguageSynonym(&language
);
47 EXPECT_EQ("en", language
);
50 // Tests that synonym language code is converted to one used in Chrome internal.
51 TEST_F(TranslateUtilTest
, ToChromeLanguageSynonym
) {
54 language
= std::string("no");
55 translate::ToChromeLanguageSynonym(&language
);
56 EXPECT_EQ("nb", language
);
58 language
= std::string("iw");
59 translate::ToChromeLanguageSynonym(&language
);
60 EXPECT_EQ("he", language
);
62 language
= std::string("jw");
63 translate::ToChromeLanguageSynonym(&language
);
64 EXPECT_EQ("jv", language
);
66 language
= std::string("tl");
67 translate::ToChromeLanguageSynonym(&language
);
68 EXPECT_EQ("fil", language
);
70 // Preserve a sub code if the language has a synonym.
71 language
= std::string("iw-IL");
72 translate::ToChromeLanguageSynonym(&language
);
73 EXPECT_EQ("he-IL", language
);
75 // Don't preserve a sub code if the language has just a similitude.
76 language
= std::string("no-NO");
77 translate::ToChromeLanguageSynonym(&language
);
78 EXPECT_EQ("no-NO", language
);
80 // Preserve the argument if it doesn't have its synonym.
81 language
= std::string("en");
82 translate::ToChromeLanguageSynonym(&language
);
83 EXPECT_EQ("en", language
);
86 TEST_F(TranslateUtilTest
, SecurityOrigin
) {
87 GURL origin
= translate::GetTranslateSecurityOrigin();
88 EXPECT_EQ(std::string(translate::kSecurityOrigin
), origin
.spec());
90 const std::string
running_origin("http://www.tamurayukari.com/");
91 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
92 command_line
->AppendSwitchASCII(translate::switches::kTranslateSecurityOrigin
,
94 GURL modified_origin
= translate::GetTranslateSecurityOrigin();
95 EXPECT_EQ(running_origin
, modified_origin
.spec());