summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 08:32:40 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-21 08:32:40 +0000
commit875033ac4f5a333451f9eb5573e6d7e92cb19923 (patch)
tree0d3ee786143de3207f3171988b7c8cf663448ba8 /chrome
parent819d805666a21dde460e535afc6a0ae1139fa841 (diff)
downloadchromium_src-875033ac4f5a333451f9eb5573e6d7e92cb19923.zip
chromium_src-875033ac4f5a333451f9eb5573e6d7e92cb19923.tar.gz
chromium_src-875033ac4f5a333451f9eb5573e6d7e92cb19923.tar.bz2
Add tests for AddLanguageComboboxModel.
TEST=out/Release/unit_tests --gtest_filter='LanguageConfigViewTest*' BUG=chromium-os:3432 Review URL: http://codereview.chromium.org/2104015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/options/language_config_view_test.cc88
1 files changed, 86 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/options/language_config_view_test.cc b/chrome/browser/chromeos/options/language_config_view_test.cc
index eaea4271..9cbca14 100644
--- a/chrome/browser/chromeos/options/language_config_view_test.cc
+++ b/chrome/browser/chromeos/options/language_config_view_test.cc
@@ -2,8 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/options/language_config_view.h"
#include <string>
+#include <vector>
+#include "app/l10n_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/options/language_config_view.h"
+#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -11,8 +15,88 @@ namespace chromeos {
TEST(LanguageConfigViewTest, MaybeRewriteLanguageName) {
EXPECT_EQ(L"English",
LanguageConfigView::MaybeRewriteLanguageName(L"English"));
- EXPECT_EQ(L"Others",
+ EXPECT_EQ(l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_OTHERS),
LanguageConfigView::MaybeRewriteLanguageName(L"t"));
}
+TEST(LanguageConfigViewTest, AddLanguageComboboxModel) {
+ std::vector<std::string> language_codes;
+ language_codes.push_back("de");
+ language_codes.push_back("fr");
+ language_codes.push_back("ko");
+ AddLanguageComboboxModel model(NULL, language_codes);
+
+ // GetItemCount() should return 4 ("Add language" + 3 language codes).
+ ASSERT_EQ(4, model.GetItemCount());
+
+ // The first item should be "Add language" labe.
+ EXPECT_EQ(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_LANGUAGES_ADD_LANGUAGE_COMBOBOX),
+ model.GetItemAt(0));
+ // Other items should be sorted language display names for UI (hence
+ // French comes before German). Note that the returned display names
+ // are followed by their native representations. To simplify matching,
+ // use StartsWith() here.
+ EXPECT_TRUE(StartsWith(model.GetItemAt(1), L"French", true))
+ << model.GetItemAt(1);
+ EXPECT_TRUE(StartsWith(model.GetItemAt(2), L"German", true))
+ << model.GetItemAt(2);
+ EXPECT_TRUE(StartsWith(model.GetItemAt(3), L"Korean", true))
+ << model.GetItemAt(3);
+
+ // GetLanguageIndex() returns the given index -1 to offset "Add language".
+ EXPECT_EQ(0, model.GetLanguageIndex(1));
+ EXPECT_EQ(1, model.GetLanguageIndex(2));
+ EXPECT_EQ(2, model.GetLanguageIndex(3));
+
+ // The returned index can be used for GetLocaleFromIndex().
+ EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+ EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2)));
+ EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3)));
+
+ // GetIndexFromLocale() returns the language index.
+ EXPECT_EQ(0, model.GetIndexFromLocale("fr"));
+ EXPECT_EQ(1, model.GetIndexFromLocale("de"));
+ EXPECT_EQ(2, model.GetIndexFromLocale("ko"));
+ EXPECT_EQ(-1, model.GetIndexFromLocale("ja")); // Not in the model.
+
+ // Mark "de" to be ignored, and check if it's gone.
+ model.SetIgnored("de", true);
+ ASSERT_EQ(3, model.GetItemCount());
+ EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+ EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(2)));
+
+ // Mark "ko" to be ignored, and check if it's gone.
+ model.SetIgnored("ko", true);
+ ASSERT_EQ(2, model.GetItemCount());
+ EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+
+ // Mark "fr" to be ignored, and check if it's gone.
+ model.SetIgnored("fr", true);
+ ASSERT_EQ(1, model.GetItemCount());
+
+ // Mark "de" not to be ignored, and see if it's back.
+ model.SetIgnored("de", false);
+ ASSERT_EQ(2, model.GetItemCount());
+ EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+
+ // Mark "fr" not to be ignored, and see if it's back.
+ model.SetIgnored("fr", false);
+ ASSERT_EQ(3, model.GetItemCount());
+ EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+ EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2)));
+
+ // Mark "ko" not to be ignored, and see if it's back.
+ model.SetIgnored("ko", false);
+ ASSERT_EQ(4, model.GetItemCount());
+ EXPECT_EQ("fr", model.GetLocaleFromIndex(model.GetLanguageIndex(1)));
+ EXPECT_EQ("de", model.GetLocaleFromIndex(model.GetLanguageIndex(2)));
+ EXPECT_EQ("ko", model.GetLocaleFromIndex(model.GetLanguageIndex(3)));
+
+ // Mark "ja" (not in the model) to be ignored.
+ model.SetIgnored("ja", true);
+ // The GetItemCount() should not be changed.
+ ASSERT_EQ(4, model.GetItemCount());
+}
+
} // namespace chromeos