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

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

Issue 8233040: SpellCheck refactoring: Moved user custom dictionary for spell check to SpellCheckProfile. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 2 months 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "chrome/browser/spellchecker/spellcheck_host.h" 7 #include "chrome/browser/spellchecker/spellcheck_host.h"
8 #include "chrome/browser/spellchecker/spellcheck_profile.h" 8 #include "chrome/browser/spellchecker/spellcheck_profile.h"
9 #include "content/browser/browser_thread.h" 9 #include "content/browser/browser_thread.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 bool IsCreatedHostReady() { 49 bool IsCreatedHostReady() {
50 return GetHost() == returning_from_create_.get(); 50 return GetHost() == returning_from_create_.get();
51 } 51 }
52 52
53 void SetHostToBeCreated(MockSpellCheckHost* host) { 53 void SetHostToBeCreated(MockSpellCheckHost* host) {
54 EXPECT_CALL(*host, UnsetProfile()).Times(1); 54 EXPECT_CALL(*host, UnsetProfile()).Times(1);
55 EXPECT_CALL(*host, IsReady()).WillRepeatedly(testing::Return(true)); 55 EXPECT_CALL(*host, IsReady()).WillRepeatedly(testing::Return(true));
56 returning_from_create_ = host; 56 returning_from_create_ = host;
57 } 57 }
58 58
59 void LoadCustomDictionary() {
60 // Do nothing.
61 }
62
63 void WriteWordToCustomDictionary(const std::string& word) {
64 // Do nothing.
65 }
66
59 size_t create_host_calls_; 67 size_t create_host_calls_;
60 scoped_refptr<SpellCheckHost> returning_from_create_; 68 scoped_refptr<SpellCheckHost> returning_from_create_;
61 }; 69 };
62 70
63 typedef SpellCheckProfile::ReinitializeResult ResultType; 71 typedef SpellCheckProfile::ReinitializeResult ResultType;
64 } // namespace 72 } // namespace
65 73
66 class SpellCheckProfileTest : public testing::Test { 74 class SpellCheckProfileTest : public testing::Test {
67 protected: 75 protected:
68 SpellCheckProfileTest() 76 SpellCheckProfileTest()
69 : file_thread_(BrowserThread::FILE) { 77 : file_thread_(BrowserThread::FILE) {
70 } 78 }
71 79
72 // SpellCheckHost will be deleted on FILE thread. 80 // SpellCheckHost will be deleted on FILE thread.
73 BrowserThread file_thread_; 81 BrowserThread file_thread_;
74 }; 82 };
75 83
76 TEST_F(SpellCheckProfileTest, ReinitializeEnabled) { 84 TEST_F(SpellCheckProfileTest, ReinitializeEnabled) {
77 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost()); 85 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
78 TestingSpellCheckProfile target; 86 scoped_refptr<TestingSpellCheckProfile> target(
79 target.SetHostToBeCreated(host.get()); 87 new TestingSpellCheckProfile());
88 target->SetHostToBeCreated(host.get());
80 89
81 // The first call should create host. 90 // The first call should create host.
82 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); 91 ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
83 EXPECT_EQ(target.create_host_calls_, 1U); 92 EXPECT_EQ(target->create_host_calls_, 1U);
84 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); 93 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
85 94
86 // The second call should be ignored. 95 // The second call should be ignored.
87 ResultType result2 = target.ReinitializeHost(false, true, "", NULL); 96 ResultType result2 = target->ReinitializeHost(false, true, "", NULL);
88 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); 97 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
89 EXPECT_EQ(target.create_host_calls_, 1U); 98 EXPECT_EQ(target->create_host_calls_, 1U);
90 99
91 // Host should become ready after the notification. 100 // Host should become ready after the notification.
92 EXPECT_FALSE(target.IsCreatedHostReady()); 101 EXPECT_FALSE(target->IsCreatedHostReady());
93 target.SpellCheckHostInitialized(0); 102 target->SpellCheckHostInitialized();
94 EXPECT_TRUE(target.IsCreatedHostReady()); 103 EXPECT_TRUE(target->IsCreatedHostReady());
95 } 104 }
96 105
97 TEST_F(SpellCheckProfileTest, ReinitializeDisabled) { 106 TEST_F(SpellCheckProfileTest, ReinitializeDisabled) {
98 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost()); 107 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
99 TestingSpellCheckProfile target; 108 scoped_refptr<TestingSpellCheckProfile> target(
100 target.returning_from_create_ = host.get(); 109 new TestingSpellCheckProfile());
110 target->returning_from_create_ = host.get();
101 111
102 // If enabled is false, nothing should happen 112 // If enabled is false, nothing should happen
103 ResultType result1 = target.ReinitializeHost(false, false, "", NULL); 113 ResultType result1 = target->ReinitializeHost(false, false, "", NULL);
104 EXPECT_EQ(target.create_host_calls_, 0U); 114 EXPECT_EQ(target->create_host_calls_, 0U);
105 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_DID_NOTHING); 115 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
106 116
107 // Nothing should happen even if forced. 117 // Nothing should happen even if forced.
108 ResultType result2 = target.ReinitializeHost(true, false, "", NULL); 118 ResultType result2 = target->ReinitializeHost(true, false, "", NULL);
109 EXPECT_EQ(target.create_host_calls_, 0U); 119 EXPECT_EQ(target->create_host_calls_, 0U);
110 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); 120 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
111 } 121 }
112 122
113 TEST_F(SpellCheckProfileTest, ReinitializeRemove) { 123 TEST_F(SpellCheckProfileTest, ReinitializeRemove) {
114 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost()); 124 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
115 TestingSpellCheckProfile target; 125 scoped_refptr<TestingSpellCheckProfile> target(
116 target.SetHostToBeCreated(host.get()); 126 new TestingSpellCheckProfile());
117 127 target->SetHostToBeCreated(host.get());
118 128
119 // At first, create the host. 129 // At first, create the host.
120 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); 130 ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
121 target.SpellCheckHostInitialized(0); 131 target->SpellCheckHostInitialized();
122 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); 132 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
123 EXPECT_TRUE(target.IsCreatedHostReady()); 133 EXPECT_TRUE(target->IsCreatedHostReady());
124 134
125 // Then the host should be deleted if it's forced to be disabled. 135 // Then the host should be deleted if it's forced to be disabled.
126 ResultType result2 = target.ReinitializeHost(true, false, "", NULL); 136 ResultType result2 = target->ReinitializeHost(true, false, "", NULL);
127 target.SpellCheckHostInitialized(0); 137 target->SpellCheckHostInitialized();
128 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST); 138 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST);
129 EXPECT_FALSE(target.IsCreatedHostReady()); 139 EXPECT_FALSE(target->IsCreatedHostReady());
130 } 140 }
131 141
132 TEST_F(SpellCheckProfileTest, ReinitializeRecreate) { 142 TEST_F(SpellCheckProfileTest, ReinitializeRecreate) {
133 scoped_refptr<MockSpellCheckHost> host1(new MockSpellCheckHost()); 143 scoped_refptr<MockSpellCheckHost> host1(new MockSpellCheckHost());
134 TestingSpellCheckProfile target; 144 scoped_refptr<TestingSpellCheckProfile> target(
135 target.SetHostToBeCreated(host1.get()); 145 new TestingSpellCheckProfile());
146 target->SetHostToBeCreated(host1.get());
136 147
137 // At first, create the host. 148 // At first, create the host.
138 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); 149 ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
139 target.SpellCheckHostInitialized(0); 150 target->SpellCheckHostInitialized();
140 EXPECT_EQ(target.create_host_calls_, 1U); 151 EXPECT_EQ(target->create_host_calls_, 1U);
141 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); 152 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
142 EXPECT_TRUE(target.IsCreatedHostReady()); 153 EXPECT_TRUE(target->IsCreatedHostReady());
143 154
144 // Then the host should be re-created if it's forced to recreate. 155 // Then the host should be re-created if it's forced to recreate.
145 scoped_refptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); 156 scoped_refptr<MockSpellCheckHost> host2(new MockSpellCheckHost());
146 target.SetHostToBeCreated(host2.get()); 157 target->SetHostToBeCreated(host2.get());
147 158
148 ResultType result2 = target.ReinitializeHost(true, true, "", NULL); 159 ResultType result2 = target->ReinitializeHost(true, true, "", NULL);
149 target.SpellCheckHostInitialized(0); 160 target->SpellCheckHostInitialized();
150 EXPECT_EQ(target.create_host_calls_, 2U); 161 EXPECT_EQ(target->create_host_calls_, 2U);
151 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_CREATED_HOST); 162 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
152 EXPECT_TRUE(target.IsCreatedHostReady()); 163 EXPECT_TRUE(target->IsCreatedHostReady());
153 }
154
155 TEST_F(SpellCheckProfileTest, SpellCheckHostInitializedWithCustomWords) {
Hironori Bono 2011/10/12 02:56:56 I'm wondering why this change deletes this test. (
shinyak (Google) 2011/10/12 10:46:54 Done.
156 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
157 TestingSpellCheckProfile target;
158 target.SetHostToBeCreated(host.get());
159 target.ReinitializeHost(false, true, "", NULL);
160
161 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
162 (new SpellCheckProfile::CustomWordList());
163 loaded_custom_words->push_back("foo");
164 loaded_custom_words->push_back("bar");
165 SpellCheckProfile::CustomWordList expected(*loaded_custom_words);
166 target.SpellCheckHostInitialized(loaded_custom_words.release());
167 EXPECT_EQ(target.GetCustomWords(), expected);
168 } 164 }
169 165
170 TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) { 166 TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) {
171 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost()); 167 scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
172 TestingSpellCheckProfile target; 168 scoped_refptr<TestingSpellCheckProfile> target(
173 target.SetHostToBeCreated(host.get()); 169 new TestingSpellCheckProfile());
174 target.ReinitializeHost(false, true, "", NULL); 170 target->SetHostToBeCreated(host.get());
171 target->ReinitializeHost(false, true, "", NULL);
175 172
176 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words 173 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
177 (new SpellCheckProfile::CustomWordList()); 174 (new SpellCheckProfile::CustomWordList());
178 target.SpellCheckHostInitialized(NULL); 175 target->SpellCheckHostInitialized();
179 SpellCheckProfile::CustomWordList expected; 176 SpellCheckProfile::CustomWordList expected;
180 EXPECT_EQ(target.GetCustomWords(), expected); 177 EXPECT_EQ(target->GetCustomWords(), expected);
181 target.CustomWordAddedLocally("foo"); 178 target->CustomWordAddedLocally("foo");
182 expected.push_back("foo"); 179 expected.push_back("foo");
183 EXPECT_EQ(target.GetCustomWords(), expected); 180 EXPECT_EQ(target->GetCustomWords(), expected);
184 target.CustomWordAddedLocally("bar"); 181 target->CustomWordAddedLocally("bar");
185 expected.push_back("bar"); 182 expected.push_back("bar");
186 EXPECT_EQ(target.GetCustomWords(), expected); 183 EXPECT_EQ(target->GetCustomWords(), expected);
187 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698