| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const char* action; | 39 const char* action; |
| 40 const char* realm; | 40 const char* realm; |
| 41 const char* username_element; | 41 const char* username_element; |
| 42 const char* username; | 42 const char* username; |
| 43 const char* password_element; | 43 const char* password_element; |
| 44 const char* password; | 44 const char* password; |
| 45 bool blacklisted; | 45 bool blacklisted; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 struct KeywordInfo { | 48 struct KeywordInfo { |
| 49 const wchar_t* keyword; | 49 const wchar_t* keyword_in_sqlite; |
| 50 const wchar_t* keyword_in_json; |
| 50 const char* url; | 51 const char* url; |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 const BookmarkInfo kFirefoxBookmarks[] = { | 54 const BookmarkInfo kFirefoxBookmarks[] = { |
| 54 {true, 1, {"Bookmarks Toolbar"}, | 55 {true, 1, {"Bookmarks Toolbar"}, |
| 55 L"Toolbar", | 56 L"Toolbar", |
| 56 "http://site/"}, | 57 "http://site/"}, |
| 57 {false, 0, {}, | 58 {false, 0, {}, |
| 58 L"Title", | 59 L"Title", |
| 59 "http://www.google.com/"}, | 60 "http://www.google.com/"}, |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 const PasswordInfo kFirefoxPasswords[] = { | 63 const PasswordInfo kFirefoxPasswords[] = { |
| 63 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | 64 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", |
| 64 "loginuser", "abc", "loginpass", "123", false}, | 65 "loginuser", "abc", "loginpass", "123", false}, |
| 65 {"http://localhost:8080/", "", "http://localhost:8080/localhost", | 66 {"http://localhost:8080/", "", "http://localhost:8080/localhost", |
| 66 "", "http", "", "Http1+1abcdefg", false}, | 67 "", "http", "", "Http1+1abcdefg", false}, |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 const KeywordInfo kFirefoxKeywords[] = { | 70 const KeywordInfo kFirefoxKeywords[] = { |
| 70 { L"amazon.com", | 71 {L"amazon.com", L"amazon.com", |
| 71 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | 72 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" |
| 72 "{searchTerms}&mode=blended" }, | 73 "{searchTerms}&mode=blended"}, |
| 73 { L"answers.com", | 74 {L"answers.com", L"answers.com", |
| 74 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | 75 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13"}, |
| 75 { L"search.creativecommons.org", | 76 {L"search.creativecommons.org", L"search.creativecommons.org", |
| 76 "http://search.creativecommons.org/?q={searchTerms}" }, | 77 "http://search.creativecommons.org/?q={searchTerms}"}, |
| 77 { L"search.ebay.com", | 78 {L"search.ebay.com", L"search.ebay.com", |
| 78 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | 79 "http://search.ebay.com/search/search.dll?query={searchTerms}&" |
| 79 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | 80 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" |
| 80 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | 81 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort"}, |
| 81 { L"google.com", | 82 {L"google.com", L"google.com", |
| 82 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | 83 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t"}, |
| 83 { L"en.wikipedia.org", | 84 {L"en.wikipedia.org", L"wiki", |
| 84 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}" }, | 85 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}"}, |
| 85 { L"search.yahoo.com", | 86 {L"search.yahoo.com", L"search.yahoo.com", |
| 86 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | 87 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8"}, |
| 87 { L"flickr.com", | 88 {L"flickr.com", L"flickr.com", |
| 88 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | 89 "http://www.flickr.com/photos/tags/?q={searchTerms}"}, |
| 89 { L"imdb.com", | 90 {L"imdb.com", L"imdb.com", "http://www.imdb.com/find?q={searchTerms}"}, |
| 90 "http://www.imdb.com/find?q={searchTerms}" }, | 91 {L"webster.com", L"webster.com", |
| 91 { L"webster.com", | 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}"}, |
| 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | 93 // Search keywords. |
| 93 // Search keywords. | 94 {L"\x4E2D\x6587", L"\x4E2D\x6587", "http://www.google.com/"}, |
| 94 { L"\x4E2D\x6587", "http://www.google.com/" }, | |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class FirefoxObserver : public ProfileWriter, | 97 class FirefoxObserver : public ProfileWriter, |
| 98 public importer::ImporterProgressObserver { | 98 public importer::ImporterProgressObserver { |
| 99 public: | 99 public: |
| 100 FirefoxObserver() | 100 explicit FirefoxObserver(bool use_keyword_in_json) |
| 101 : ProfileWriter(NULL), | 101 : ProfileWriter(NULL), |
| 102 bookmark_count_(0), | 102 bookmark_count_(0), |
| 103 history_count_(0), | 103 history_count_(0), |
| 104 password_count_(0), | 104 password_count_(0), |
| 105 keyword_count_(0) {} | 105 keyword_count_(0), |
| 106 use_keyword_in_json_(use_keyword_in_json) {} |
| 106 | 107 |
| 107 // importer::ImporterProgressObserver: | 108 // importer::ImporterProgressObserver: |
| 108 virtual void ImportStarted() OVERRIDE {} | 109 virtual void ImportStarted() OVERRIDE {} |
| 109 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 110 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
| 110 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 111 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
| 111 virtual void ImportEnded() OVERRIDE { | 112 virtual void ImportEnded() OVERRIDE { |
| 112 base::MessageLoop::current()->Quit(); | 113 base::MessageLoop::current()->Quit(); |
| 113 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 114 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
| 114 EXPECT_EQ(1U, history_count_); | 115 EXPECT_EQ(1U, history_count_); |
| 115 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 116 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 ++bookmark_count_; | 166 ++bookmark_count_; |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 | 169 |
| 169 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 170 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
| 170 bool unique_on_host_and_path) OVERRIDE { | 171 bool unique_on_host_and_path) OVERRIDE { |
| 171 for (size_t i = 0; i < template_urls.size(); ++i) { | 172 for (size_t i = 0; i < template_urls.size(); ++i) { |
| 172 // The order might not be deterministic, look in the expected list for | 173 // The order might not be deterministic, look in the expected list for |
| 173 // that template URL. | 174 // that template URL. |
| 174 bool found = false; | 175 bool found = false; |
| 175 const base::string16& keyword = template_urls[i]->keyword(); | 176 const base::string16& imported_keyword = template_urls[i]->keyword(); |
| 176 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | 177 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { |
| 177 if (keyword == base::WideToUTF16(kFirefoxKeywords[j].keyword)) { | 178 const base::string16 expected_keyword = base::WideToUTF16( |
| 179 use_keyword_in_json_ ? |
| 180 kFirefoxKeywords[j].keyword_in_json : |
| 181 kFirefoxKeywords[j].keyword_in_sqlite); |
| 182 if (imported_keyword == expected_keyword) { |
| 178 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | 183 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); |
| 179 found = true; | 184 found = true; |
| 180 break; | 185 break; |
| 181 } | 186 } |
| 182 } | 187 } |
| 183 EXPECT_TRUE(found); | 188 EXPECT_TRUE(found); |
| 184 ++keyword_count_; | 189 ++keyword_count_; |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 virtual void AddFavicons( | 193 virtual void AddFavicons( |
| 189 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
| 190 } | 195 } |
| 191 | 196 |
| 192 private: | 197 private: |
| 193 virtual ~FirefoxObserver() {} | 198 virtual ~FirefoxObserver() {} |
| 194 | 199 |
| 195 size_t bookmark_count_; | 200 size_t bookmark_count_; |
| 196 size_t history_count_; | 201 size_t history_count_; |
| 197 size_t password_count_; | 202 size_t password_count_; |
| 198 size_t keyword_count_; | 203 size_t keyword_count_; |
| 204 |
| 205 // Newer versions of Firefox can store custom keyword names in json, which |
| 206 // override the sqlite values. To be able to test both older and newer |
| 207 // versions, tests set this variable to indicate whether to expect the |
| 208 // |keyword_in_sqlite| or |keyword_in_json| values from the reference data. |
| 209 bool use_keyword_in_json_; |
| 199 }; | 210 }; |
| 200 | 211 |
| 201 } // namespace | 212 } // namespace |
| 202 | 213 |
| 203 // These tests need to be browser tests in order to be able to run the OOP | 214 // These tests need to be browser tests in order to be able to run the OOP |
| 204 // import (via ExternalProcessImporterHost) which launches a utility process on | 215 // import (via ExternalProcessImporterHost) which launches a utility process on |
| 205 // supported platforms. | 216 // supported platforms. |
| 206 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 217 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
| 207 protected: | 218 protected: |
| 208 virtual void SetUp() OVERRIDE { | 219 virtual void SetUp() OVERRIDE { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 base::MessageLoop::current()->Run(); | 281 base::MessageLoop::current()->Run(); |
| 271 } | 282 } |
| 272 | 283 |
| 273 base::ScopedTempDir temp_dir_; | 284 base::ScopedTempDir temp_dir_; |
| 274 base::FilePath profile_path_; | 285 base::FilePath profile_path_; |
| 275 base::FilePath app_path_; | 286 base::FilePath app_path_; |
| 276 }; | 287 }; |
| 277 | 288 |
| 278 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 289 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
| 279 MAYBE_IMPORTER(Firefox30Importer)) { | 290 MAYBE_IMPORTER(Firefox30Importer)) { |
| 280 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 291 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); |
| 281 FirefoxImporterBrowserTest( | 292 FirefoxImporterBrowserTest( |
| 282 "firefox3_profile", observer.get(), observer.get()); | 293 "firefox3_profile", observer.get(), observer.get()); |
| 283 } | 294 } |
| 284 | 295 |
| 285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 296 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
| 286 MAYBE_IMPORTER(Firefox35Importer)) { | 297 MAYBE_IMPORTER(Firefox35Importer)) { |
| 287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 298 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(false)); |
| 288 FirefoxImporterBrowserTest( | 299 FirefoxImporterBrowserTest( |
| 289 "firefox35_profile", observer.get(), observer.get()); | 300 "firefox35_profile", observer.get(), observer.get()); |
| 290 } | 301 } |
| 291 | 302 |
| 292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 303 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
| 293 MAYBE_IMPORTER(FirefoxImporter)) { | 304 MAYBE_IMPORTER(FirefoxImporter)) { |
| 294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 305 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver(true)); |
| 295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 306 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
| 296 } | 307 } |
| OLD | NEW |