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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
diff --git a/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
new file mode 100755
index 0000000000000000000000000000000000000000..249ca1b8ac3680f284e2ce06663b3b91964a5837
--- /dev/null
+++ b/chrome/browser/spellchecker/spellcheck_custom_dictionary_unittest.cc
@@ -0,0 +1,154 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/spellchecker/spellcheck_factory.h"
+#include "chrome/browser/spellchecker/spellcheck_service.h"
+#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
+#include "chrome/common/spellcheck_common.h"
+#include "chrome/test/base/testing_profile.h"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using content::BrowserThread;
+using chrome::spellcheck_common::WordList;
+
+static ProfileKeyedService* BuildSpellcheckService(Profile* profile) {
+ return new SpellcheckService(profile);
+}
+
+class SpellcheckCustomDictionaryTest : public testing::Test {
+ protected:
+ SpellcheckCustomDictionaryTest()
+ : ui_thread_(BrowserThread::UI, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_),
+ profile_(new TestingProfile()) {
+ }
+
+ void SetUp() OVERRIDE {
+ // Use SetTestingFactoryAndUse to force creation and initialization.
+ SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile_.get(), &BuildSpellcheckService);
+ }
+
+ void TearDown() OVERRIDE {
+ MessageLoop::current()->RunUntilIdle();
+ }
+
+ MessageLoop message_loop_;
+ content::TestBrowserThread ui_thread_;
+ content::TestBrowserThread file_thread_;
+
+ scoped_ptr<TestingProfile> profile_;
+};
+
+// TODO(rlp/rouslan): Shift some of these to a cutsom dictionary test suite.
+TEST_F(SpellcheckCustomDictionaryTest, SpellcheckSetCustomWordList) {
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+
+ WordList loaded_custom_words;
+ loaded_custom_words.push_back("foo");
+ loaded_custom_words.push_back("bar");
+ WordList expected(loaded_custom_words);
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ custom_dictionary->SetCustomWordList(&loaded_custom_words);
+ EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
+}
+
+TEST_F(SpellcheckCustomDictionaryTest, CustomWordAddedLocally) {
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+
+ WordList loaded_custom_words;
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ custom_dictionary->Load();
+ WordList expected;
+ EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
+ custom_dictionary->CustomWordAddedLocally("foo");
+ expected.push_back("foo");
+ EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
+ custom_dictionary->CustomWordAddedLocally("bar");
+ expected.push_back("bar");
+ EXPECT_EQ(custom_dictionary->GetCustomWords(), expected);
+}
+
+TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) {
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+
+ WordList loaded_custom_words;
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+
+ // The custom word list should be empty now.
+ WordList expected;
+ EXPECT_EQ(loaded_custom_words, expected);
+
+ custom_dictionary->WriteWordToCustomDictionary("foo");
+ expected.push_back("foo");
+
+ custom_dictionary->WriteWordToCustomDictionary("bar");
+ expected.push_back("bar");
+
+ // The custom word list should include written words.
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&loaded_custom_words);
+ EXPECT_EQ(loaded_custom_words, expected);
+
+ // Load in another instance of SpellCheckService.
+ // The result should be the same.
+ SpellcheckService spellcheck_service2(profile_.get());
+ WordList loaded_custom_words2;
+ spellcheck_service2.GetCustomDictionary()->
+ LoadDictionaryIntoCustomWordList(&loaded_custom_words2);
+ EXPECT_EQ(loaded_custom_words2, expected);
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
+
+TEST_F(SpellcheckCustomDictionaryTest, MultiProfile) {
+ SpellcheckService* spellcheck_service =
+ SpellcheckServiceFactory::GetForProfile(profile_.get());
+ SpellcheckCustomDictionary* custom_dictionary =
+ spellcheck_service->GetCustomDictionary();
+ TestingProfile profile2;
+ SpellcheckService* spellcheck_service2 =
+ static_cast<SpellcheckService*>(
+ SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ &profile2, &BuildSpellcheckService));
+ SpellcheckCustomDictionary* custom_dictionary2 =
+ spellcheck_service2->GetCustomDictionary();
+
+ WordList expected1;
+ WordList expected2;
+
+ custom_dictionary->WriteWordToCustomDictionary("foo");
+ custom_dictionary->WriteWordToCustomDictionary("bar");
+ expected1.push_back("foo");
+ expected1.push_back("bar");
+
+ custom_dictionary2->WriteWordToCustomDictionary("hoge");
+ custom_dictionary2->WriteWordToCustomDictionary("fuga");
+ expected2.push_back("hoge");
+ expected2.push_back("fuga");
+
+ WordList actual1;
+ custom_dictionary->LoadDictionaryIntoCustomWordList(&actual1);
+ EXPECT_EQ(actual1, expected1);
+
+ WordList actual2;
+ custom_dictionary2->LoadDictionaryIntoCustomWordList(&actual2);
+ EXPECT_EQ(actual2, expected2);
+
+ // Flush the loop now to prevent service init tasks from being run during
+ // TearDown();
+ MessageLoop::current()->RunUntilIdle();
+}
« 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