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
3 // found in the LICENSE file.
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
10 #include "chrome/browser/spellchecker/spellcheck_factory.h"
11 #include "chrome/browser/spellchecker/spellcheck_service.h"
12 #include "chrome/common/spellcheck_common.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using chrome::spellcheck_common::WordList
;
20 static KeyedService
* BuildSpellcheckService(content::BrowserContext
* profile
) {
21 return new SpellcheckService(static_cast<Profile
*>(profile
));
24 class SpellcheckServiceTest
: public testing::Test
{
26 void SetUp() override
{
27 // Use SetTestingFactoryAndUse to force creation and initialization.
28 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
29 &profile_
, &BuildSpellcheckService
);
33 content::TestBrowserThreadBundle thread_bundle_
;
34 TestingProfile profile_
;
37 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages1
) {
38 std::vector
<std::string
> accept_languages
;
39 accept_languages
.push_back("en");
40 accept_languages
.push_back("en-US");
41 std::vector
<std::string
> languages
;
43 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
44 accept_languages
, "en-US", &languages
);
46 EXPECT_EQ(1U, languages
.size());
47 EXPECT_EQ("en-US", languages
[0]);
50 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages2
) {
51 std::vector
<std::string
> accept_languages
;
52 accept_languages
.push_back("en-US");
53 accept_languages
.push_back("en");
54 std::vector
<std::string
> languages
;
56 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
57 accept_languages
, "en-US", &languages
);
59 EXPECT_EQ(1U, languages
.size());
60 EXPECT_EQ("en-US", languages
[0]);
63 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages3
) {
64 std::vector
<std::string
> accept_languages
;
65 accept_languages
.push_back("en");
66 accept_languages
.push_back("en-US");
67 accept_languages
.push_back("en-AU");
68 std::vector
<std::string
> languages
;
70 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
71 accept_languages
, "en-US", &languages
);
73 EXPECT_EQ(2U, languages
.size());
75 std::sort(languages
.begin(), languages
.end());
76 EXPECT_EQ("en-AU", languages
[0]);
77 EXPECT_EQ("en-US", languages
[1]);
80 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages4
) {
81 std::vector
<std::string
> accept_languages
;
82 accept_languages
.push_back("en");
83 accept_languages
.push_back("en-US");
84 accept_languages
.push_back("fr");
85 std::vector
<std::string
> languages
;
87 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
88 accept_languages
, "en-US", &languages
);
90 EXPECT_EQ(2U, languages
.size());
92 std::sort(languages
.begin(), languages
.end());
93 EXPECT_EQ("en-US", languages
[0]);
94 EXPECT_EQ("fr", languages
[1]);
97 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages5
) {
98 std::vector
<std::string
> accept_languages
;
99 accept_languages
.push_back("en");
100 accept_languages
.push_back("en-JP"); // Will not exist.
101 accept_languages
.push_back("fr");
102 accept_languages
.push_back("aa"); // Will not exist.
103 std::vector
<std::string
> languages
;
105 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
106 accept_languages
, "fr", &languages
);
108 EXPECT_EQ(1U, languages
.size());
109 EXPECT_EQ("fr", languages
[0]);