Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / spellchecker / spellcheck_service_unittest.cc
blobc481af2a5ef4d27c417aa19b3d463d94f7438742
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 <vector>
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 BrowserContextKeyedService* BuildSpellcheckService(
21 content::BrowserContext* profile) {
22 return new SpellcheckService(static_cast<Profile*>(profile));
25 class SpellcheckServiceTest : public testing::Test {
26 protected:
27 virtual void SetUp() OVERRIDE {
28 // Use SetTestingFactoryAndUse to force creation and initialization.
29 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
30 &profile_, &BuildSpellcheckService);
33 private:
34 content::TestBrowserThreadBundle thread_bundle_;
35 TestingProfile profile_;
38 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages1) {
39 std::vector<std::string> accept_languages;
40 accept_languages.push_back("en");
41 accept_languages.push_back("en-US");
42 std::vector<std::string> languages;
44 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
45 accept_languages, "en-US", &languages);
47 EXPECT_EQ(1U, languages.size());
48 EXPECT_EQ("en-US", languages[0]);
51 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages2) {
52 std::vector<std::string> accept_languages;
53 accept_languages.push_back("en-US");
54 accept_languages.push_back("en");
55 std::vector<std::string> languages;
57 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
58 accept_languages, "en-US", &languages);
60 EXPECT_EQ(1U, languages.size());
61 EXPECT_EQ("en-US", languages[0]);
64 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages3) {
65 std::vector<std::string> accept_languages;
66 accept_languages.push_back("en");
67 accept_languages.push_back("en-US");
68 accept_languages.push_back("en-AU");
69 std::vector<std::string> languages;
71 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
72 accept_languages, "en-US", &languages);
74 EXPECT_EQ(2U, languages.size());
76 std::sort(languages.begin(), languages.end());
77 EXPECT_EQ("en-AU", languages[0]);
78 EXPECT_EQ("en-US", languages[1]);
81 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages4) {
82 std::vector<std::string> accept_languages;
83 accept_languages.push_back("en");
84 accept_languages.push_back("en-US");
85 accept_languages.push_back("fr");
86 std::vector<std::string> languages;
88 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
89 accept_languages, "en-US", &languages);
91 EXPECT_EQ(2U, languages.size());
93 std::sort(languages.begin(), languages.end());
94 EXPECT_EQ("en-US", languages[0]);
95 EXPECT_EQ("fr", languages[1]);
98 TEST_F(SpellcheckServiceTest, GetSpellCheckLanguages5) {
99 std::vector<std::string> accept_languages;
100 accept_languages.push_back("en");
101 accept_languages.push_back("en-JP"); // Will not exist.
102 accept_languages.push_back("fr");
103 accept_languages.push_back("aa"); // Will not exist.
104 std::vector<std::string> languages;
106 SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
107 accept_languages, "fr", &languages);
109 EXPECT_EQ(1U, languages.size());
110 EXPECT_EQ("fr", languages[0]);