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" | |
12 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
14 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
15 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
17 #include "components/prefs/pref_registry_simple.h" | 16 #include "components/prefs/pref_registry_simple.h" |
18 #include "components/prefs/testing_pref_service.h" | 17 #include "components/prefs/testing_pref_service.h" |
19 #include "components/spellcheck/browser/pref_names.h" | 18 #include "components/spellcheck/browser/pref_names.h" |
20 #include "components/user_prefs/user_prefs.h" | 19 #include "components/user_prefs/user_prefs.h" |
21 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
23 | 22 |
24 struct TestCase { | 23 struct TestCase { |
25 TestCase(const std::string& accept_languages, | 24 TestCase(const std::string& accept_languages, |
26 const std::string& unsplit_spellcheck_dictionaries, | 25 const std::string& unsplit_spellcheck_dictionaries, |
27 const std::string& unsplit_expected_languages, | 26 const std::string& unsplit_expected_languages, |
28 const std::string& unsplit_expected_languages_used_for_spellcheck) | 27 const std::string& unsplit_expected_languages_used_for_spellcheck) |
29 : accept_languages(accept_languages), | 28 : accept_languages(accept_languages), |
30 spellcheck_dictionaries( | 29 spellcheck_dictionaries( |
31 base::SplitString(unsplit_spellcheck_dictionaries, | 30 base::SplitString(unsplit_spellcheck_dictionaries, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 << "], expected=["; | 76 << "], expected=["; |
78 for (const auto& dictionary : test_case.expected_dictionaries) { | 77 for (const auto& dictionary : test_case.expected_dictionaries) { |
79 out << dictionary << ","; | 78 out << dictionary << ","; |
80 } | 79 } |
81 out << "]"; | 80 out << "]"; |
82 return out; | 81 return out; |
83 } | 82 } |
84 | 83 |
85 class SpellcheckServiceUnitTest : public testing::TestWithParam<TestCase> { | 84 class SpellcheckServiceUnitTest : public testing::TestWithParam<TestCase> { |
86 public: | 85 public: |
87 SpellcheckServiceUnitTest() | 86 SpellcheckServiceUnitTest() { |
88 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | |
89 user_prefs::UserPrefs::Set(&context_, &prefs_); | 87 user_prefs::UserPrefs::Set(&context_, &prefs_); |
90 } | 88 } |
91 ~SpellcheckServiceUnitTest() override {} | 89 ~SpellcheckServiceUnitTest() override {} |
92 | 90 |
93 void SetUp() override { | 91 void SetUp() override { |
94 prefs()->registry()->RegisterListPref( | 92 prefs()->registry()->RegisterListPref( |
95 spellcheck::prefs::kSpellCheckDictionaries); | 93 spellcheck::prefs::kSpellCheckDictionaries); |
96 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages, | 94 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages, |
97 std::string()); | 95 std::string()); |
98 } | 96 } |
99 | 97 |
100 base::SupportsUserData* context() { return &context_; } | 98 base::SupportsUserData* context() { return &context_; } |
101 TestingPrefServiceSimple* prefs() { return &prefs_; } | 99 TestingPrefServiceSimple* prefs() { return &prefs_; } |
102 | 100 |
103 private: | 101 private: |
104 struct : public base::SupportsUserData { | 102 struct : public base::SupportsUserData { |
105 } context_; | 103 } context_; |
106 TestingPrefServiceSimple prefs_; | 104 TestingPrefServiceSimple prefs_; |
107 base::MessageLoop message_loop_; | 105 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
108 content::TestBrowserThread ui_thread_; | |
109 | 106 |
110 DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceUnitTest); | 107 DISALLOW_COPY_AND_ASSIGN(SpellcheckServiceUnitTest); |
111 }; | 108 }; |
112 | 109 |
113 INSTANTIATE_TEST_CASE_P( | 110 INSTANTIATE_TEST_CASE_P( |
114 TestCases, | 111 TestCases, |
115 SpellcheckServiceUnitTest, | 112 SpellcheckServiceUnitTest, |
116 testing::Values( | 113 testing::Values( |
117 TestCase("en,aa", "aa", "", ""), | 114 TestCase("en,aa", "aa", "", ""), |
118 TestCase("en,en-JP,fr,aa", "fr", "fr", "fr"), | 115 TestCase("en,en-JP,fr,aa", "fr", "fr", "fr"), |
(...skipping 12 matching lines...) Expand all Loading... |
131 base::ListValue spellcheck_dictionaries; | 128 base::ListValue spellcheck_dictionaries; |
132 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries); | 129 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries); |
133 prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, | 130 prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries, |
134 spellcheck_dictionaries); | 131 spellcheck_dictionaries); |
135 | 132 |
136 std::vector<SpellcheckService::Dictionary> dictionaries; | 133 std::vector<SpellcheckService::Dictionary> dictionaries; |
137 SpellcheckService::GetDictionaries(context(), &dictionaries); | 134 SpellcheckService::GetDictionaries(context(), &dictionaries); |
138 | 135 |
139 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries); | 136 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries); |
140 } | 137 } |
OLD | NEW |