| OLD | NEW |
| 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 "base/scoped_temp_dir.h" | 7 #include "base/scoped_temp_dir.h" |
| 8 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
| 8 #include "chrome/browser/spellchecker/spellcheck_host.h" | 9 #include "chrome/browser/spellchecker/spellcheck_host.h" |
| 9 #include "chrome/browser/spellchecker/spellcheck_profile.h" | 10 #include "chrome/browser/spellchecker/spellcheck_profile.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/test/test_browser_thread.h" | 12 #include "content/test/test_browser_thread.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 14 using content::BrowserThread; | 16 using content::BrowserThread; |
| 15 | 17 |
| 16 namespace { | 18 namespace { |
| 17 | 19 |
| 18 class MockSpellCheckHost : public SpellCheckHost { | 20 class MockSpellCheckHost : public SpellCheckHost { |
| 19 public: | 21 public: |
| 20 MOCK_METHOD0(UnsetProfile, void()); | 22 MOCK_METHOD0(UnsetProfile, void()); |
| 21 MOCK_METHOD1(InitForRenderer, void(content::RenderProcessHost* process)); | 23 MOCK_METHOD1(InitForRenderer, void(content::RenderProcessHost* process)); |
| 22 MOCK_METHOD1(AddWord, void(const std::string& word)); | 24 MOCK_METHOD1(AddWord, void(const std::string& word)); |
| 23 MOCK_CONST_METHOD0(GetDictionaryFile, const base::PlatformFile&()); | 25 MOCK_CONST_METHOD0(GetDictionaryFile, const base::PlatformFile&()); |
| 24 MOCK_CONST_METHOD0(GetCustomWords, | 26 MOCK_CONST_METHOD0(GetCustomWords, |
| 25 const SpellCheckProfile::CustomWordList&()); | 27 const SpellCheckProfile::CustomWordList&()); |
| 26 MOCK_CONST_METHOD0(GetLastAddedFile, const std::string&()); | 28 MOCK_CONST_METHOD0(GetLastAddedFile, const std::string&()); |
| 27 MOCK_CONST_METHOD0(GetLanguage, const std::string&()); | 29 MOCK_CONST_METHOD0(GetLanguage, const std::string&()); |
| 28 MOCK_CONST_METHOD0(IsUsingPlatformChecker, bool()); | 30 MOCK_CONST_METHOD0(IsUsingPlatformChecker, bool()); |
| 29 MOCK_CONST_METHOD0(GetMetrics, SpellCheckHostMetrics*()); | 31 MOCK_CONST_METHOD0(GetMetrics, SpellCheckHostMetrics*()); |
| 30 MOCK_CONST_METHOD0(IsReady, bool()); | 32 MOCK_CONST_METHOD0(IsReady, bool()); |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 class TestingSpellCheckProfile : public SpellCheckProfile { | 35 class TestingSpellCheckProfile : public SpellCheckProfile { |
| 34 public: | 36 public: |
| 35 explicit TestingSpellCheckProfile(const FilePath& profile_dir) | 37 explicit TestingSpellCheckProfile(Profile* profile) |
| 36 : SpellCheckProfile(profile_dir), | 38 : SpellCheckProfile(profile), |
| 37 create_host_calls_(0) { | 39 create_host_calls_(0) { |
| 38 } | 40 } |
| 39 virtual SpellCheckHost* CreateHost( | 41 virtual SpellCheckHost* CreateHost( |
| 40 SpellCheckProfileProvider* profile, | 42 SpellCheckProfileProvider* profile, |
| 41 const std::string& language, | 43 const std::string& language, |
| 42 net::URLRequestContextGetter* request_context, | 44 net::URLRequestContextGetter* request_context, |
| 43 SpellCheckHostMetrics* metrics) { | 45 SpellCheckHostMetrics* metrics) { |
| 44 create_host_calls_++; | 46 create_host_calls_++; |
| 45 return returning_from_create_.release(); | 47 return returning_from_create_.release(); |
| 46 } | 48 } |
| 47 | 49 |
| 48 virtual bool IsTesting() const { | 50 virtual bool IsTesting() const { |
| 49 return true; | 51 return true; |
| 50 } | 52 } |
| 51 | 53 |
| 52 bool IsCreatedHostReady() { | 54 bool IsCreatedHostReady() { |
| 53 return !!GetHost(); | 55 return !!GetHost(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void SetHostToBeCreated(MockSpellCheckHost* host) { | 58 void SetHostToBeCreated(MockSpellCheckHost* host) { |
| 57 EXPECT_CALL(*host, UnsetProfile()).Times(1); | 59 EXPECT_CALL(*host, UnsetProfile()).Times(1); |
| 58 EXPECT_CALL(*host, IsReady()).WillRepeatedly(testing::Return(true)); | 60 EXPECT_CALL(*host, IsReady()).WillRepeatedly(testing::Return(true)); |
| 59 returning_from_create_.reset(host); | 61 returning_from_create_.reset(host); |
| 60 } | 62 } |
| 61 | 63 |
| 62 size_t create_host_calls_; | 64 size_t create_host_calls_; |
| 63 scoped_ptr<SpellCheckHost> returning_from_create_; | 65 scoped_ptr<SpellCheckHost> returning_from_create_; |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 typedef SpellCheckProfile::ReinitializeResult ResultType; | 68 ProfileKeyedService* BuildTestingSpellCheckProfile(Profile* profile) { |
| 67 } // namespace | 69 return new TestingSpellCheckProfile(profile); |
| 70 } |
| 68 | 71 |
| 69 class SpellCheckProfileTest : public testing::Test { | 72 class SpellCheckProfileTest : public testing::Test { |
| 70 protected: | 73 protected: |
| 71 SpellCheckProfileTest() | 74 SpellCheckProfileTest() |
| 72 : file_thread_(BrowserThread::FILE) { | 75 : file_thread_(BrowserThread::FILE), |
| 76 profile_(new TestingProfile()) { |
| 77 target_ = BuildSpellCheckProfileWith(profile_.get()); |
| 78 } |
| 79 |
| 80 static TestingSpellCheckProfile* BuildSpellCheckProfileWith( |
| 81 TestingProfile* profile) { |
| 82 return static_cast<TestingSpellCheckProfile*>( |
| 83 SpellCheckFactory::GetInstance()->SetTestingFactoryAndUse( |
| 84 profile, &BuildTestingSpellCheckProfile)); |
| 73 } | 85 } |
| 74 | 86 |
| 75 // SpellCheckHost will be deleted on FILE thread. | 87 // SpellCheckHost will be deleted on FILE thread. |
| 76 content::TestBrowserThread file_thread_; | 88 content::TestBrowserThread file_thread_; |
| 89 |
| 90 scoped_ptr<TestingProfile> profile_; |
| 91 |
| 92 // Our normal profile, created as part of test startup. |
| 93 TestingSpellCheckProfile* target_; |
| 77 }; | 94 }; |
| 78 | 95 |
| 96 } // namespace |
| 97 |
| 79 TEST_F(SpellCheckProfileTest, ReinitializeEnabled) { | 98 TEST_F(SpellCheckProfileTest, ReinitializeEnabled) { |
| 80 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 99 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 81 ScopedTempDir dir; | 100 target_->SetHostToBeCreated(host.release()); |
| 82 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
| 83 TestingSpellCheckProfile target(dir.path()); | |
| 84 target.SetHostToBeCreated(host.release()); | |
| 85 | 101 |
| 86 // The first call should create host. | 102 // The first call should create host. |
| 87 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); | 103 SpellCheckProfile::ReinitializeResult result1 = |
| 88 EXPECT_EQ(target.create_host_calls_, 1U); | 104 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 105 EXPECT_EQ(target_->create_host_calls_, 1U); |
| 89 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); | 106 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); |
| 90 | 107 |
| 91 // The second call should be ignored. | 108 // The second call should be ignored. |
| 92 ResultType result2 = target.ReinitializeHost(false, true, "", NULL); | 109 SpellCheckProfile::ReinitializeResult result2 = |
| 110 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 93 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); | 111 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); |
| 94 EXPECT_EQ(target.create_host_calls_, 1U); | 112 EXPECT_EQ(target_->create_host_calls_, 1U); |
| 95 | 113 |
| 96 // Host should become ready after the notification. | 114 // Host should become ready after the notification. |
| 97 EXPECT_FALSE(target.IsCreatedHostReady()); | 115 EXPECT_FALSE(target_->IsCreatedHostReady()); |
| 98 target.SpellCheckHostInitialized(0); | 116 target_->SpellCheckHostInitialized(0); |
| 99 EXPECT_TRUE(target.IsCreatedHostReady()); | 117 EXPECT_TRUE(target_->IsCreatedHostReady()); |
| 100 } | 118 } |
| 101 | 119 |
| 102 TEST_F(SpellCheckProfileTest, ReinitializeDisabled) { | 120 TEST_F(SpellCheckProfileTest, ReinitializeDisabled) { |
| 103 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 121 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 104 ScopedTempDir dir; | 122 target_->returning_from_create_.reset(host.release()); |
| 105 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
| 106 TestingSpellCheckProfile target(dir.path()); | |
| 107 | |
| 108 target.returning_from_create_.reset(host.release()); | |
| 109 | 123 |
| 110 // If enabled is false, nothing should happen | 124 // If enabled is false, nothing should happen |
| 111 ResultType result1 = target.ReinitializeHost(false, false, "", NULL); | 125 SpellCheckProfile::ReinitializeResult result1 = |
| 112 EXPECT_EQ(target.create_host_calls_, 0U); | 126 target_->ReinitializeHostImpl(false, false, "", NULL); |
| 127 EXPECT_EQ(target_->create_host_calls_, 0U); |
| 113 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_DID_NOTHING); | 128 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_DID_NOTHING); |
| 114 | 129 |
| 115 // Nothing should happen even if forced. | 130 // Nothing should happen even if forced. |
| 116 ResultType result2 = target.ReinitializeHost(true, false, "", NULL); | 131 SpellCheckProfile::ReinitializeResult result2 = |
| 117 EXPECT_EQ(target.create_host_calls_, 0U); | 132 target_->ReinitializeHostImpl(true, false, "", NULL); |
| 133 EXPECT_EQ(target_->create_host_calls_, 0U); |
| 118 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); | 134 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING); |
| 119 } | 135 } |
| 120 | 136 |
| 121 TEST_F(SpellCheckProfileTest, ReinitializeRemove) { | 137 TEST_F(SpellCheckProfileTest, ReinitializeRemove) { |
| 122 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 138 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 123 ScopedTempDir dir; | 139 target_->SetHostToBeCreated(host.release()); |
| 124 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
| 125 TestingSpellCheckProfile target(dir.path()); | |
| 126 | |
| 127 target.SetHostToBeCreated(host.release()); | |
| 128 | 140 |
| 129 // At first, create the host. | 141 // At first, create the host. |
| 130 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); | 142 SpellCheckProfile::ReinitializeResult result1 = |
| 131 target.SpellCheckHostInitialized(0); | 143 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 144 target_->SpellCheckHostInitialized(0); |
| 132 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); | 145 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); |
| 133 EXPECT_TRUE(target.IsCreatedHostReady()); | 146 EXPECT_TRUE(target_->IsCreatedHostReady()); |
| 134 | 147 |
| 135 // Then the host should be deleted if it's forced to be disabled. | 148 // Then the host should be deleted if it's forced to be disabled. |
| 136 ResultType result2 = target.ReinitializeHost(true, false, "", NULL); | 149 SpellCheckProfile::ReinitializeResult result2 = |
| 137 target.SpellCheckHostInitialized(0); | 150 target_->ReinitializeHostImpl(true, false, "", NULL); |
| 151 target_->SpellCheckHostInitialized(0); |
| 138 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST); | 152 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST); |
| 139 EXPECT_FALSE(target.IsCreatedHostReady()); | 153 EXPECT_FALSE(target_->IsCreatedHostReady()); |
| 140 } | 154 } |
| 141 | 155 |
| 142 TEST_F(SpellCheckProfileTest, ReinitializeRecreate) { | 156 TEST_F(SpellCheckProfileTest, ReinitializeRecreate) { |
| 143 scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost()); | 157 scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost()); |
| 144 ScopedTempDir dir; | 158 target_->SetHostToBeCreated(host1.release()); |
| 145 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
| 146 TestingSpellCheckProfile target(dir.path()); | |
| 147 | |
| 148 target.SetHostToBeCreated(host1.release()); | |
| 149 | 159 |
| 150 // At first, create the host. | 160 // At first, create the host. |
| 151 ResultType result1 = target.ReinitializeHost(false, true, "", NULL); | 161 SpellCheckProfile::ReinitializeResult result1 = |
| 152 target.SpellCheckHostInitialized(0); | 162 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 153 EXPECT_EQ(target.create_host_calls_, 1U); | 163 target_->SpellCheckHostInitialized(0); |
| 164 EXPECT_EQ(target_->create_host_calls_, 1U); |
| 154 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); | 165 EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST); |
| 155 EXPECT_TRUE(target.IsCreatedHostReady()); | 166 EXPECT_TRUE(target_->IsCreatedHostReady()); |
| 156 | 167 |
| 157 // Then the host should be re-created if it's forced to recreate. | 168 // Then the host should be re-created if it's forced to recreate. |
| 158 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); | 169 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); |
| 159 target.SetHostToBeCreated(host2.release()); | 170 target_->SetHostToBeCreated(host2.release()); |
| 160 | 171 |
| 161 ResultType result2 = target.ReinitializeHost(true, true, "", NULL); | 172 SpellCheckProfile::ReinitializeResult result2 = |
| 162 target.SpellCheckHostInitialized(0); | 173 target_->ReinitializeHostImpl(true, true, "", NULL); |
| 163 EXPECT_EQ(target.create_host_calls_, 2U); | 174 target_->SpellCheckHostInitialized(0); |
| 175 EXPECT_EQ(target_->create_host_calls_, 2U); |
| 164 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_CREATED_HOST); | 176 EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_CREATED_HOST); |
| 165 EXPECT_TRUE(target.IsCreatedHostReady()); | 177 EXPECT_TRUE(target_->IsCreatedHostReady()); |
| 166 } | 178 } |
| 167 | 179 |
| 168 TEST_F(SpellCheckProfileTest, SpellCheckHostInitializedWithCustomWords) { | 180 TEST_F(SpellCheckProfileTest, SpellCheckHostInitializedWithCustomWords) { |
| 169 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 181 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 170 ScopedTempDir dir; | 182 target_->SetHostToBeCreated(host.release()); |
| 171 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 183 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 172 TestingSpellCheckProfile target(dir.path()); | |
| 173 | |
| 174 target.SetHostToBeCreated(host.release()); | |
| 175 target.ReinitializeHost(false, true, "", NULL); | |
| 176 | 184 |
| 177 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words | 185 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words |
| 178 (new SpellCheckProfile::CustomWordList()); | 186 (new SpellCheckProfile::CustomWordList()); |
| 179 loaded_custom_words->push_back("foo"); | 187 loaded_custom_words->push_back("foo"); |
| 180 loaded_custom_words->push_back("bar"); | 188 loaded_custom_words->push_back("bar"); |
| 181 SpellCheckProfile::CustomWordList expected(*loaded_custom_words); | 189 SpellCheckProfile::CustomWordList expected(*loaded_custom_words); |
| 182 target.SpellCheckHostInitialized(loaded_custom_words.release()); | 190 target_->SpellCheckHostInitialized(loaded_custom_words.release()); |
| 183 EXPECT_EQ(target.GetCustomWords(), expected); | 191 EXPECT_EQ(target_->GetCustomWords(), expected); |
| 184 } | 192 } |
| 185 | 193 |
| 186 TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) { | 194 TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) { |
| 187 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 195 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 188 ScopedTempDir dir; | 196 target_->SetHostToBeCreated(host.release()); |
| 189 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 197 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 190 TestingSpellCheckProfile target(dir.path()); | |
| 191 | |
| 192 target.SetHostToBeCreated(host.release()); | |
| 193 target.ReinitializeHost(false, true, "", NULL); | |
| 194 | 198 |
| 195 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words | 199 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words |
| 196 (new SpellCheckProfile::CustomWordList()); | 200 (new SpellCheckProfile::CustomWordList()); |
| 197 target.SpellCheckHostInitialized(NULL); | 201 target_->SpellCheckHostInitialized(NULL); |
| 198 SpellCheckProfile::CustomWordList expected; | 202 SpellCheckProfile::CustomWordList expected; |
| 199 EXPECT_EQ(target.GetCustomWords(), expected); | 203 EXPECT_EQ(target_->GetCustomWords(), expected); |
| 200 target.CustomWordAddedLocally("foo"); | 204 target_->CustomWordAddedLocally("foo"); |
| 201 expected.push_back("foo"); | 205 expected.push_back("foo"); |
| 202 EXPECT_EQ(target.GetCustomWords(), expected); | 206 EXPECT_EQ(target_->GetCustomWords(), expected); |
| 203 target.CustomWordAddedLocally("bar"); | 207 target_->CustomWordAddedLocally("bar"); |
| 204 expected.push_back("bar"); | 208 expected.push_back("bar"); |
| 205 EXPECT_EQ(target.GetCustomWords(), expected); | 209 EXPECT_EQ(target_->GetCustomWords(), expected); |
| 206 } | 210 } |
| 207 | 211 |
| 208 TEST_F(SpellCheckProfileTest, SaveAndLoad) { | 212 TEST_F(SpellCheckProfileTest, SaveAndLoad) { |
| 209 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); | 213 scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost()); |
| 210 ScopedTempDir dir; | 214 target_->SetHostToBeCreated(host.release()); |
| 211 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 215 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 212 TestingSpellCheckProfile target(dir.path()); | |
| 213 | |
| 214 target.SetHostToBeCreated(host.release()); | |
| 215 target.ReinitializeHost(false, true, "", NULL); | |
| 216 | 216 |
| 217 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words( | 217 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words( |
| 218 new SpellCheckProfile::CustomWordList()); | 218 new SpellCheckProfile::CustomWordList()); |
| 219 target.LoadCustomDictionary(loaded_custom_words.get()); | 219 target_->LoadCustomDictionary(loaded_custom_words.get()); |
| 220 | 220 |
| 221 // The custom word list should be empty now. | 221 // The custom word list should be empty now. |
| 222 SpellCheckProfile::CustomWordList expected; | 222 SpellCheckProfile::CustomWordList expected; |
| 223 EXPECT_EQ(*loaded_custom_words, expected); | 223 EXPECT_EQ(*loaded_custom_words, expected); |
| 224 | 224 |
| 225 target.WriteWordToCustomDictionary("foo"); | 225 target_->WriteWordToCustomDictionary("foo"); |
| 226 expected.push_back("foo"); | 226 expected.push_back("foo"); |
| 227 | 227 |
| 228 target.WriteWordToCustomDictionary("bar"); | 228 target_->WriteWordToCustomDictionary("bar"); |
| 229 expected.push_back("bar"); | 229 expected.push_back("bar"); |
| 230 | 230 |
| 231 // The custom word list should include written words. | 231 // The custom word list should include written words. |
| 232 target.LoadCustomDictionary(loaded_custom_words.get()); | 232 target_->LoadCustomDictionary(loaded_custom_words.get()); |
| 233 EXPECT_EQ(*loaded_custom_words, expected); | 233 EXPECT_EQ(*loaded_custom_words, expected); |
| 234 | 234 |
| 235 // Load in another instance of SpellCheckProfile. | 235 // Load in another instance of SpellCheckProfile. |
| 236 // The result should be the same. | 236 // The result should be the same. |
| 237 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); | 237 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); |
| 238 TestingSpellCheckProfile target2(dir.path()); | 238 TestingSpellCheckProfile* target2 = |
| 239 target2.SetHostToBeCreated(host2.release()); | 239 BuildSpellCheckProfileWith(profile_.get()); |
| 240 target2.ReinitializeHost(false, true, "", NULL); | 240 target2->SetHostToBeCreated(host2.release()); |
| 241 target2->ReinitializeHostImpl(false, true, "", NULL); |
| 241 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words2( | 242 scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words2( |
| 242 new SpellCheckProfile::CustomWordList()); | 243 new SpellCheckProfile::CustomWordList()); |
| 243 target2.LoadCustomDictionary(loaded_custom_words2.get()); | 244 target2->LoadCustomDictionary(loaded_custom_words2.get()); |
| 244 EXPECT_EQ(*loaded_custom_words2, expected); | 245 EXPECT_EQ(*loaded_custom_words2, expected); |
| 245 } | 246 } |
| 246 | 247 |
| 247 TEST_F(SpellCheckProfileTest, MultiProfile) { | 248 TEST_F(SpellCheckProfileTest, MultiProfile) { |
| 248 scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost()); | 249 scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost()); |
| 249 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); | 250 scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost()); |
| 250 | 251 |
| 251 ScopedTempDir dir1; | 252 TestingProfile profile2; |
| 252 ScopedTempDir dir2; | 253 TestingSpellCheckProfile* target2 = BuildSpellCheckProfileWith(&profile2); |
| 253 ASSERT_TRUE(dir1.CreateUniqueTempDir()); | |
| 254 ASSERT_TRUE(dir2.CreateUniqueTempDir()); | |
| 255 TestingSpellCheckProfile target1(dir1.path()); | |
| 256 TestingSpellCheckProfile target2(dir2.path()); | |
| 257 | 254 |
| 258 target1.SetHostToBeCreated(host1.release()); | 255 target_->SetHostToBeCreated(host1.release()); |
| 259 target1.ReinitializeHost(false, true, "", NULL); | 256 target_->ReinitializeHostImpl(false, true, "", NULL); |
| 260 target2.SetHostToBeCreated(host2.release()); | 257 target2->SetHostToBeCreated(host2.release()); |
| 261 target2.ReinitializeHost(false, true, "", NULL); | 258 target2->ReinitializeHostImpl(false, true, "", NULL); |
| 262 | 259 |
| 263 SpellCheckProfile::CustomWordList expected1; | 260 SpellCheckProfile::CustomWordList expected1; |
| 264 SpellCheckProfile::CustomWordList expected2; | 261 SpellCheckProfile::CustomWordList expected2; |
| 265 | 262 |
| 266 target1.WriteWordToCustomDictionary("foo"); | 263 target_->WriteWordToCustomDictionary("foo"); |
| 267 target1.WriteWordToCustomDictionary("bar"); | 264 target_->WriteWordToCustomDictionary("bar"); |
| 268 expected1.push_back("foo"); | 265 expected1.push_back("foo"); |
| 269 expected1.push_back("bar"); | 266 expected1.push_back("bar"); |
| 270 | 267 |
| 271 target2.WriteWordToCustomDictionary("hoge"); | 268 target2->WriteWordToCustomDictionary("hoge"); |
| 272 target2.WriteWordToCustomDictionary("fuga"); | 269 target2->WriteWordToCustomDictionary("fuga"); |
| 273 expected2.push_back("hoge"); | 270 expected2.push_back("hoge"); |
| 274 expected2.push_back("fuga"); | 271 expected2.push_back("fuga"); |
| 275 | 272 |
| 276 SpellCheckProfile::CustomWordList actual1; | 273 SpellCheckProfile::CustomWordList actual1; |
| 277 target1.LoadCustomDictionary(&actual1); | 274 target_->LoadCustomDictionary(&actual1); |
| 278 EXPECT_EQ(actual1, expected1); | 275 EXPECT_EQ(actual1, expected1); |
| 279 | 276 |
| 280 SpellCheckProfile::CustomWordList actual2; | 277 SpellCheckProfile::CustomWordList actual2; |
| 281 target2.LoadCustomDictionary(&actual2); | 278 target2->LoadCustomDictionary(&actual2); |
| 282 EXPECT_EQ(actual2, expected2); | 279 EXPECT_EQ(actual2, expected2); |
| 283 } | 280 } |
| OLD | NEW |