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" |
| (...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 KeywordInfo(const char* keyword, const char* url) |
| 50 const char* url; | 50 : keyword(keyword), url(url) {} |
| 51 KeywordInfo() {} | |
| 52 std::string keyword; | |
| 53 std::string url; | |
| 51 }; | 54 }; |
| 52 | 55 |
| 56 std::vector<KeywordInfo> search_list; | |
| 57 | |
| 53 const BookmarkInfo kFirefoxBookmarks[] = { | 58 const BookmarkInfo kFirefoxBookmarks[] = { |
| 54 {true, 1, {"Bookmarks Toolbar"}, | 59 {true, 1, {"Bookmarks Toolbar"}, |
| 55 L"Toolbar", | 60 L"Toolbar", |
| 56 "http://site/"}, | 61 "http://site/"}, |
| 57 {false, 0, {}, | 62 {false, 0, {}, |
| 58 L"Title", | 63 L"Title", |
| 59 "http://www.google.com/"}, | 64 "http://www.google.com/"}, |
| 60 }; | 65 }; |
| 61 | 66 |
| 62 const PasswordInfo kFirefoxPasswords[] = { | 67 const PasswordInfo kFirefoxPasswords[] = { |
| 63 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", | 68 {"http://localhost:8080/", "http://localhost:8080/", "http://localhost:8080/", |
| 64 "loginuser", "abc", "loginpass", "123", false}, | 69 "loginuser", "abc", "loginpass", "123", false}, |
| 65 {"http://localhost:8080/", "", "http://localhost:8080/localhost", | 70 {"http://localhost:8080/", "", "http://localhost:8080/localhost", |
| 66 "", "http", "", "Http1+1abcdefg", false}, | 71 "", "http", "", "Http1+1abcdefg", false}, |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 const KeywordInfo kFirefoxKeywords[] = { | |
| 70 { L"amazon.com", | |
| 71 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
| 72 "{searchTerms}&mode=blended" }, | |
| 73 { L"answers.com", | |
| 74 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13" }, | |
| 75 { L"search.creativecommons.org", | |
| 76 "http://search.creativecommons.org/?q={searchTerms}" }, | |
| 77 { L"search.ebay.com", | |
| 78 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
| 79 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
| 80 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort" }, | |
| 81 { L"google.com", | |
| 82 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t" }, | |
| 83 { L"en.wikipedia.org", | |
| 84 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}" }, | |
| 85 { L"search.yahoo.com", | |
| 86 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8" }, | |
| 87 { L"flickr.com", | |
| 88 "http://www.flickr.com/photos/tags/?q={searchTerms}" }, | |
| 89 { L"imdb.com", | |
| 90 "http://www.imdb.com/find?q={searchTerms}" }, | |
| 91 { L"webster.com", | |
| 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | |
| 93 // Search keywords. | |
| 94 { L"\x4E2D\x6587", "http://www.google.com/" }, | |
| 95 }; | |
| 96 | |
| 97 class FirefoxObserver : public ProfileWriter, | 74 class FirefoxObserver : public ProfileWriter, |
| 98 public importer::ImporterProgressObserver { | 75 public importer::ImporterProgressObserver { |
| 99 public: | 76 public: |
| 100 FirefoxObserver() | 77 FirefoxObserver() |
| 101 : ProfileWriter(NULL), | 78 : ProfileWriter(NULL), |
| 102 bookmark_count_(0), | 79 bookmark_count_(0), |
| 103 history_count_(0), | 80 history_count_(0), |
| 104 password_count_(0), | 81 password_count_(0) {} |
| 105 keyword_count_(0) {} | |
| 106 | 82 |
| 107 // importer::ImporterProgressObserver: | 83 // importer::ImporterProgressObserver: |
| 108 virtual void ImportStarted() OVERRIDE {} | 84 virtual void ImportStarted() OVERRIDE {} |
| 109 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 85 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
| 110 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 86 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
| 111 virtual void ImportEnded() OVERRIDE { | 87 virtual void ImportEnded() OVERRIDE { |
| 112 base::MessageLoop::current()->Quit(); | 88 base::MessageLoop::current()->Quit(); |
| 113 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 89 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
| 114 EXPECT_EQ(1U, history_count_); | 90 EXPECT_EQ(1U, history_count_); |
| 115 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 91 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
| 116 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); | |
| 117 } | 92 } |
| 118 | 93 |
| 119 virtual bool BookmarkModelIsLoaded() const OVERRIDE { | 94 virtual bool BookmarkModelIsLoaded() const OVERRIDE { |
| 120 // Profile is ready for writing. | 95 // Profile is ready for writing. |
| 121 return true; | 96 return true; |
| 122 } | 97 } |
| 123 | 98 |
| 124 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { | 99 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { |
| 125 return true; | 100 return true; |
| 126 } | 101 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 for (size_t i = 0; i < bookmarks.size(); ++i) { | 136 for (size_t i = 0; i < bookmarks.size(); ++i) { |
| 162 EXPECT_NO_FATAL_FAILURE( | 137 EXPECT_NO_FATAL_FAILURE( |
| 163 TestEqualBookmarkEntry(bookmarks[i], | 138 TestEqualBookmarkEntry(bookmarks[i], |
| 164 kFirefoxBookmarks[bookmark_count_])) << i; | 139 kFirefoxBookmarks[bookmark_count_])) << i; |
| 165 ++bookmark_count_; | 140 ++bookmark_count_; |
| 166 } | 141 } |
| 167 } | 142 } |
| 168 | 143 |
| 169 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, | 144 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, |
| 170 bool unique_on_host_and_path) OVERRIDE { | 145 bool unique_on_host_and_path) OVERRIDE { |
| 171 for (size_t i = 0; i < template_urls.size(); ++i) { | 146 for (size_t i = 0; i < template_urls.size(); ++i) { |
|
Peter Kasting
2014/08/11 22:25:05
Nit: Prefer iterators to indexes when the actual i
Nikhil
2014/08/12 09:48:55
Done.
| |
| 172 // The order might not be deterministic, look in the expected list for | 147 KeywordInfo item; |
| 173 // that template URL. | 148 item.keyword = base::UTF16ToUTF8(template_urls[i]->keyword()); |
| 174 bool found = false; | 149 item.url = template_urls[i]->url(); |
|
Peter Kasting
2014/08/11 22:25:05
You added a 2-arg constructor for KeywordInfo, so
Nikhil
2014/08/12 09:48:55
Done.
| |
| 175 const base::string16& keyword = template_urls[i]->keyword(); | 150 search_list.push_back(item); |
| 176 for (size_t j = 0; j < arraysize(kFirefoxKeywords); ++j) { | |
| 177 if (keyword == base::WideToUTF16(kFirefoxKeywords[j].keyword)) { | |
| 178 EXPECT_EQ(kFirefoxKeywords[j].url, template_urls[i]->url()); | |
| 179 found = true; | |
| 180 break; | |
| 181 } | |
| 182 } | |
| 183 EXPECT_TRUE(found); | |
| 184 ++keyword_count_; | |
| 185 } | 151 } |
| 186 } | 152 } |
| 187 | 153 |
| 188 virtual void AddFavicons( | 154 virtual void AddFavicons( |
| 189 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 155 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
| 190 } | 156 } |
| 191 | 157 |
| 192 private: | 158 private: |
| 193 virtual ~FirefoxObserver() {} | 159 virtual ~FirefoxObserver() {} |
| 194 | 160 |
| 195 size_t bookmark_count_; | 161 size_t bookmark_count_; |
| 196 size_t history_count_; | 162 size_t history_count_; |
| 197 size_t password_count_; | 163 size_t password_count_; |
| 198 size_t keyword_count_; | |
| 199 }; | 164 }; |
| 200 | 165 |
| 201 } // namespace | 166 } // namespace |
| 202 | 167 |
| 203 // These tests need to be browser tests in order to be able to run the OOP | 168 // 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 | 169 // import (via ExternalProcessImporterHost) which launches a utility process on |
| 205 // supported platforms. | 170 // supported platforms. |
| 206 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 171 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
| 207 protected: | 172 protected: |
| 208 virtual void SetUp() OVERRIDE { | 173 virtual void SetUp() OVERRIDE { |
| 209 // Creates a new profile in a new subdirectory in the temp directory. | 174 // Creates a new profile in a new subdirectory in the temp directory. |
| 210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 175 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 211 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | 176 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
| 212 base::DeleteFile(test_path, true); | 177 base::DeleteFile(test_path, true); |
| 213 base::CreateDirectory(test_path); | 178 base::CreateDirectory(test_path); |
| 214 profile_path_ = test_path.AppendASCII("profile"); | 179 profile_path_ = test_path.AppendASCII("profile"); |
| 215 app_path_ = test_path.AppendASCII("app"); | 180 app_path_ = test_path.AppendASCII("app"); |
| 216 base::CreateDirectory(app_path_); | 181 base::CreateDirectory(app_path_); |
| 217 | 182 |
| 218 // This will launch the browser test and thus needs to happen last. | 183 // This will launch the browser test and thus needs to happen last. |
| 219 InProcessBrowserTest::SetUp(); | 184 InProcessBrowserTest::SetUp(); |
| 220 } | 185 } |
| 221 | 186 |
| 187 void VerifyImportedSearchEngines(std::vector<KeywordInfo*>& expected_data) { | |
| 188 EXPECT_EQ(expected_data.size(), search_list.size()); | |
| 189 | |
| 190 for (size_t i = 0; i < expected_data.size(); ++i) { | |
| 191 // The order might not be deterministic, look in the expected list for | |
| 192 // that template URL. | |
| 193 bool found = false; | |
| 194 const std::string& keyword = expected_data[i]->keyword; | |
| 195 for (size_t j = 0; j < search_list.size(); ++j) { | |
| 196 if (keyword == search_list[j].keyword) { | |
| 197 EXPECT_EQ(expected_data[i]->url, search_list[j].url); | |
| 198 found = true; | |
| 199 break; | |
| 200 } | |
| 201 } | |
| 202 EXPECT_TRUE(found); | |
| 203 } | |
| 204 } | |
| 205 | |
| 222 void FirefoxImporterBrowserTest(std::string profile_dir, | 206 void FirefoxImporterBrowserTest(std::string profile_dir, |
| 223 importer::ImporterProgressObserver* observer, | 207 importer::ImporterProgressObserver* observer, |
| 224 ProfileWriter* writer) { | 208 ProfileWriter* writer) { |
| 225 base::FilePath data_path; | 209 base::FilePath data_path; |
| 226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 210 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
| 227 data_path = data_path.AppendASCII(profile_dir); | 211 data_path = data_path.AppendASCII(profile_dir); |
| 228 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); | 212 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); |
| 229 | 213 |
| 230 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 214 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
| 231 data_path = data_path.AppendASCII("firefox3_nss"); | 215 data_path = data_path.AppendASCII("firefox3_nss"); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 269 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
| 286 MAYBE_IMPORTER(Firefox35Importer)) { | 270 MAYBE_IMPORTER(Firefox35Importer)) { |
| 287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 271 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
| 288 FirefoxImporterBrowserTest( | 272 FirefoxImporterBrowserTest( |
| 289 "firefox35_profile", observer.get(), observer.get()); | 273 "firefox35_profile", observer.get(), observer.get()); |
| 290 } | 274 } |
| 291 | 275 |
| 292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 276 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
| 293 MAYBE_IMPORTER(FirefoxImporter)) { | 277 MAYBE_IMPORTER(FirefoxImporter)) { |
| 294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 278 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
| 279 | |
| 280 // Expected data for search engine list and keywords. | |
| 281 std::vector<KeywordInfo*> expected_data; | |
|
Peter Kasting
2014/08/11 22:25:05
Why does this take objects by pointer instead of v
Nikhil
2014/08/12 09:48:54
Done.
| |
| 282 expected_data.push_back( | |
| 283 new KeywordInfo("amazon.com", | |
| 284 "http://www.amazon.com/exec/obidos/external-search/" | |
| 285 "?field-keywords={searchTerms}&mode=blended")); | |
| 286 expected_data.push_back(new KeywordInfo( | |
| 287 "google.com", | |
| 288 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t")); | |
| 289 expected_data.push_back(new KeywordInfo( | |
| 290 "wiki", | |
| 291 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}")); | |
| 292 expected_data.push_back(new KeywordInfo( | |
| 293 "webster.com", | |
| 294 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}")); | |
| 295 expected_data.push_back(new KeywordInfo( | |
| 296 base::WideToUTF8(L"\x4E2D\x6587").c_str(), "http://www.google.com/")); | |
| 297 | |
| 298 // Import search engines. | |
| 295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 299 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
| 300 | |
| 301 // Verify imported search engine list and keywords. | |
| 302 VerifyImportedSearchEngines(expected_data); | |
| 303 | |
| 304 expected_data.clear(); | |
|
Peter Kasting
2014/08/11 22:25:05
This statement isn't necessary.
Nikhil
2014/08/12 09:48:55
Done.
| |
| 296 } | 305 } |
| OLD | NEW |