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" |
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 Loading... |
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 Loading... |
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 kFirefoxAutofillEntries[] = { |
| 104 {"name", "John"}, |
| 105 {"address", "#123 Cherry Ave"}, |
| 106 {"city", "Mountain View"}, |
| 107 {"zip", "94043"}, |
| 108 {"n300", "+1 (408) 871-4567"}, |
| 109 {"name", "john"}, |
| 110 {"name", "aguantó"}, |
| 111 {"address", "télévision@example.com"}, |
| 112 {"city", "&$%$$$ TESTO *&*&^&^& MOKO"}, |
| 113 {"zip", "WOHOOOO$$$$$$$$****"}, |
| 114 {"n300", "\xe0\xa4\x9f\xe2\x97\x8c\xe0\xa4\xbe\xe0\xa4\xaf\xe0\xa4\xb0"}, |
| 115 {"n300", "\xe4\xbb\xa5\xe7\x8e\xa9\xe4\xb8\xba\xe4\xb8\xbb"} |
| 116 }; |
| 117 |
97 class FirefoxObserver : public ProfileWriter, | 118 class FirefoxObserver : public ProfileWriter, |
98 public importer::ImporterProgressObserver { | 119 public importer::ImporterProgressObserver { |
99 public: | 120 public: |
100 explicit FirefoxObserver(bool use_keyword_in_json) | 121 explicit FirefoxObserver(bool use_keyword_in_json) |
101 : ProfileWriter(NULL), | 122 : ProfileWriter(NULL), |
102 bookmark_count_(0), | 123 bookmark_count_(0), |
103 history_count_(0), | 124 history_count_(0), |
104 password_count_(0), | 125 password_count_(0), |
105 keyword_count_(0), | 126 keyword_count_(0), |
106 use_keyword_in_json_(use_keyword_in_json) {} | 127 use_keyword_in_json_(use_keyword_in_json) {} |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // 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 |
161 // order. | 182 // order. |
162 for (size_t i = 0; i < bookmarks.size(); ++i) { | 183 for (size_t i = 0; i < bookmarks.size(); ++i) { |
163 EXPECT_NO_FATAL_FAILURE( | 184 EXPECT_NO_FATAL_FAILURE( |
164 TestEqualBookmarkEntry(bookmarks[i], | 185 TestEqualBookmarkEntry(bookmarks[i], |
165 kFirefoxBookmarks[bookmark_count_])) << i; | 186 kFirefoxBookmarks[bookmark_count_])) << i; |
166 ++bookmark_count_; | 187 ++bookmark_count_; |
167 } | 188 } |
168 } | 189 } |
169 | 190 |
| 191 virtual void AddAutofillFormDataEntries( |
| 192 const std::vector<autofill::AutofillEntry>& autofill_entries) OVERRIDE { |
| 193 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); |
| 194 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { |
| 195 EXPECT_EQ(kFirefoxAutofillEntries[i].name, |
| 196 base::UTF16ToUTF8(autofill_entries[i].key().name())); |
| 197 EXPECT_EQ(kFirefoxAutofillEntries[i].value, |
| 198 base::UTF16ToUTF8(autofill_entries[i].key().value())); |
| 199 } |
| 200 } |
| 201 |
170 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 202 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
171 bool unique_on_host_and_path) OVERRIDE { | 203 bool unique_on_host_and_path) OVERRIDE { |
172 for (size_t i = 0; i < template_urls.size(); ++i) { | 204 for (size_t i = 0; i < template_urls.size(); ++i) { |
173 // 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 |
174 // that template URL. | 206 // that template URL. |
175 bool found = false; | 207 bool found = false; |
176 const base::string16& imported_keyword = template_urls[i]->keyword(); | 208 const base::string16& imported_keyword = template_urls[i]->keyword(); |
177 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 209 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
178 const base::string16 expected_keyword = base::WideToUTF16( | 210 const base::string16 expected_keyword = base::WideToUTF16( |
179 use_keyword_in_json_ ? | 211 use_keyword_in_json_ ? |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 ASSERT_TRUE(base::CopyDirectory( | 296 ASSERT_TRUE(base::CopyDirectory( |
265 custom_search_engine_source_path, custom_search_engine_path, false)); | 297 custom_search_engine_source_path, custom_search_engine_path, false)); |
266 | 298 |
267 importer::SourceProfile source_profile; | 299 importer::SourceProfile source_profile; |
268 source_profile.importer_type = importer::TYPE_FIREFOX; | 300 source_profile.importer_type = importer::TYPE_FIREFOX; |
269 source_profile.app_path = app_path_; | 301 source_profile.app_path = app_path_; |
270 source_profile.source_path = profile_path_; | 302 source_profile.source_path = profile_path_; |
271 source_profile.locale = "en-US"; | 303 source_profile.locale = "en-US"; |
272 | 304 |
273 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES | | 305 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES | |
274 importer::SEARCH_ENGINES; | 306 importer::SEARCH_ENGINES | importer::AUTOFILL_FORM_DATA; |
275 | 307 |
276 // Deletes itself. | 308 // Deletes itself. |
277 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; | 309 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; |
278 host->set_observer(observer); | 310 host->set_observer(observer); |
279 host->StartImportSettings( | 311 host->StartImportSettings( |
280 source_profile, browser()->profile(), items, writer); | 312 source_profile, browser()->profile(), items, writer); |
281 base::MessageLoop::current()->Run(); | 313 base::MessageLoop::current()->Run(); |
282 } | 314 } |
283 | 315 |
284 base::ScopedTempDir temp_dir_; | 316 base::ScopedTempDir temp_dir_; |
(...skipping 13 matching lines...) Expand all Loading... |
298 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); | 330 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); |
299 FirefoxImporterBrowserTest( | 331 FirefoxImporterBrowserTest( |
300 "firefox35_profile", observer.get(), observer.get()); | 332 "firefox35_profile", observer.get(), observer.get()); |
301 } | 333 } |
302 | 334 |
303 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 335 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
304 MAYBE_IMPORTER(FirefoxImporter)) { | 336 MAYBE_IMPORTER(FirefoxImporter)) { |
305 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); | 337 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); |
306 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 338 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
307 } | 339 } |
OLD | NEW |