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

Unified Diff: chrome/browser/spellchecker/spellcheck_profile_unittest.cc

Issue 9289007: Profiles: Move the Spelling system onto a ProfileKeyedServiceFactory. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove stray mark Created 8 years, 11 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 fc4b53d388fbf756d76329d5e4f83f303de6b79b..f0fe7060232fc3cab5b23adb2c15f3150b3f4f10 100644
--- a/chrome/browser/spellchecker/spellcheck_profile_unittest.cc
+++ b/chrome/browser/spellchecker/spellcheck_profile_unittest.cc
@@ -5,8 +5,10 @@
#include <vector>
#include "base/scoped_temp_dir.h"
+#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_host.h"
#include "chrome/browser/spellchecker/spellcheck_profile.h"
+#include "chrome/test/base/testing_profile.h"
#include "content/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,8 +34,8 @@ class MockSpellCheckHost : public SpellCheckHost {
class TestingSpellCheckProfile : public SpellCheckProfile {
public:
- explicit TestingSpellCheckProfile(const FilePath& profile_dir)
- : SpellCheckProfile(profile_dir),
+ explicit TestingSpellCheckProfile(Profile* profile)
+ : SpellCheckProfile(profile),
create_host_calls_(0) {
}
virtual SpellCheckHost* CreateHost(
@@ -63,184 +65,183 @@ class TestingSpellCheckProfile : public SpellCheckProfile {
scoped_ptr<SpellCheckHost> returning_from_create_;
};
-typedef SpellCheckProfile::ReinitializeResult ResultType;
-} // namespace
+ProfileKeyedService* BuildTestingSpellCheckProfile(Profile* profile) {
+ return new TestingSpellCheckProfile(profile);
+}
class SpellCheckProfileTest : public testing::Test {
protected:
SpellCheckProfileTest()
- : file_thread_(BrowserThread::FILE) {
+ : file_thread_(BrowserThread::FILE),
+ profile_(new TestingProfile()) {
+ target_ = BuildSpellCheckProfileWith(profile_.get());
+ }
+
+ static TestingSpellCheckProfile* BuildSpellCheckProfileWith(
+ TestingProfile* profile) {
+ return static_cast<TestingSpellCheckProfile*>(
+ SpellCheckFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile, &BuildTestingSpellCheckProfile));
}
// SpellCheckHost will be deleted on FILE thread.
content::TestBrowserThread file_thread_;
+
+ scoped_ptr<TestingProfile> profile_;
+
+ // Our normal profile, created as part of test startup.
+ TestingSpellCheckProfile* target_;
};
+} // namespace
+
TEST_F(SpellCheckProfileTest, ReinitializeEnabled) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
- target.SetHostToBeCreated(host.release());
+ target_->SetHostToBeCreated(host.release());
// The first call should create host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- EXPECT_EQ(target.create_host_calls_, 1U);
+ SpellCheckProfile::ReinitializeResult result1 =
+ target_->ReinitializeHostImpl(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);
+ SpellCheckProfile::ReinitializeResult result2 =
+ target_->ReinitializeHostImpl(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(0);
+ EXPECT_TRUE(target_->IsCreatedHostReady());
}
TEST_F(SpellCheckProfileTest, ReinitializeDisabled) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.returning_from_create_.reset(host.release());
+ target_->returning_from_create_.reset(host.release());
// If enabled is false, nothing should happen
- ResultType result1 = target.ReinitializeHost(false, false, "", NULL);
- EXPECT_EQ(target.create_host_calls_, 0U);
+ SpellCheckProfile::ReinitializeResult result1 =
+ target_->ReinitializeHostImpl(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);
+ SpellCheckProfile::ReinitializeResult result2 =
+ target_->ReinitializeHostImpl(true, false, "", NULL);
+ EXPECT_EQ(target_->create_host_calls_, 0U);
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_DID_NOTHING);
}
TEST_F(SpellCheckProfileTest, ReinitializeRemove) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.SetHostToBeCreated(host.release());
+ target_->SetHostToBeCreated(host.release());
// At first, create the host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- target.SpellCheckHostInitialized(0);
+ SpellCheckProfile::ReinitializeResult result1 =
+ target_->ReinitializeHostImpl(false, true, "", NULL);
+ target_->SpellCheckHostInitialized(0);
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);
+ SpellCheckProfile::ReinitializeResult result2 =
+ target_->ReinitializeHostImpl(true, false, "", NULL);
+ target_->SpellCheckHostInitialized(0);
EXPECT_EQ(result2, SpellCheckProfile::REINITIALIZE_REMOVED_HOST);
- EXPECT_FALSE(target.IsCreatedHostReady());
+ EXPECT_FALSE(target_->IsCreatedHostReady());
}
TEST_F(SpellCheckProfileTest, ReinitializeRecreate) {
scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.SetHostToBeCreated(host1.release());
+ target_->SetHostToBeCreated(host1.release());
// At first, create the host.
- ResultType result1 = target.ReinitializeHost(false, true, "", NULL);
- target.SpellCheckHostInitialized(0);
- EXPECT_EQ(target.create_host_calls_, 1U);
+ SpellCheckProfile::ReinitializeResult result1 =
+ target_->ReinitializeHostImpl(false, true, "", NULL);
+ target_->SpellCheckHostInitialized(0);
+ 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_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost());
- target.SetHostToBeCreated(host2.release());
+ target_->SetHostToBeCreated(host2.release());
- ResultType result2 = target.ReinitializeHost(true, true, "", NULL);
- target.SpellCheckHostInitialized(0);
- EXPECT_EQ(target.create_host_calls_, 2U);
+ SpellCheckProfile::ReinitializeResult result2 =
+ target_->ReinitializeHostImpl(true, true, "", NULL);
+ target_->SpellCheckHostInitialized(0);
+ 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) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.SetHostToBeCreated(host.release());
- target.ReinitializeHost(false, true, "", NULL);
+ target_->SetHostToBeCreated(host.release());
+ target_->ReinitializeHostImpl(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
(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_->SpellCheckHostInitialized(loaded_custom_words.release());
+ EXPECT_EQ(target_->GetCustomWords(), expected);
}
TEST_F(SpellCheckProfileTest, CustomWordAddedLocally) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.SetHostToBeCreated(host.release());
- target.ReinitializeHost(false, true, "", NULL);
+ target_->SetHostToBeCreated(host.release());
+ target_->ReinitializeHostImpl(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words
(new SpellCheckProfile::CustomWordList());
- target.SpellCheckHostInitialized(NULL);
+ target_->SpellCheckHostInitialized(NULL);
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);
}
TEST_F(SpellCheckProfileTest, SaveAndLoad) {
scoped_ptr<MockSpellCheckHost> host(new MockSpellCheckHost());
- ScopedTempDir dir;
- ASSERT_TRUE(dir.CreateUniqueTempDir());
- TestingSpellCheckProfile target(dir.path());
-
- target.SetHostToBeCreated(host.release());
- target.ReinitializeHost(false, true, "", NULL);
+ target_->SetHostToBeCreated(host.release());
+ target_->ReinitializeHostImpl(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words(
new SpellCheckProfile::CustomWordList());
- target.LoadCustomDictionary(loaded_custom_words.get());
+ target_->LoadCustomDictionary(loaded_custom_words.get());
// The custom word list should be empty now.
SpellCheckProfile::CustomWordList expected;
EXPECT_EQ(*loaded_custom_words, expected);
- target.WriteWordToCustomDictionary("foo");
+ target_->WriteWordToCustomDictionary("foo");
expected.push_back("foo");
- target.WriteWordToCustomDictionary("bar");
+ target_->WriteWordToCustomDictionary("bar");
expected.push_back("bar");
// The custom word list should include written words.
- target.LoadCustomDictionary(loaded_custom_words.get());
+ target_->LoadCustomDictionary(loaded_custom_words.get());
EXPECT_EQ(*loaded_custom_words, expected);
// Load in another instance of SpellCheckProfile.
// The result should be the same.
scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost());
- TestingSpellCheckProfile target2(dir.path());
- target2.SetHostToBeCreated(host2.release());
- target2.ReinitializeHost(false, true, "", NULL);
+ TestingSpellCheckProfile* target2 =
+ BuildSpellCheckProfileWith(profile_.get());
+ target2->SetHostToBeCreated(host2.release());
+ target2->ReinitializeHostImpl(false, true, "", NULL);
scoped_ptr<SpellCheckProfile::CustomWordList> loaded_custom_words2(
new SpellCheckProfile::CustomWordList());
- target2.LoadCustomDictionary(loaded_custom_words2.get());
+ target2->LoadCustomDictionary(loaded_custom_words2.get());
EXPECT_EQ(*loaded_custom_words2, expected);
}
@@ -248,36 +249,32 @@ TEST_F(SpellCheckProfileTest, MultiProfile) {
scoped_ptr<MockSpellCheckHost> host1(new MockSpellCheckHost());
scoped_ptr<MockSpellCheckHost> host2(new MockSpellCheckHost());
- ScopedTempDir dir1;
- ScopedTempDir dir2;
- ASSERT_TRUE(dir1.CreateUniqueTempDir());
- ASSERT_TRUE(dir2.CreateUniqueTempDir());
- TestingSpellCheckProfile target1(dir1.path());
- TestingSpellCheckProfile target2(dir2.path());
+ TestingProfile profile2;
+ TestingSpellCheckProfile* target2 = BuildSpellCheckProfileWith(&profile2);
- target1.SetHostToBeCreated(host1.release());
- target1.ReinitializeHost(false, true, "", NULL);
- target2.SetHostToBeCreated(host2.release());
- target2.ReinitializeHost(false, true, "", NULL);
+ target_->SetHostToBeCreated(host1.release());
+ target_->ReinitializeHostImpl(false, true, "", NULL);
+ target2->SetHostToBeCreated(host2.release());
+ target2->ReinitializeHostImpl(false, true, "", NULL);
SpellCheckProfile::CustomWordList expected1;
SpellCheckProfile::CustomWordList expected2;
- target1.WriteWordToCustomDictionary("foo");
- target1.WriteWordToCustomDictionary("bar");
+ target_->WriteWordToCustomDictionary("foo");
+ target_->WriteWordToCustomDictionary("bar");
expected1.push_back("foo");
expected1.push_back("bar");
- target2.WriteWordToCustomDictionary("hoge");
- target2.WriteWordToCustomDictionary("fuga");
+ target2->WriteWordToCustomDictionary("hoge");
+ target2->WriteWordToCustomDictionary("fuga");
expected2.push_back("hoge");
expected2.push_back("fuga");
SpellCheckProfile::CustomWordList actual1;
- target1.LoadCustomDictionary(&actual1);
+ target_->LoadCustomDictionary(&actual1);
EXPECT_EQ(actual1, expected1);
SpellCheckProfile::CustomWordList actual2;
- target2.LoadCustomDictionary(&actual2);
+ target2->LoadCustomDictionary(&actual2);
EXPECT_EQ(actual2, expected2);
}

Powered by Google App Engine
This is Rietveld 408576698