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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 net::TestURLFetcherFactory fetcher_factory_; | 111 net::TestURLFetcherFactory fetcher_factory_; |
112 }; | 112 }; |
113 | 113 |
114 // An implementation of SyncErrorFactory that does not upload the error message | 114 // An implementation of SyncErrorFactory that does not upload the error message |
115 // and updates an outside error counter. This lets us know the number of error | 115 // and updates an outside error counter. This lets us know the number of error |
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 ~SyncErrorFactoryStub() override {} |
122 | 122 |
123 // Overridden from syncer::SyncErrorFactory: | 123 // Overridden from syncer::SyncErrorFactory: |
124 virtual syncer::SyncError CreateAndUploadError( | 124 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 void OnCustomDictionaryLoaded() override { loads_++; } |
150 virtual void OnCustomDictionaryChanged( | 150 void OnCustomDictionaryChanged( |
151 const SpellcheckCustomDictionary::Change& change) override { changes_++; } | 151 const SpellcheckCustomDictionary::Change& change) override { |
| 152 changes_++; |
| 153 } |
152 | 154 |
153 private: | 155 private: |
154 int loads_; | 156 int loads_; |
155 int changes_; | 157 int changes_; |
156 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); | 158 DISALLOW_COPY_AND_ASSIGN(DictionaryObserverCounter); |
157 }; | 159 }; |
158 | 160 |
159 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { | 161 TEST_F(SpellcheckCustomDictionaryTest, SaveAndLoad) { |
160 base::FilePath path = | 162 base::FilePath path = |
161 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); | 163 profile_.GetPath().Append(chrome::kCustomDictionaryFileName); |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 SpellcheckServiceFactory::GetForContext(&profile_); | 1169 SpellcheckServiceFactory::GetForContext(&profile_); |
1168 SpellcheckCustomDictionary* custom_dictionary = | 1170 SpellcheckCustomDictionary* custom_dictionary = |
1169 spellcheck_service->GetCustomDictionary(); | 1171 spellcheck_service->GetCustomDictionary(); |
1170 OnLoaded(*custom_dictionary, WordList()); | 1172 OnLoaded(*custom_dictionary, WordList()); |
1171 EXPECT_FALSE(custom_dictionary->HasWord("foo")); | 1173 EXPECT_FALSE(custom_dictionary->HasWord("foo")); |
1172 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1174 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1173 custom_dictionary->AddWord("foo"); | 1175 custom_dictionary->AddWord("foo"); |
1174 EXPECT_TRUE(custom_dictionary->HasWord("foo")); | 1176 EXPECT_TRUE(custom_dictionary->HasWord("foo")); |
1175 EXPECT_FALSE(custom_dictionary->HasWord("bar")); | 1177 EXPECT_FALSE(custom_dictionary->HasWord("bar")); |
1176 } | 1178 } |
OLD | NEW |