Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / translate / core / common / translate_util_unittest.cc
blobf6ef86934c760cd77d0948b46536f16cd0ddd5dc
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"
10 #include "url/gurl.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) {
16 std::string language;
18 language = std::string("nb");
19 translate::ToTranslateLanguageSynonym(&language);
20 EXPECT_EQ("no", language);
22 language = std::string("zh-HK");
23 translate::ToTranslateLanguageSynonym(&language);
24 EXPECT_EQ("zh-TW", language);
26 // A sub code is not preserved (except for Chinese).
27 language = std::string("he-IL");
28 translate::ToTranslateLanguageSynonym(&language);
29 EXPECT_EQ("iw", language);
31 language = std::string("zh-JP");
32 translate::ToTranslateLanguageSynonym(&language);
33 EXPECT_EQ("zh-JP", language);
35 // Preserve the argument if it doesn't have its synonym.
36 language = std::string("en");
37 translate::ToTranslateLanguageSynonym(&language);
38 EXPECT_EQ("en", language);
41 // Tests that synonym language code is converted to one used in Chrome internal.
42 TEST_F(TranslateUtilTest, ToChromeLanguageSynonym) {
43 std::string language;
45 language = std::string("no");
46 translate::ToChromeLanguageSynonym(&language);
47 EXPECT_EQ("nb", language);
49 // Preserve a sub code
50 language = std::string("iw-IL");
51 translate::ToChromeLanguageSynonym(&language);
52 EXPECT_EQ("he-IL", language);
54 // Preserve the argument if it doesn't have its synonym.
55 language = std::string("en");
56 translate::ToChromeLanguageSynonym(&language);
57 EXPECT_EQ("en", language);
60 TEST_F(TranslateUtilTest, SecurityOrigin) {
61 GURL origin = translate::GetTranslateSecurityOrigin();
62 EXPECT_EQ(std::string(translate::kSecurityOrigin), origin.spec());
64 const std::string running_origin("http://www.tamurayukari.com/");
65 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
66 command_line->AppendSwitchASCII(translate::switches::kTranslateSecurityOrigin,
67 running_origin);
68 GURL modified_origin = translate::GetTranslateSecurityOrigin();
69 EXPECT_EQ(running_origin, modified_origin.spec());