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

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

Issue 11293241: Cleaning up the custom dictionary code relative to the SpellcheckService to make the custom diction… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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/scoped_temp_dir.h"
8 #include "chrome/browser/spellchecker/spellcheck_factory.h"
9 #include "chrome/browser/spellchecker/spellcheck_service.h"
10 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
11 #include "chrome/common/spellcheck_common.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using content::BrowserThread;
18 using chrome::spellcheck_common::WordList;
19
20 static ProfileKeyedService* BuildSpellcheckService(Profile* profile) {
21 return new SpellcheckService(profile);
22 }
23
24 class SpellcheckCustomDictionaryTest : public testing::Test {
25 protected:
26 SpellcheckCustomDictionaryTest()
27 : ui_thread_(BrowserThread::UI, &message_loop_),
28 file_thread_(BrowserThread::FILE, &message_loop_),
29 profile_(new TestingProfile()) {
30 }
31
32 void SetUp() OVERRIDE {
33 // Use SetTestingFactoryAndUse to force creation and initialization.
34 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
35 profile_.get(), &BuildSpellcheckService);
36 }
37
38 void TearDown() OVERRIDE {
39 MessageLoop::current()->RunUntilIdle();
40 }
41
42 MessageLoop message_loop_;
43 content::TestBrowserThread ui_thread_;
44 content::TestBrowserThread file_thread_;
45
46 scoped_ptr<TestingProfile> profile_;
47 };
48
49 // TODO(rlp/rouslan): Shift some of these to a cutsom dictionary test suite.
50 TEST_F(SpellcheckCustomDictionaryTest, SpellcheckSetCustomWordList) {
51 SpellcheckService* spellcheck_service =
52 SpellcheckServiceFactory::GetForProfile(profile_.get());
53
54 WordList loaded_custom_words;
55 loaded_custom_words.push_back("foo");
56 loaded_custom_words.push_back("bar");
57 WordList expected(loaded_custom_words);
58 SpellcheckCustomDictionary* custom_dictionary =
59 spellcheck_service->GetCustomDictionary();
60 custom_dictionary->SetCustomWordList(&loaded_custom_words);
61 EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
62 }
63
64 TEST_F(SpellcheckCustomDictionaryTest, CustomWordAddedLocally) {
65 SpellcheckService* spellcheck_service =
66 SpellcheckServiceFactory::GetForProfile(profile_.get());
67
68 WordList loaded_custom_words;
69 SpellcheckCustomDictionary* custom_dictionary =
70 spellcheck_service->GetCustomDictionary();
71 custom_dictionary->Load();
72 WordList expected;
73 EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
74 custom_dictionary->CustomWordAddedLocally("foo");
75 expected.push_back("foo");
76 EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
77 custom_dictionary->CustomWordAddedLocally("bar");
78 expected.push_back("bar");
79 EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
80 }
81
82 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
83 SpellcheckService* spellcheck_service =
84 SpellcheckServiceFactory::GetForProfile(profile_.get());
85 SpellcheckCustomDictionary* custom_dictionary =
86 spellcheck_service->GetCustomDictionary();
87
88 WordList loaded_custom_words;
89 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
90
91 // The custom word list should be empty now.
92 WordList expected;
93 EXPECT_EQ(loaded_custom_words, expected);
94
95 custom_dictionary->WriteWordToCustomDictionary("foo");
96 expected.push_back("foo");
97
98 custom_dictionary->WriteWordToCustomDictionary("bar");
99 expected.push_back("bar");
100
101 // The custom word list should include written words.
102 custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
103 EXPECT_EQ(loaded_custom_words, expected);
104
105 // Load in another instance of SpellCheckService.
106 // The result should be the same.
107 SpellcheckService spellcheck_service2(profile_.get());
108 WordList loaded_custom_words2;
109 spellcheck_service2.GetCustomDictionary()->
110 LoadDictionaryIntoCustomWordList(&loaded_custom_words2);
111 EXPECT_EQ(loaded_custom_words2, expected);
112 // Flush the loop now to prevent service init tasks from being run during
113 // TearDown();
114 MessageLoop::current()->RunUntilIdle();
115 }
116
117 TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
118 SpellcheckService* spellcheck_service =
119 SpellcheckServiceFactory::GetForProfile(profile_.get());
120 SpellcheckCustomDictionary* custom_dictionary =
121 spellcheck_service->GetCustomDictionary();
122 TestingProfile profile2;
123 SpellcheckService* spellcheck_service2 =
124 static_cast<SpellcheckService*>(
125 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
126 &profile2, &BuildSpellcheckService));
127 SpellcheckCustomDictionary* custom_dictionary2 =
128 spellcheck_service2->GetCustomDictionary();
129
130 WordList expected1;
131 WordList expected2;
132
133 custom_dictionary->WriteWordToCustomDictionary("foo");
134 custom_dictionary->WriteWordToCustomDictionary("bar");
135 expected1.push_back("foo");
136 expected1.push_back("bar");
137
138 custom_dictionary2->WriteWordToCustomDictionary("hoge");
139 custom_dictionary2->WriteWordToCustomDictionary("fuga");
140 expected2.push_back("hoge");
141 expected2.push_back("fuga");
142
143 WordList actual1;
144 custom_dictionary->LoadDictionaryIntoCustomWordList(&actual1);
145 EXPECT_EQ(actual1, expected1);
146
147 WordList actual2;
148 custom_dictionary2->LoadDictionaryIntoCustomWordList(&actual2);
149 EXPECT_EQ(actual2, expected2);
150
151 // Flush the loop now to prevent service init tasks from being run during
152 // TearDown();
153 MessageLoop::current()->RunUntilIdle();
154 }
OLDNEW
« no previous file with comments | « chrome/browser/spellchecker/spellcheck_custom_dictionary.cc ('k') | chrome/browser/spellchecker/spellcheck_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698