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

Side by Side Diff: chrome/browser/importer/firefox_importer_browsertest.cc

Issue 480953002: Implement "Autofill form data" import for Firefox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test case Created 6 years, 4 months 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 unified diff | Download patch
OLDNEW
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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.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"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/importer/external_process_importer_host.h" 14 #include "chrome/browser/importer/external_process_importer_host.h"
15 #include "chrome/browser/importer/importer_progress_observer.h" 15 #include "chrome/browser/importer/importer_progress_observer.h"
16 #include "chrome/browser/importer/importer_unittest_utils.h" 16 #include "chrome/browser/importer/importer_unittest_utils.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/importer/imported_bookmark_entry.h" 19 #include "chrome/common/importer/imported_bookmark_entry.h"
20 #include "chrome/common/importer/imported_favicon_usage.h" 20 #include "chrome/common/importer/imported_favicon_usage.h"
21 #include "chrome/common/importer/importer_data_types.h" 21 #include "chrome/common/importer/importer_data_types.h"
22 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
23 #include "components/autofill/core/browser/webdata/autofill_entry.h"
23 #include "components/autofill/core/common/password_form.h" 24 #include "components/autofill/core/common/password_form.h"
24 #include "components/search_engines/template_url.h" 25 #include "components/search_engines/template_url.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 // TODO(estade): some of these are disabled on mac. http://crbug.com/48007 28 // TODO(estade): some of these are disabled on mac. http://crbug.com/48007
28 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 29 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688
29 #if defined(OS_MACOSX) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64)) 30 #if defined(OS_MACOSX) || (defined(OS_WIN) && defined(ARCH_CPU_X86_64))
30 #define MAYBE_IMPORTER(x) DISABLED_##x 31 #define MAYBE_IMPORTER(x) DISABLED_##x
31 #else 32 #else
32 #define MAYBE_IMPORTER(x) x 33 #define MAYBE_IMPORTER(x) x
(...skipping 11 matching lines...) Expand all
44 const char* password; 45 const char* password;
45 bool blacklisted; 46 bool blacklisted;
46 }; 47 };
47 48
48 struct KeywordInfo { 49 struct KeywordInfo {
49 const wchar_t* keyword_in_sqlite; 50 const wchar_t* keyword_in_sqlite;
50 const wchar_t* keyword_in_json; 51 const wchar_t* keyword_in_json;
51 const char* url; 52 const char* url;
52 }; 53 };
53 54
55 struct AutofillFormDataInfo {
56 const char* name;
57 const char* value;
58 };
59
54 const BookmarkInfo kFirefoxBookmarks[] = { 60 const BookmarkInfo kFirefoxBookmarks[] = {
55 {true, 1, {"Bookmarks Toolbar"}, 61 {true, 1, {"Bookmarks Toolbar"},
56 L"Toolbar", 62 L"Toolbar",
57 "http://site/"}, 63 "http://site/"},
58 {false, 0, {}, 64 {false, 0, {},
59 L"Title", 65 L"Title",
60 "http://www.google.com/"}, 66 "http://www.google.com/"},
61 }; 67 };
62 68
63 const PasswordInfo kFirefoxPasswords[] = { 69 const PasswordInfo kFirefoxPasswords[] = {
(...skipping 23 matching lines...) Expand all
87 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"}, 93 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"},
88 {L"flickr.com", L"flickr.com", 94 {L"flickr.com", L"flickr.com",
89 "http://www.flickr.com/photos/tags/?q={searchTerms}"}, 95 "http://www.flickr.com/photos/tags/?q={searchTerms}"},
90 {L"imdb.com", L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"}, 96 {L"imdb.com", L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"},
91 {L"webster.com", L"webster.com", 97 {L"webster.com", L"webster.com",
92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"}, 98 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"},
93 // Search keywords. 99 // Search keywords.
94 {L"\x4E2D\x6587", L"\x4E2D\x6587", "http://www.google.com/"}, 100 {L"\x4E2D\x6587", L"\x4E2D\x6587", "http://www.google.com/"},
95 }; 101 };
96 102
103 const AutofillFormDataInfo kFirefoxAutofill[] = {
Ilya Sherman 2014/08/20 05:47:41 nit: "kFirefoxAutofillEntries"
Nikhil 2014/08/20 11:29:16 Done.
104 {"name", "user_one"},
105 {"n300", "user_two"},
Ilya Sherman 2014/08/20 05:47:41 Please include additional cases: case sensitivity,
Nikhil 2014/08/20 11:29:16 I'm going to add these in next revision of this CL
106 };
107
97 class FirefoxObserver : public ProfileWriter, 108 class FirefoxObserver : public ProfileWriter,
98 public importer::ImporterProgressObserver { 109 public importer::ImporterProgressObserver {
99 public: 110 public:
100 explicit FirefoxObserver(bool use_keyword_in_json) 111 explicit FirefoxObserver(bool use_keyword_in_json)
101 : ProfileWriter(NULL), 112 : ProfileWriter(NULL),
102 bookmark_count_(0), 113 bookmark_count_(0),
103 history_count_(0), 114 history_count_(0),
104 password_count_(0), 115 password_count_(0),
105 keyword_count_(0), 116 keyword_count_(0),
106 use_keyword_in_json_(use_keyword_in_json) {} 117 use_keyword_in_json_(use_keyword_in_json) {}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Importer should import the FF favorites the same as the list, in the same 171 // Importer should import the FF favorites the same as the list, in the same
161 // order. 172 // order.
162 for (size_t i = 0; i < bookmarks.size(); ++i) { 173 for (size_t i = 0; i < bookmarks.size(); ++i) {
163 EXPECT_NO_FATAL_FAILURE( 174 EXPECT_NO_FATAL_FAILURE(
164 TestEqualBookmarkEntry(bookmarks[i], 175 TestEqualBookmarkEntry(bookmarks[i],
165 kFirefoxBookmarks[bookmark_count_])) << i; 176 kFirefoxBookmarks[bookmark_count_])) << i;
166 ++bookmark_count_; 177 ++bookmark_count_;
167 } 178 }
168 } 179 }
169 180
181 virtual void AddAutofillFormDataEntries(
182 const std::vector<autofill::AutofillEntry>& autofill_entries) OVERRIDE {
183 EXPECT_EQ(arraysize(kFirefoxAutofill), autofill_entries.size());
184 for (size_t i = 0; i < arraysize(kFirefoxAutofill); ++i) {
185 EXPECT_EQ(kFirefoxAutofill[i].name,
186 base::UTF16ToUTF8(autofill_entries[i].key().name()));
187 EXPECT_EQ(kFirefoxAutofill[i].value,
188 base::UTF16ToUTF8(autofill_entries[i].key().value()));
189 }
190 }
191
170 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, 192 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls,
171 bool unique_on_host_and_path) OVERRIDE { 193 bool unique_on_host_and_path) OVERRIDE {
172 for (size_t i = 0; i < template_urls.size(); ++i) { 194 for (size_t i = 0; i < template_urls.size(); ++i) {
173 // The order might not be deterministic, look in the expected list for 195 // The order might not be deterministic, look in the expected list for
174 // that template URL. 196 // that template URL.
175 bool found = false; 197 bool found = false;
176 const base::string16& imported_keyword = template_urls[i]->keyword(); 198 const base::string16& imported_keyword = template_urls[i]->keyword();
177 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { 199 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) {
178 const base::string16 expected_keyword = base::WideToUTF16( 200 const base::string16 expected_keyword = base::WideToUTF16(
179 use_keyword_in_json_ ? 201 use_keyword_in_json_ ?
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ASSERT_TRUE(base::CopyDirectory( 286 ASSERT_TRUE(base::CopyDirectory(
265 custom_search_engine_source_path, custom_search_engine_path, false)); 287 custom_search_engine_source_path, custom_search_engine_path, false));
266 288
267 importer::SourceProfile source_profile; 289 importer::SourceProfile source_profile;
268 source_profile.importer_type = importer::TYPE_FIREFOX; 290 source_profile.importer_type = importer::TYPE_FIREFOX;
269 source_profile.app_path = app_path_; 291 source_profile.app_path = app_path_;
270 source_profile.source_path = profile_path_; 292 source_profile.source_path = profile_path_;
271 source_profile.locale = "en-US"; 293 source_profile.locale = "en-US";
272 294
273 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES | 295 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES |
274 importer::SEARCH_ENGINES; 296 importer::SEARCH_ENGINES | importer::AUTOFILL_FORM_DATA;
275 297
276 // Deletes itself. 298 // Deletes itself.
277 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; 299 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
278 host->set_observer(observer); 300 host->set_observer(observer);
279 host->StartImportSettings( 301 host->StartImportSettings(
280 source_profile, browser()->profile(), items, writer); 302 source_profile, browser()->profile(), items, writer);
281 base::MessageLoop::current()->Run(); 303 base::MessageLoop::current()->Run();
282 } 304 }
283 305
284 base::ScopedTempDir temp_dir_; 306 base::ScopedTempDir temp_dir_;
(...skipping 13 matching lines...) Expand all
298 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); 320 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false));
299 FirefoxImporterBrowserTest( 321 FirefoxImporterBrowserTest(
300 "firefox35_profile", observer.get(), observer.get()); 322 "firefox35_profile", observer.get(), observer.get());
301 } 323 }
302 324
303 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, 325 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest,
304 MAYBE_IMPORTER(FirefoxImporter)) { 326 MAYBE_IMPORTER(FirefoxImporter)) {
305 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); 327 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true));
306 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); 328 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get());
307 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698