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 virtual void ImportStarted() override {} |
131 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 131 virtual void ImportItemStarted(importer::ImportItem item) override {} |
132 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 132 virtual void ImportItemEnded(importer::ImportItem item) override {} |
133 virtual void ImportEnded() OVERRIDE { | 133 virtual 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 virtual 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 virtual bool TemplateURLServiceIsLoaded() const override { |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 virtual void AddPasswordForm(const autofill::PasswordForm& form) OVERRIDE { | 150 virtual void AddPasswordForm(const autofill::PasswordForm& form) override { |
151 PasswordInfo p = kFirefoxPasswords[password_count_]; | 151 PasswordInfo p = kFirefoxPasswords[password_count_]; |
152 EXPECT_EQ(p.origin, form.origin.spec()); | 152 EXPECT_EQ(p.origin, form.origin.spec()); |
153 EXPECT_EQ(p.realm, form.signon_realm); | 153 EXPECT_EQ(p.realm, form.signon_realm); |
154 EXPECT_EQ(p.action, form.action.spec()); | 154 EXPECT_EQ(p.action, form.action.spec()); |
155 EXPECT_EQ(base::ASCIIToUTF16(p.username_element), form.username_element); | 155 EXPECT_EQ(base::ASCIIToUTF16(p.username_element), form.username_element); |
156 EXPECT_EQ(base::ASCIIToUTF16(p.username), form.username_value); | 156 EXPECT_EQ(base::ASCIIToUTF16(p.username), form.username_value); |
157 EXPECT_EQ(base::ASCIIToUTF16(p.password_element), form.password_element); | 157 EXPECT_EQ(base::ASCIIToUTF16(p.password_element), form.password_element); |
158 EXPECT_EQ(base::ASCIIToUTF16(p.password), form.password_value); | 158 EXPECT_EQ(base::ASCIIToUTF16(p.password), form.password_value); |
159 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); | 159 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); |
160 ++password_count_; | 160 ++password_count_; |
161 } | 161 } |
162 | 162 |
163 virtual void AddHistoryPage(const history::URLRows& page, | 163 virtual void AddHistoryPage(const history::URLRows& page, |
164 history::VisitSource visit_source) OVERRIDE { | 164 history::VisitSource visit_source) override { |
165 ASSERT_EQ(3U, page.size()); | 165 ASSERT_EQ(3U, page.size()); |
166 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); | 166 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); |
167 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[0].title()); | 167 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[0].title()); |
168 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); | 168 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); |
169 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[1].title()); | 169 EXPECT_EQ(base::ASCIIToUTF16("Google"), page[1].title()); |
170 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" | 170 EXPECT_EQ("http://www.cs.unc.edu/~jbs/resources/perl/perl-cgi/programs/" |
171 "form1-POST.html", page[2].url().spec()); | 171 "form1-POST.html", page[2].url().spec()); |
172 EXPECT_EQ(base::ASCIIToUTF16("example form (POST)"), page[2].title()); | 172 EXPECT_EQ(base::ASCIIToUTF16("example form (POST)"), page[2].title()); |
173 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); | 173 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); |
174 ++history_count_; | 174 ++history_count_; |
175 } | 175 } |
176 | 176 |
177 virtual void AddBookmarks( | 177 virtual void AddBookmarks( |
178 const std::vector<ImportedBookmarkEntry>& bookmarks, | 178 const std::vector<ImportedBookmarkEntry>& bookmarks, |
179 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)); | 180 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kFirefoxBookmarks)); |
181 // Importer should import the FF favorites the same as the list, in the same | 181 // Importer should import the FF favorites the same as the list, in the same |
182 // order. | 182 // order. |
183 for (size_t i = 0; i < bookmarks.size(); ++i) { | 183 for (size_t i = 0; i < bookmarks.size(); ++i) { |
184 EXPECT_NO_FATAL_FAILURE( | 184 EXPECT_NO_FATAL_FAILURE( |
185 TestEqualBookmarkEntry(bookmarks[i], | 185 TestEqualBookmarkEntry(bookmarks[i], |
186 kFirefoxBookmarks[bookmark_count_])) << i; | 186 kFirefoxBookmarks[bookmark_count_])) << i; |
187 ++bookmark_count_; | 187 ++bookmark_count_; |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 virtual void AddAutofillFormDataEntries( | 191 virtual void AddAutofillFormDataEntries( |
192 const std::vector<autofill::AutofillEntry>& autofill_entries) OVERRIDE { | 192 const std::vector<autofill::AutofillEntry>& autofill_entries) override { |
193 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); | 193 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); |
194 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { | 194 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { |
195 EXPECT_EQ(kFirefoxAutofillEntries[i].name, | 195 EXPECT_EQ(kFirefoxAutofillEntries[i].name, |
196 base::UTF16ToUTF8(autofill_entries[i].key().name())); | 196 base::UTF16ToUTF8(autofill_entries[i].key().name())); |
197 EXPECT_EQ(kFirefoxAutofillEntries[i].value, | 197 EXPECT_EQ(kFirefoxAutofillEntries[i].value, |
198 base::UTF16ToUTF8(autofill_entries[i].key().value())); | 198 base::UTF16ToUTF8(autofill_entries[i].key().value())); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 202 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
203 bool unique_on_host_and_path) OVERRIDE { | 203 bool unique_on_host_and_path) override { |
204 for (size_t i = 0; i < template_urls.size(); ++i) { | 204 for (size_t i = 0; i < template_urls.size(); ++i) { |
205 // The order might not be deterministic, look in the expected list for | 205 // The order might not be deterministic, look in the expected list for |
206 // that template URL. | 206 // that template URL. |
207 bool found = false; | 207 bool found = false; |
208 const base::string16& imported_keyword = template_urls[i]->keyword(); | 208 const base::string16& imported_keyword = template_urls[i]->keyword(); |
209 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 209 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
210 const base::string16 expected_keyword = base::WideToUTF16( | 210 const base::string16 expected_keyword = base::WideToUTF16( |
211 use_keyword_in_json_ ? | 211 use_keyword_in_json_ ? |
212 kFirefoxKeywords[j].keyword_in_json : | 212 kFirefoxKeywords[j].keyword_in_json : |
213 kFirefoxKeywords[j].keyword_in_sqlite); | 213 kFirefoxKeywords[j].keyword_in_sqlite); |
214 if (imported_keyword == expected_keyword) { | 214 if (imported_keyword == expected_keyword) { |
215 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | 215 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); |
216 found = true; | 216 found = true; |
217 break; | 217 break; |
218 } | 218 } |
219 } | 219 } |
220 EXPECT_TRUE(found); | 220 EXPECT_TRUE(found); |
221 ++keyword_count_; | 221 ++keyword_count_; |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 virtual void AddFavicons( | 225 virtual void AddFavicons( |
226 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 226 const std::vector<ImportedFaviconUsage>& favicons) override { |
227 } | 227 } |
228 | 228 |
229 private: | 229 private: |
230 virtual ~FirefoxObserver() {} | 230 virtual ~FirefoxObserver() {} |
231 | 231 |
232 size_t bookmark_count_; | 232 size_t bookmark_count_; |
233 size_t history_count_; | 233 size_t history_count_; |
234 size_t password_count_; | 234 size_t password_count_; |
235 size_t keyword_count_; | 235 size_t keyword_count_; |
236 | 236 |
237 // Newer versions of Firefox can store custom keyword names in json, which | 237 // 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 | 238 // 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 | 239 // versions, tests set this variable to indicate whether to expect the |
240 // |keyword_in_sqlite| or |keyword_in_json| values from the reference data. | 240 // |keyword_in_sqlite| or |keyword_in_json| values from the reference data. |
241 bool use_keyword_in_json_; | 241 bool use_keyword_in_json_; |
242 }; | 242 }; |
243 | 243 |
244 } // namespace | 244 } // namespace |
245 | 245 |
246 // These tests need to be browser tests in order to be able to run the OOP | 246 // These tests need to be browser tests in order to be able to run the OOP |
247 // import (via ExternalProcessImporterHost) which launches a utility process on | 247 // import (via ExternalProcessImporterHost) which launches a utility process on |
248 // supported platforms. | 248 // supported platforms. |
249 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 249 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
250 protected: | 250 protected: |
251 virtual void SetUp() OVERRIDE { | 251 virtual void SetUp() override { |
252 // Creates a new profile in a new subdirectory in the temp directory. | 252 // Creates a new profile in a new subdirectory in the temp directory. |
253 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 253 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
254 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | 254 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
255 base::DeleteFile(test_path, true); | 255 base::DeleteFile(test_path, true); |
256 base::CreateDirectory(test_path); | 256 base::CreateDirectory(test_path); |
257 profile_path_ = test_path.AppendASCII("profile"); | 257 profile_path_ = test_path.AppendASCII("profile"); |
258 app_path_ = test_path.AppendASCII("app"); | 258 app_path_ = test_path.AppendASCII("app"); |
259 base::CreateDirectory(app_path_); | 259 base::CreateDirectory(app_path_); |
260 | 260 |
261 // This will launch the browser test and thus needs to happen last. | 261 // This will launch the browser test and thus needs to happen last. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); | 330 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); |
331 FirefoxImporterBrowserTest( | 331 FirefoxImporterBrowserTest( |
332 "firefox35_profile", observer.get(), observer.get()); | 332 "firefox35_profile", observer.get(), observer.get()); |
333 } | 333 } |
334 | 334 |
335 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 335 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
336 MAYBE_IMPORTER(FirefoxImporter)) { | 336 MAYBE_IMPORTER(FirefoxImporter)) { |
337 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); | 337 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); |
338 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 338 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
339 } | 339 } |
OLD | NEW |