• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include <vector>
6 
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"
17 
18 using chrome::spellcheck_common::WordList;
19 
BuildSpellcheckService(content::BrowserContext * profile)20 static KeyedService* BuildSpellcheckService(content::BrowserContext* profile) {
21   return new SpellcheckService(static_cast<Profile*>(profile));
22 }
23 
24 class SpellcheckServiceTest : public testing::Test {
25  protected:
SetUp()26   virtual void SetUp() OVERRIDE {
27     // Use SetTestingFactoryAndUse to force creation and initialization.
28     SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
29         &profile_, &BuildSpellcheckService);
30   }
31 
32  private:
33   content::TestBrowserThreadBundle thread_bundle_;
34   TestingProfile profile_;
35 };
36 
TEST_F(SpellcheckServiceTest,GetSpellCheckLanguages1)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;
42 
43   SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
44       accept_languages, "en-US", &languages);
45 
46   EXPECT_EQ(1U, languages.size());
47   EXPECT_EQ("en-US", languages[0]);
48 }
49 
TEST_F(SpellcheckServiceTest,GetSpellCheckLanguages2)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;
55 
56   SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
57       accept_languages, "en-US", &languages);
58 
59   EXPECT_EQ(1U, languages.size());
60   EXPECT_EQ("en-US", languages[0]);
61 }
62 
TEST_F(SpellcheckServiceTest,GetSpellCheckLanguages3)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;
69 
70   SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
71       accept_languages, "en-US", &languages);
72 
73   EXPECT_EQ(2U, languages.size());
74 
75   std::sort(languages.begin(), languages.end());
76   EXPECT_EQ("en-AU", languages[0]);
77   EXPECT_EQ("en-US", languages[1]);
78 }
79 
TEST_F(SpellcheckServiceTest,GetSpellCheckLanguages4)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;
86 
87   SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
88       accept_languages, "en-US", &languages);
89 
90   EXPECT_EQ(2U, languages.size());
91 
92   std::sort(languages.begin(), languages.end());
93   EXPECT_EQ("en-US", languages[0]);
94   EXPECT_EQ("fr", languages[1]);
95 }
96 
TEST_F(SpellcheckServiceTest,GetSpellCheckLanguages5)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;
104 
105   SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
106       accept_languages, "fr", &languages);
107 
108   EXPECT_EQ(1U, languages.size());
109   EXPECT_EQ("fr", languages[0]);
110 }
111