OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/spellchecker/spellcheck_service.h" | 5 #include "chrome/browser/spellchecker/spellcheck_service.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "chrome/common/chrome_switches.h" | 15 //#include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/spellcheck/browser/pref_names.h" |
17 #include "components/prefs/pref_registry_simple.h" | 18 #include "components/prefs/pref_registry_simple.h" |
18 #include "components/prefs/testing_pref_service.h" | 19 #include "components/prefs/testing_pref_service.h" |
19 #include "components/user_prefs/user_prefs.h" | 20 #include "components/user_prefs/user_prefs.h" |
20 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 struct TestCase { | 24 struct TestCase { |
24 TestCase(const std::string& accept_languages, | 25 TestCase(const std::string& accept_languages, |
25 const std::string& unsplit_spellcheck_dictionaries, | 26 const std::string& unsplit_spellcheck_dictionaries, |
26 const std::string& unsplit_expected_languages, | 27 const std::string& unsplit_expected_languages, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 84 |
84 class SpellcheckServiceUnitTest : public testing::TestWithParam<TestCase> { | 85 class SpellcheckServiceUnitTest : public testing::TestWithParam<TestCase> { |
85 public: | 86 public: |
86 SpellcheckServiceUnitTest() | 87 SpellcheckServiceUnitTest() |
87 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 88 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
88 user_prefs::UserPrefs::Set(&context_, &prefs_); | 89 user_prefs::UserPrefs::Set(&context_, &prefs_); |
89 } | 90 } |
90 ~SpellcheckServiceUnitTest() override {} | 91 ~SpellcheckServiceUnitTest() override {} |
91 | 92 |
92 void SetUp() override { | 93 void SetUp() override { |
93 prefs()->registry()->RegisterListPref(prefs::kSpellCheckDictionaries); | 94 prefs()->registry()->RegisterListPref(spellcheck::prefs::kSpellCheckDictiona
ries); |
94 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages, | 95 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages, |
95 std::string()); | 96 std::string()); |
96 } | 97 } |
97 | 98 |
98 base::SupportsUserData* context() { return &context_; } | 99 base::SupportsUserData* context() { return &context_; } |
99 TestingPrefServiceSimple* prefs() { return &prefs_; } | 100 TestingPrefServiceSimple* prefs() { return &prefs_; } |
100 | 101 |
101 private: | 102 private: |
102 struct : public base::SupportsUserData { | 103 struct : public base::SupportsUserData { |
103 } context_; | 104 } context_; |
(...skipping 17 matching lines...) Expand all Loading... |
121 TestCase("en,en-US", "en-US", "en-US", "en-US"), | 122 TestCase("en,en-US", "en-US", "en-US", "en-US"), |
122 TestCase("en,en-US,fr", "en-US", "en-US,fr", "en-US"), | 123 TestCase("en,en-US,fr", "en-US", "en-US,fr", "en-US"), |
123 TestCase("en,fr,en-US,en-AU", "en-US,fr", "fr,en-US,en-AU", "fr,en-US"), | 124 TestCase("en,fr,en-US,en-AU", "en-US,fr", "fr,en-US,en-AU", "fr,en-US"), |
124 TestCase("en-US,en", "en-US", "en-US", "en-US"), | 125 TestCase("en-US,en", "en-US", "en-US", "en-US"), |
125 TestCase("hu-HU,hr-HR", "hr", "hu,hr", "hr"))); | 126 TestCase("hu-HU,hr-HR", "hr", "hu,hr", "hr"))); |
126 | 127 |
127 TEST_P(SpellcheckServiceUnitTest, GetDictionaries) { | 128 TEST_P(SpellcheckServiceUnitTest, GetDictionaries) { |
128 prefs()->SetString(prefs::kAcceptLanguages, GetParam().accept_languages); | 129 prefs()->SetString(prefs::kAcceptLanguages, GetParam().accept_languages); |
129 base::ListValue spellcheck_dictionaries; | 130 base::ListValue spellcheck_dictionaries; |
130 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries); | 131 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries); |
131 prefs()->Set(prefs::kSpellCheckDictionaries, spellcheck_dictionaries); | 132 prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, spellcheck_dictionari
es); |
132 | 133 |
133 std::vector<SpellcheckService::Dictionary> dictionaries; | 134 std::vector<SpellcheckService::Dictionary> dictionaries; |
134 SpellcheckService::GetDictionaries(context(), &dictionaries); | 135 SpellcheckService::GetDictionaries(context(), &dictionaries); |
135 | 136 |
136 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries); | 137 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries); |
137 } | 138 } |
OLD | NEW |