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.
5 #include "chrome/browser/spellchecker/spellcheck_service.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/spellchecker/feedback_sender.h"
11 #include "chrome/browser/spellchecker/spellcheck_factory.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 static scoped_ptr
<KeyedService
> BuildSpellcheckService(
17 content::BrowserContext
* profile
) {
18 return make_scoped_ptr(new SpellcheckService(static_cast<Profile
*>(profile
)));
21 class SpellcheckServiceTest
: public testing::Test
{
23 void SetUp() override
{
24 // Use SetTestingFactoryAndUse to force creation and initialization.
25 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
26 &profile_
, &BuildSpellcheckService
);
30 content::TestBrowserThreadBundle thread_bundle_
;
31 TestingProfile profile_
;
34 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages1
) {
35 std::vector
<std::string
> accept_languages
;
36 accept_languages
.push_back("en");
37 accept_languages
.push_back("en-US");
38 std::vector
<std::string
> languages
;
40 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
41 accept_languages
, "en-US", &languages
);
43 EXPECT_EQ(1U, languages
.size());
44 EXPECT_EQ("en-US", languages
[0]);
47 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages2
) {
48 std::vector
<std::string
> accept_languages
;
49 accept_languages
.push_back("en-US");
50 accept_languages
.push_back("en");
51 std::vector
<std::string
> languages
;
53 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
54 accept_languages
, "en-US", &languages
);
56 EXPECT_EQ(1U, languages
.size());
57 EXPECT_EQ("en-US", languages
[0]);
60 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages3
) {
61 std::vector
<std::string
> accept_languages
;
62 accept_languages
.push_back("en");
63 accept_languages
.push_back("en-US");
64 accept_languages
.push_back("en-AU");
65 std::vector
<std::string
> languages
;
67 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
68 accept_languages
, "en-US", &languages
);
70 EXPECT_EQ(2U, languages
.size());
72 std::sort(languages
.begin(), languages
.end());
73 EXPECT_EQ("en-AU", languages
[0]);
74 EXPECT_EQ("en-US", languages
[1]);
77 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages4
) {
78 std::vector
<std::string
> accept_languages
;
79 accept_languages
.push_back("en");
80 accept_languages
.push_back("en-US");
81 accept_languages
.push_back("fr");
82 std::vector
<std::string
> languages
;
84 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
85 accept_languages
, "en-US", &languages
);
87 EXPECT_EQ(2U, languages
.size());
89 std::sort(languages
.begin(), languages
.end());
90 EXPECT_EQ("en-US", languages
[0]);
91 EXPECT_EQ("fr", languages
[1]);
94 TEST_F(SpellcheckServiceTest
, GetSpellCheckLanguages5
) {
95 std::vector
<std::string
> accept_languages
;
96 accept_languages
.push_back("en");
97 accept_languages
.push_back("en-JP"); // Will not exist.
98 accept_languages
.push_back("fr");
99 accept_languages
.push_back("aa"); // Will not exist.
100 std::vector
<std::string
> languages
;
102 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
103 accept_languages
, "fr", &languages
);
105 EXPECT_EQ(1U, languages
.size());
106 EXPECT_EQ("fr", languages
[0]);