OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 public: | 120 public: |
121 explicit FirefoxObserver(bool use_keyword_in_json) | 121 explicit FirefoxObserver(bool use_keyword_in_json) |
122 : ProfileWriter(NULL), | 122 : ProfileWriter(NULL), |
123 bookmark_count_(0), | 123 bookmark_count_(0), |
124 history_count_(0), | 124 history_count_(0), |
125 password_count_(0), | 125 password_count_(0), |
126 keyword_count_(0), | 126 keyword_count_(0), |
127 use_keyword_in_json_(use_keyword_in_json) {} | 127 use_keyword_in_json_(use_keyword_in_json) {} |
128 | 128 |
129 // importer::ImporterProgressObserver: | 129 // importer::ImporterProgressObserver: |
130 virtual void ImportStarted() override {} | 130 void ImportStarted() override {} |
131 virtual void ImportItemStarted(importer::ImportItem item) override {} | 131 void ImportItemStarted(importer::ImportItem item) override {} |
132 virtual void ImportItemEnded(importer::ImportItem item) override {} | 132 void ImportItemEnded(importer::ImportItem item) override {} |
133 virtual void ImportEnded() override { | 133 void ImportEnded() override { |
134 base::MessageLoop::current()->Quit(); | 134 base::MessageLoop::current()->Quit(); |
135 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 135 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
136 EXPECT_EQ(1U, history_count_); | 136 EXPECT_EQ(1U, history_count_); |
137 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 137 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
138 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); | 138 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); |
139 } | 139 } |
140 | 140 |
141 virtual bool BookmarkModelIsLoaded() const override { | 141 bool BookmarkModelIsLoaded() const override { |
142 // Profile is ready for writing. | 142 // Profile is ready for writing. |
143 return true; | 143 return true; |
144 } | 144 } |
145 | 145 |
146 virtual bool TemplateURLServiceIsLoaded() const override { | 146 bool TemplateURLServiceIsLoaded() const override { return true; } |
147 return true; | |
148 } | |
149 | 147 |
150 virtual void AddPasswordForm(const autofill::PasswordForm& form) override { | 148 void AddPasswordForm(const autofill::PasswordForm& form) override { |
151 PasswordInfo p = kFirefoxPasswords[password_count_]; | 149 PasswordInfo p = kFirefoxPasswords[password_count_]; |
152 EXPECT_EQ(p.origin, form.origin.spec()); | 150 EXPECT_EQ(p.origin, form.origin.spec()); |
153 EXPECT_EQ(p.realm, form.signon_realm); | 151 EXPECT_EQ(p.realm, form.signon_realm); |
154 EXPECT_EQ(p.action, form.action.spec()); | 152 EXPECT_EQ(p.action, form.action.spec()); |
155 EXPECT_EQ(base::ASCIIToUTF16(p.username_element), form.username_element); | 153 EXPECT_EQ(base::ASCIIToUTF16(p.username_element), form.username_element); |
156 EXPECT_EQ(base::ASCIIToUTF16(p.username), form.username_value); | 154 EXPECT_EQ(base::ASCIIToUTF16(p.username), form.username_value); |
157 EXPECT_EQ(base::ASCIIToUTF16(p.password_element), form.password_element); | 155 EXPECT_EQ(base::ASCIIToUTF16(p.password_element), form.password_element); |
158 EXPECT_EQ(base::ASCIIToUTF16(p.password), form.password_value); | 156 EXPECT_EQ(base::ASCIIToUTF16(p.password), form.password_value); |
159 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); | 157 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); |
160 ++password_count_; | 158 ++password_count_; |
161 } | 159 } |
162 | 160 |
163 virtual void AddHistoryPage(const history::URLRows& page, | 161 void AddHistoryPage(const history::URLRows& page, |
164 history::VisitSource visit_source) override { | 162 history::VisitSource visit_source) override { |
165 ASSERT_EQ(3U, page.size()); | 163 ASSERT_EQ(3U, page.size()); |
166 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); | 164 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); |
167 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[0].title()); | 165 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[0].title()); |
168 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); | 166 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); |
169 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[1].title()); | 167 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[1].title()); |
170 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" | 168 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" |
171 "form1-POST.html", page[2].url().spec()); | 169 "form1-POST.html", page[2].url().spec()); |
172 EXPECT_EQ(base::ASCIIToUTF16("example form (POST)"), page[2].title()); | 170 EXPECT_EQ(base::ASCIIToUTF16("example form (POST)"), page[2].title()); |
173 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | 171 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); |
174 ++history_count_; | 172 ++history_count_; |
175 } | 173 } |
176 | 174 |
177 virtual void AddBookmarks( | 175 void AddBookmarks(const std::vector<ImportedBookmarkEntry>& bookmarks, |
178 const std::vector<ImportedBookmarkEntry>& bookmarks, | 176 const base::string16& top_level_folder_name) override { |
179 const base::string16& top_level_folder_name) override { | |
180 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kFirefoxBookmarks)); | 177 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kFirefoxBookmarks)); |
181 // Importer should import the FF favorites the same as the list, in the same | 178 // Importer should import the FF favorites the same as the list, in the same |
182 // order. | 179 // order. |
183 for (size_t i = 0; i < bookmarks.size(); ++i) { | 180 for (size_t i = 0; i < bookmarks.size(); ++i) { |
184 EXPECT_NO_FATAL_FAILURE( | 181 EXPECT_NO_FATAL_FAILURE( |
185 TestEqualBookmarkEntry(bookmarks[i], | 182 TestEqualBookmarkEntry(bookmarks[i], |
186 kFirefoxBookmarks[bookmark_count_])) << i; | 183 kFirefoxBookmarks[bookmark_count_])) << i; |
187 ++bookmark_count_; | 184 ++bookmark_count_; |
188 } | 185 } |
189 } | 186 } |
190 | 187 |
191 virtual void AddAutofillFormDataEntries( | 188 void AddAutofillFormDataEntries( |
192 const std::vector<autofill::AutofillEntry>& autofill_entries) override { | 189 const std::vector<autofill::AutofillEntry>& autofill_entries) override { |
193 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); | 190 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); |
194 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { | 191 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { |
195 EXPECT_EQ(kFirefoxAutofillEntries[i].name, | 192 EXPECT_EQ(kFirefoxAutofillEntries[i].name, |
196 base::UTF16ToUTF8(autofill_entries[i].key().name())); | 193 base::UTF16ToUTF8(autofill_entries[i].key().name())); |
197 EXPECT_EQ(kFirefoxAutofillEntries[i].value, | 194 EXPECT_EQ(kFirefoxAutofillEntries[i].value, |
198 base::UTF16ToUTF8(autofill_entries[i].key().value())); | 195 base::UTF16ToUTF8(autofill_entries[i].key().value())); |
199 } | 196 } |
200 } | 197 } |
201 | 198 |
202 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 199 void AddKeywords(ScopedVector<TemplateURL> template_urls, |
203 bool unique_on_host_and_path) override { | 200 bool unique_on_host_and_path) override { |
204 for (size_t i = 0; i < template_urls.size(); ++i) { | 201 for (size_t i = 0; i < template_urls.size(); ++i) { |
205 // The order might not be deterministic, look in the expected list for | 202 // The order might not be deterministic, look in the expected list for |
206 // that template URL. | 203 // that template URL. |
207 bool found = false; | 204 bool found = false; |
208 const base::string16& imported_keyword = template_urls[i]->keyword(); | 205 const base::string16& imported_keyword = template_urls[i]->keyword(); |
209 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 206 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
210 const base::string16 expected_keyword = base::WideToUTF16( | 207 const base::string16 expected_keyword = base::WideToUTF16( |
211 use_keyword_in_json_ ? | 208 use_keyword_in_json_ ? |
212 kFirefoxKeywords[j].keyword_in_json : | 209 kFirefoxKeywords[j].keyword_in_json : |
213 kFirefoxKeywords[j].keyword_in_sqlite); | 210 kFirefoxKeywords[j].keyword_in_sqlite); |
214 if (imported_keyword == expected_keyword) { | 211 if (imported_keyword == expected_keyword) { |
215 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | 212 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); |
216 found = true; | 213 found = true; |
217 break; | 214 break; |
218 } | 215 } |
219 } | 216 } |
220 EXPECT_TRUE(found); | 217 EXPECT_TRUE(found); |
221 ++keyword_count_; | 218 ++keyword_count_; |
222 } | 219 } |
223 } | 220 } |
224 | 221 |
225 virtual void AddFavicons( | 222 void AddFavicons(const std::vector<ImportedFaviconUsage>& favicons) override { |
226 const std::vector<ImportedFaviconUsage>& favicons) override { | |
227 } | 223 } |
228 | 224 |
229 private: | 225 private: |
230 virtual ~FirefoxObserver() {} | 226 ~FirefoxObserver() override {} |
231 | 227 |
232 size_t bookmark_count_; | 228 size_t bookmark_count_; |
233 size_t history_count_; | 229 size_t history_count_; |
234 size_t password_count_; | 230 size_t password_count_; |
235 size_t keyword_count_; | 231 size_t keyword_count_; |
236 | 232 |
237 // Newer versions of Firefox can store custom keyword names in json, which | 233 // Newer versions of Firefox can store custom keyword names in json, which |
238 // override the sqlite values. To be able to test both older and newer | 234 // override the sqlite values. To be able to test both older and newer |
239 // versions, tests set this variable to indicate whether to expect the | 235 // versions, tests set this variable to indicate whether to expect the |
240 // |keyword_in_sqlite| or |keyword_in_json| values from the reference data. | 236 // |keyword_in_sqlite| or |keyword_in_json| values from the reference data. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); | 326 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); |
331 FirefoxImporterBrowserTest( | 327 FirefoxImporterBrowserTest( |
332 "firefox35_profile", observer.get(), observer.get()); | 328 "firefox35_profile", observer.get(), observer.get()); |
333 } | 329 } |
334 | 330 |
335 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 331 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
336 MAYBE_IMPORTER(FirefoxImporter)) { | 332 MAYBE_IMPORTER(FirefoxImporter)) { |
337 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); | 333 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); |
338 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 334 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
339 } | 335 } |
OLD | NEW |