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

Unified 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: Mentioned lifecycle of word_list 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellcheck_profile_unittest.cc
diff --git a/chrome/browser/spellchecker/spellcheck_profile_unittest.cc b/chrome/browser/spellchecker/spellcheck_profile_unittest.cc
index 4e03fa9160c5226d58c6166a7b2b9ffd16c32109..d870d0340c0edd23d325730be3a4fed14038794e 100644
--- a/chrome/browser/spellchecker/spellcheck_profile_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_profile_unittest.cc
@@ -4,6 +4,7 @@
#include <vector>
+#include "base/scoped_temp_dir.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_profile.h"
#include "content/browser/browser_thread.h"
@@ -56,8 +57,16 @@ class TestingSpellCheckProfile : public SpellCheckProfile {
returning_from_create_ = host;
}
+ FilePath GetCustomDictionaryDir() {
+ if (!custom_dictionary_dir_.IsValid())
+ EXPECT_TRUE(custom_dictionary_dir_.CreateUniqueTempDir());
+
+ return custom_dictionary_dir_.path();
+ }
+
size_t create_host_calls_;
scoped_refptr<SpellCheckHost> returning_from_create_;
+ ScopedTempDir custom_dictionary_dir_;
};
typedef SpellCheckProfile::ReinitializeResult ResultType;
@@ -66,122 +75,141 @@ typedef SpellCheckProfile::ReinitializeResult ResultType;
class SpellCheckProfileTest : public testing::Test {
protected:
SpellCheckProfileTest()
- : file_thread_(BrowserThread::FILE) {
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_) {
}
// SpellCheckHost will be deleted on FILE thread.
+ MessageLoop message_loop_;
+ BrowserThread ui_thread_;
BrowserThread file_thread_;
};
TEST_F(SpellCheckProfileTest, ReinitializeEnabled) {
scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.SetHostToBeCreated(host.get());
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->SetHostToBeCreated(host.get());
// The first call should create host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- EXPECT_EQ(target.create_host_calls_, 1U);
+ ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
+ EXPECT_EQ(target->create_host_calls_, 1U);
EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
// The second call should be ignored.
- ResultType result2 = target.ReinitializeHost(false, true, "", NULL);
+ ResultType result2 = target->ReinitializeHost(false, true, "", NULL);
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
- EXPECT_EQ(target.create_host_calls_, 1U);
+ EXPECT_EQ(target->create_host_calls_, 1U);
// Host should become ready after the notification.
- EXPECT_FALSE(target.IsCreatedHostReady());
- target.SpellCheckHostInitialized(0);
- EXPECT_TRUE(target.IsCreatedHostReady());
+ EXPECT_FALSE(target->IsCreatedHostReady());
+ target->SpellCheckHostInitialized();
+ EXPECT_TRUE(target->IsCreatedHostReady());
}
TEST_F(SpellCheckProfileTest, ReinitializeDisabled) {
scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.returning_from_create_ = host.get();
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->returning_from_create_ = host.get();
// If enabled is false, nothing should happen
- ResultType result1 = target.ReinitializeHost(false, false, "", NULL);
- EXPECT_EQ(target.create_host_calls_, 0U);
+ ResultType result1 = target->ReinitializeHost(false, false, "", NULL);
+ EXPECT_EQ(target->create_host_calls_, 0U);
EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
// Nothing should happen even if forced.
- ResultType result2 = target.ReinitializeHost(true, false, "", NULL);
- EXPECT_EQ(target.create_host_calls_, 0U);
+ ResultType result2 = target->ReinitializeHost(true, false, "", NULL);
+ EXPECT_EQ(target->create_host_calls_, 0U);
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
}
TEST_F(SpellCheckProfileTest, ReinitializeRemove) {
scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.SetHostToBeCreated(host.get());
-
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->SetHostToBeCreated(host.get());
// At first, create the host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- target.SpellCheckHostInitialized(0);
+ ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
+ target->SpellCheckHostInitialized();
EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
- EXPECT_TRUE(target.IsCreatedHostReady());
+ EXPECT_TRUE(target->IsCreatedHostReady());
// Then the host should be deleted if it's forced to be disabled.
- ResultType result2 = target.ReinitializeHost(true, false, "", NULL);
- target.SpellCheckHostInitialized(0);
+ ResultType result2 = target->ReinitializeHost(true, false, "", NULL);
+ target->SpellCheckHostInitialized();
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST);
- EXPECT_FALSE(target.IsCreatedHostReady());
+ EXPECT_FALSE(target->IsCreatedHostReady());
}
TEST_F(SpellCheckProfileTest, ReinitializeRecreate) {
scoped_refptr<MockSpellCheckHost> host1(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.SetHostToBeCreated(host1.get());
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->SetHostToBeCreated(host1.get());
// At first, create the host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- target.SpellCheckHostInitialized(0);
- EXPECT_EQ(target.create_host_calls_, 1U);
+ ResultType result1 = target->ReinitializeHost(false, true, "", NULL);
+ target->SpellCheckHostInitialized();
+ EXPECT_EQ(target->create_host_calls_, 1U);
EXPECT_EQ(result1, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
- EXPECT_TRUE(target.IsCreatedHostReady());
+ EXPECT_TRUE(target->IsCreatedHostReady());
// Then the host should be re-created if it's forced to recreate.
scoped_refptr<MockSpellCheckHost> host2(new MockSpellCheckHost());
- target.SetHostToBeCreated(host2.get());
+ target->SetHostToBeCreated(host2.get());
- ResultType result2 = target.ReinitializeHost(true, true, "", NULL);
- target.SpellCheckHostInitialized(0);
- EXPECT_EQ(target.create_host_calls_, 2U);
+ ResultType result2 = target->ReinitializeHost(true, true, "", NULL);
+ target->SpellCheckHostInitialized();
+ EXPECT_EQ(target->create_host_calls_, 2U);
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_CREATED_HOST);
- EXPECT_TRUE(target.IsCreatedHostReady());
+ EXPECT_TRUE(target->IsCreatedHostReady());
}
-TEST_F(SpellCheckProfileTest, SpellCheckHostInitializedWithCustomWords) {
+TEST_F(SpellCheckProfileTest, CustomDictionaryLoaded) {
scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.SetHostToBeCreated(host.get());
- target.ReinitializeHost(false, true, "", NULL);
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->SetHostToBeCreated(host.get());
+ target->ReinitializeHost(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
- (new SpellCheckProfile::CustomWordList());
+ (new SpellCheckProfile::CustomWordList());
loaded_custom_words->push_back("foo");
loaded_custom_words->push_back("bar");
+
SpellCheckProfile::CustomWordList expected(*loaded_custom_words);
- target.SpellCheckHostInitialized(loaded_custom_words.release());
- EXPECT_EQ(target.GetCustomWords(), expected);
+ target->CustomDictionaryLoaded(loaded_custom_words.release());
+ EXPECT_EQ(target->GetCustomWords(), expected);
}
-TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) {
+TEST_F(SpellCheckProfileTest, SaveAndLoad) {
scoped_refptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- TestingSpellCheckProfile target;
- target.SetHostToBeCreated(host.get());
- target.ReinitializeHost(false, true, "", NULL);
+ scoped_refptr<TestingSpellCheckProfile> target(
+ new TestingSpellCheckProfile());
+ target->SetHostToBeCreated(host.get());
+ target->ReinitializeHost(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
(new SpellCheckProfile::CustomWordList());
- target.SpellCheckHostInitialized(NULL);
+ target->SpellCheckHostInitialized();
SpellCheckProfile::CustomWordList expected;
- EXPECT_EQ(target.GetCustomWords(), expected);
- target.CustomWordAddedLocally("foo");
+ EXPECT_EQ(target->GetCustomWords(), expected);
+ target->CustomWordAddedLocally("foo");
expected.push_back("foo");
- EXPECT_EQ(target.GetCustomWords(), expected);
- target.CustomWordAddedLocally("bar");
+ EXPECT_EQ(target->GetCustomWords(), expected);
+ target->CustomWordAddedLocally("bar");
expected.push_back("bar");
- EXPECT_EQ(target.GetCustomWords(), expected);
+ EXPECT_EQ(target->GetCustomWords(), expected);
+
+ file_thread_.message_loop()->RunAllPending();
+
+ // The same dictionary should be loaded again.
+ target->ClearCustomWords();
+ target->LoadCustomDictionary();
+ file_thread_.message_loop()->RunAllPending();
+ ui_thread_.message_loop()->RunAllPending();
+
+ EXPECT_EQ(target->GetCustomWords(), expected);
}

Powered by Google App Engine
This is Rietveld 408576698