Chromium Code Reviews| 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/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 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"}, | |
| 
 
Ilya Sherman
2014/08/27 00:42:03
Hmm, I'm pretty sure that non-ASCII characters are
 
Nikhil
2014/08/27 12:30:10
Done.
 
 | |
| 112 {"city", "&$%$$$ TESTO *&*&^&^& MOKO"}, | |
| 113 {"zip", "WOHOOOO$$$$$$$$****"} | |
| 114 }; | |
| 115 | |
| 97 class FirefoxObserver : public ProfileWriter, | 116 class FirefoxObserver : public ProfileWriter, | 
| 98 public importer::ImporterProgressObserver { | 117 public importer::ImporterProgressObserver { | 
| 99 public: | 118 public: | 
| 100 explicit FirefoxObserver(bool use_keyword_in_json) | 119 explicit FirefoxObserver(bool use_keyword_in_json) | 
| 101 : ProfileWriter(NULL), | 120 : ProfileWriter(NULL), | 
| 102 bookmark_count_(0), | 121 bookmark_count_(0), | 
| 103 history_count_(0), | 122 history_count_(0), | 
| 104 password_count_(0), | 123 password_count_(0), | 
| 105 keyword_count_(0), | 124 keyword_count_(0), | 
| 106 use_keyword_in_json_(use_keyword_in_json) {} | 125 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 | 179 // Importer should import the FF favorites the same as the list, in the same | 
| 161 // order. | 180 // order. | 
| 162 for (size_t i = 0; i < bookmarks.size(); ++i) { | 181 for (size_t i = 0; i < bookmarks.size(); ++i) { | 
| 163 EXPECT_NO_FATAL_FAILURE( | 182 EXPECT_NO_FATAL_FAILURE( | 
| 164 TestEqualBookmarkEntry(bookmarks[i], | 183 TestEqualBookmarkEntry(bookmarks[i], | 
| 165 kFirefoxBookmarks[bookmark_count_])) << i; | 184 kFirefoxBookmarks[bookmark_count_])) << i; | 
| 166 ++bookmark_count_; | 185 ++bookmark_count_; | 
| 167 } | 186 } | 
| 168 } | 187 } | 
| 169 | 188 | 
| 189 virtual void AddAutofillFormDataEntries( | |
| 190 const std::vector<autofill::AutofillEntry>& autofill_entries) OVERRIDE { | |
| 191 EXPECT_EQ(arraysize(kFirefoxAutofillEntries), autofill_entries.size()); | |
| 192 for (size_t i = 0; i < arraysize(kFirefoxAutofillEntries); ++i) { | |
| 193 EXPECT_EQ(kFirefoxAutofillEntries[i].name, | |
| 194 base::UTF16ToUTF8(autofill_entries[i].key().name())); | |
| 195 EXPECT_EQ(kFirefoxAutofillEntries[i].value, | |
| 196 base::UTF16ToUTF8(autofill_entries[i].key().value())); | |
| 197 } | |
| 198 } | |
| 199 | |
| 170 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 200 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 
| 171 bool unique_on_host_and_path) OVERRIDE { | 201 bool unique_on_host_and_path) OVERRIDE { | 
| 172 for (size_t i = 0; i < template_urls.size(); ++i) { | 202 for (size_t i = 0; i < template_urls.size(); ++i) { | 
| 173 // The order might not be deterministic, look in the expected list for | 203 // The order might not be deterministic, look in the expected list for | 
| 174 // that template URL. | 204 // that template URL. | 
| 175 bool found = false; | 205 bool found = false; | 
| 176 const base::string16& imported_keyword = template_urls[i]->keyword(); | 206 const base::string16& imported_keyword = template_urls[i]->keyword(); | 
| 177 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 207 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 
| 178 const base::string16 expected_keyword = base::WideToUTF16( | 208 const base::string16 expected_keyword = base::WideToUTF16( | 
| 179 use_keyword_in_json_ ? | 209 use_keyword_in_json_ ? | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 ASSERT_TRUE(base::CopyDirectory( | 294 ASSERT_TRUE(base::CopyDirectory( | 
| 265 custom_search_engine_source_path, custom_search_engine_path, false)); | 295 custom_search_engine_source_path, custom_search_engine_path, false)); | 
| 266 | 296 | 
| 267 importer::SourceProfile source_profile; | 297 importer::SourceProfile source_profile; | 
| 268 source_profile.importer_type = importer::TYPE_FIREFOX; | 298 source_profile.importer_type = importer::TYPE_FIREFOX; | 
| 269 source_profile.app_path = app_path_; | 299 source_profile.app_path = app_path_; | 
| 270 source_profile.source_path = profile_path_; | 300 source_profile.source_path = profile_path_; | 
| 271 source_profile.locale = "en-US"; | 301 source_profile.locale = "en-US"; | 
| 272 | 302 | 
| 273 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES | | 303 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES | | 
| 274 importer::SEARCH_ENGINES; | 304 importer::SEARCH_ENGINES | importer::AUTOFILL_FORM_DATA; | 
| 275 | 305 | 
| 276 // Deletes itself. | 306 // Deletes itself. | 
| 277 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; | 307 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; | 
| 278 host->set_observer(observer); | 308 host->set_observer(observer); | 
| 279 host->StartImportSettings( | 309 host->StartImportSettings( | 
| 280 source_profile, browser()->profile(), items, writer); | 310 source_profile, browser()->profile(), items, writer); | 
| 281 base::MessageLoop::current()->Run(); | 311 base::MessageLoop::current()->Run(); | 
| 282 } | 312 } | 
| 283 | 313 | 
| 284 base::ScopedTempDir temp_dir_; | 314 base::ScopedTempDir temp_dir_; | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 298 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); | 328 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); | 
| 299 FirefoxImporterBrowserTest( | 329 FirefoxImporterBrowserTest( | 
| 300 "firefox35_profile", observer.get(), observer.get()); | 330 "firefox35_profile", observer.get(), observer.get()); | 
| 301 } | 331 } | 
| 302 | 332 | 
| 303 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 333 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 
| 304 MAYBE_IMPORTER(FirefoxImporter)) { | 334 MAYBE_IMPORTER(FirefoxImporter)) { | 
| 305 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); | 335 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); | 
| 306 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 336 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 
| 307 } | 337 } | 
| OLD | NEW |