OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 static KeyedService* BuildSpellcheckService(content::BrowserContext* profile) { | 60 static KeyedService* BuildSpellcheckService(content::BrowserContext* profile) { |
61 return new SpellcheckService(static_cast<Profile*>(profile)); | 61 return new SpellcheckService(static_cast<Profile*>(profile)); |
62 } | 62 } |
63 | 63 |
64 class SpellcheckCustomDictionaryTest : public testing::Test { | 64 class SpellcheckCustomDictionaryTest : public testing::Test { |
65 protected: | 65 protected: |
66 virtual void SetUp() OVERRIDE { | 66 virtual void SetUp() override { |
67 // Use SetTestingFactoryAndUse to force creation and initialization. | 67 // Use SetTestingFactoryAndUse to force creation and initialization. |
68 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 68 SpellcheckServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
69 &profile_, &BuildSpellcheckService); | 69 &profile_, &BuildSpellcheckService); |
70 | 70 |
71 StatisticsRecorder::Initialize(); | 71 StatisticsRecorder::Initialize(); |
72 } | 72 } |
73 | 73 |
74 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private | 74 // A wrapper around SpellcheckCustomDictionary::LoadDictionaryFile private |
75 // function to avoid a large number of FRIEND_TEST declarations in | 75 // function to avoid a large number of FRIEND_TEST declarations in |
76 // SpellcheckCustomDictionary. | 76 // SpellcheckCustomDictionary. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // messages in an instance of this class after that instance is deleted. | 116 // messages in an instance of this class after that instance is deleted. |
117 class SyncErrorFactoryStub : public syncer::SyncErrorFactory { | 117 class SyncErrorFactoryStub : public syncer::SyncErrorFactory { |
118 public: | 118 public: |
119 explicit SyncErrorFactoryStub(int* error_counter) | 119 explicit SyncErrorFactoryStub(int* error_counter) |
120 : error_counter_(error_counter) {} | 120 : error_counter_(error_counter) {} |
121 virtual ~SyncErrorFactoryStub() {} | 121 virtual ~SyncErrorFactoryStub() {} |
122 | 122 |
123 // Overridden from syncer::SyncErrorFactory: | 123 // Overridden from syncer::SyncErrorFactory: |
124 virtual syncer::SyncError CreateAndUploadError( | 124 virtual syncer::SyncError CreateAndUploadError( |
125 const tracked_objects::Location& location, | 125 const tracked_objects::Location& location, |
126 const std::string& message) OVERRIDE { | 126 const std::string& message) override { |
127 (*error_counter_)++; | 127 (*error_counter_)++; |
128 return syncer::SyncError(location, | 128 return syncer::SyncError(location, |
129 syncer::SyncError::DATATYPE_ERROR, | 129 syncer::SyncError::DATATYPE_ERROR, |
130 message, | 130 message, |
131 syncer::DICTIONARY); | 131 syncer::DICTIONARY); |
132 } | 132 } |
133 | 133 |
134 private: | 134 private: |
135 int* error_counter_; | 135 int* error_counter_; |
136 DISALLOW_COPY_AND_ASSIGN(SyncErrorFactoryStub); | 136 DISALLOW_COPY_AND_ASSIGN(SyncErrorFactoryStub); |
137 }; | 137 }; |
138 | 138 |
139 // Counts the number of notifications for dictionary load and change. | 139 // Counts the number of notifications for dictionary load and change. |
140 class DictionaryObserverCounter : public SpellcheckCustomDictionary::Observer { | 140 class DictionaryObserverCounter : public SpellcheckCustomDictionary::Observer { |
141 public: | 141 public: |
142 DictionaryObserverCounter() : loads_(0), changes_(0) {} | 142 DictionaryObserverCounter() : loads_(0), changes_(0) {} |
143 virtual ~DictionaryObserverCounter() {} | 143 virtual ~DictionaryObserverCounter() {} |
144 | 144 |
145 int loads() const { return loads_; } | 145 int loads() const { return loads_; } |
146 int changes() const { return changes_; } | 146 int changes() const { return changes_; } |
147 | 147 |
148 // Overridden from SpellcheckCustomDictionary::Observer: | 148 // Overridden from SpellcheckCustomDictionary::Observer: |
149 virtual void OnCustomDictionaryLoaded() OVERRIDE { loads_++; } | 149 virtual void OnCustomDictionaryLoaded() override { loads_++; } |
150 virtual void OnCustomDictionaryChanged( | 150 virtual void OnCustomDictionaryChanged( |
151 const SpellcheckCustomDictionary::Change& change) OVERRIDE { changes_++; } | 151 const SpellcheckCustomDictionary::Change& change) override { changes_++; } |
152 | 152 |
153 private: | 153 private: |
154 int loads_; | 154 int loads_; |
155 int changes_; | 155 int changes_; |
156 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); | 156 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); |
157 }; | 157 }; |
158 | 158 |
159 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { | 159 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { |
160 base::FilePath path = | 160 base::FilePath path = |
161 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); | 161 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 SpellcheckServiceFactory::GetForContext(&profile_); | 1167 SpellcheckServiceFactory::GetForContext(&profile_); |
1168 SpellcheckCustomDictionary* custom_dictionary = | 1168 SpellcheckCustomDictionary* custom_dictionary = |
1169 spellcheck_service->GetCustomDictionary(); | 1169 spellcheck_service->GetCustomDictionary(); |
1170 OnLoaded(*custom_dictionary, WordList()); | 1170 OnLoaded(*custom_dictionary, WordList()); |
1171 EXPECT_FALSE(custom_dictionary->HasWord("foo")); | 1171 EXPECT_FALSE(custom_dictionary->HasWord("foo")); |
1172 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1172 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1173 custom_dictionary->AddWord("foo"); | 1173 custom_dictionary->AddWord("foo"); |
1174 EXPECT_TRUE(custom_dictionary->HasWord("foo")); | 1174 EXPECT_TRUE(custom_dictionary->HasWord("foo")); |
1175 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1175 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1176 } | 1176 } |
OLD | NEW |