Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service_unittest.cc

Issue 2244083002: Componentize spellcheck [4]: spellcheck/browser and android java-side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/prefs/pref_registry_simple.h" 17 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/testing_pref_service.h" 18 #include "components/prefs/testing_pref_service.h"
19 #include "components/spellcheck/browser/pref_names.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,
27 const std::string& unsplit_expected_languages_used_for_spellcheck) 28 const std::string& unsplit_expected_languages_used_for_spellcheck)
28 : accept_languages(accept_languages), 29 : accept_languages(accept_languages),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
95 spellcheck::prefs::kSpellCheckDictionaries);
94 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages, 96 prefs()->registry()->RegisterStringPref(prefs::kAcceptLanguages,
95 std::string()); 97 std::string());
96 } 98 }
97 99
98 base::SupportsUserData* context() { return &context_; } 100 base::SupportsUserData* context() { return &context_; }
99 TestingPrefServiceSimple* prefs() { return &prefs_; } 101 TestingPrefServiceSimple* prefs() { return &prefs_; }
100 102
101 private: 103 private:
102 struct : public base::SupportsUserData { 104 struct : public base::SupportsUserData {
103 } context_; 105 } context_;
(...skipping 17 matching lines...) Expand all
121 TestCase("en,en-US", "en-US", "en-US", "en-US"), 123 TestCase("en,en-US", "en-US", "en-US", "en-US"),
122 TestCase("en,en-US,fr", "en-US", "en-US,fr", "en-US"), 124 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"), 125 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"), 126 TestCase("en-US,en", "en-US", "en-US", "en-US"),
125 TestCase("hu-HU,hr-HR", "hr", "hu,hr", "hr"))); 127 TestCase("hu-HU,hr-HR", "hr", "hu,hr", "hr")));
126 128
127 TEST_P(SpellcheckServiceUnitTest, GetDictionaries) { 129 TEST_P(SpellcheckServiceUnitTest, GetDictionaries) {
128 prefs()->SetString(prefs::kAcceptLanguages, GetParam().accept_languages); 130 prefs()->SetString(prefs::kAcceptLanguages, GetParam().accept_languages);
129 base::ListValue spellcheck_dictionaries; 131 base::ListValue spellcheck_dictionaries;
130 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries); 132 spellcheck_dictionaries.AppendStrings(GetParam().spellcheck_dictionaries);
131 prefs()->Set(prefs::kSpellCheckDictionaries, spellcheck_dictionaries); 133 prefs()->Set(spellcheck::prefs::kSpellCheckDictionaries,
134 spellcheck_dictionaries);
132 135
133 std::vector<SpellcheckService::Dictionary> dictionaries; 136 std::vector<SpellcheckService::Dictionary> dictionaries;
134 SpellcheckService::GetDictionaries(context(), &dictionaries); 137 SpellcheckService::GetDictionaries(context(), &dictionaries);
135 138
136 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries); 139 EXPECT_EQ(GetParam().expected_dictionaries, dictionaries);
137 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698