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(std::string keyword, std::string url) |
Peter Kasting
2014/08/12 18:16:45
Nit: Const refs
Nikhil
2014/08/13 05:52:41
Done.
| |
50 const char* url; | 50 : keyword(keyword), url(url) {} |
51 KeywordInfo() {} | |
Peter Kasting
2014/08/12 18:16:45
Nit: Is this constructor necessary? Maybe for the
Nikhil
2014/08/13 05:52:41
Done.
| |
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 // Importer should import the FF favorites the same as the list, in the same | 134 // Importer should import the FF favorites the same as the list, in the same |
160 // order. | 135 // order. |
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, |
Peter Kasting
2014/08/12 18:16:45
Nit: While here: Make this a const ref (requires c
Peter Kasting
2014/08/12 18:23:06
Wait, don't do that. This is trying to pass owner
Nikhil
2014/08/13 05:52:41
Acknowledged.
| |
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 (ScopedVector<TemplateURL>::const_iterator i = template_urls.begin(); |
172 // The order might not be deterministic, look in the expected list for | 147 i != template_urls.end(); |
173 // that template URL. | 148 ++i) { |
174 bool found = false; | 149 search_list.push_back( |
175 const base::string16& keyword = template_urls[i]->keyword(); | 150 KeywordInfo(base::UTF16ToUTF8((*i)->keyword()), (*i)->url())); |
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) { | |
Peter Kasting
2014/08/12 18:16:45
Nit: const arg
Nikhil
2014/08/13 05:52:41
Done.
| |
188 EXPECT_EQ(expected_data.size(), search_list.size()); | |
Peter Kasting
2014/08/12 18:16:45
Nit: (expected, actual)
Nikhil
2014/08/13 05:52:41
Are you suggesting to change variable name for vec
Peter Kasting
2014/08/13 06:21:07
OK.
| |
189 | |
190 for (std::vector<KeywordInfo>::const_iterator i = expected_data.begin(); | |
191 i != expected_data.end(); | |
192 ++i) { | |
193 // The order might not be deterministic, look in the expected list for | |
194 // that template URL. | |
195 bool found = false; | |
196 const std::string& keyword = i->keyword; | |
197 for (std::vector<KeywordInfo>::const_iterator j = search_list.begin(); | |
198 j != search_list.end(); | |
199 ++j) { | |
200 if (keyword == j->keyword) { | |
201 EXPECT_EQ(i->url, j->url); | |
202 found = true; | |
203 break; | |
204 } | |
205 } | |
206 EXPECT_TRUE(found); | |
207 } | |
208 } | |
209 | |
222 void FirefoxImporterBrowserTest(std::string profile_dir, | 210 void FirefoxImporterBrowserTest(std::string profile_dir, |
223 importer::ImporterProgressObserver* observer, | 211 importer::ImporterProgressObserver* observer, |
224 ProfileWriter* writer) { | 212 ProfileWriter* writer) { |
225 base::FilePath data_path; | 213 base::FilePath data_path; |
226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 214 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
227 data_path = data_path.AppendASCII(profile_dir); | 215 data_path = data_path.AppendASCII(profile_dir); |
228 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); | 216 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); |
229 | 217 |
230 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 218 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
231 data_path = data_path.AppendASCII("firefox3_nss"); | 219 data_path = data_path.AppendASCII("firefox3_nss"); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } | 259 } |
272 | 260 |
273 base::ScopedTempDir temp_dir_; | 261 base::ScopedTempDir temp_dir_; |
274 base::FilePath profile_path_; | 262 base::FilePath profile_path_; |
275 base::FilePath app_path_; | 263 base::FilePath app_path_; |
276 }; | 264 }; |
277 | 265 |
278 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 266 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
279 MAYBE_IMPORTER(Firefox30Importer)) { | 267 MAYBE_IMPORTER(Firefox30Importer)) { |
280 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 268 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
269 | |
270 std::vector<KeywordInfo> expected_data; | |
271 expected_data.push_back(KeywordInfo( | |
272 "amazon.com", | |
273 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
274 "{searchTerms}&mode=blended")); | |
275 expected_data.push_back(KeywordInfo( | |
276 "answers.com", | |
277 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13")); | |
278 expected_data.push_back( | |
279 KeywordInfo("search.creativecommons.org", | |
280 "http://search.creativecommons.org/?q={searchTerms}")); | |
281 expected_data.push_back(KeywordInfo( | |
282 "search.ebay.com", | |
283 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
284 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
285 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort")); | |
286 expected_data.push_back(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(KeywordInfo( | |
290 "en.wikipedia.org", | |
291 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}")); | |
292 expected_data.push_back( | |
293 KeywordInfo("search.yahoo.com", | |
294 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8")); | |
295 expected_data.push_back(KeywordInfo( | |
296 "flickr.com", "http://www.flickr.com/photos/tags/?q={searchTerms}")); | |
297 expected_data.push_back( | |
298 KeywordInfo("imdb.com", "http://www.imdb.com/find?q={searchTerms}")); | |
299 expected_data.push_back(KeywordInfo( | |
300 "webster.com", | |
301 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}")); | |
302 expected_data.push_back(KeywordInfo(base::WideToUTF8(L"\x4E2D\x6587").c_str(), | |
303 "http://www.google.com/")); | |
304 | |
281 FirefoxImporterBrowserTest( | 305 FirefoxImporterBrowserTest( |
282 "firefox3_profile", observer.get(), observer.get()); | 306 "firefox3_profile", observer.get(), observer.get()); |
307 | |
308 VerifyImportedSearchEngines(expected_data); | |
283 } | 309 } |
284 | 310 |
285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 311 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
286 MAYBE_IMPORTER(Firefox35Importer)) { | 312 MAYBE_IMPORTER(Firefox35Importer)) { |
287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 313 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
314 | |
315 std::vector<KeywordInfo> expected_data; | |
316 expected_data.push_back(KeywordInfo( | |
317 "amazon.com", | |
318 "http://www.amazon.com/exec/obidos/external-search/?field-keywords=" | |
319 "{searchTerms}&mode=blended")); | |
320 expected_data.push_back(KeywordInfo( | |
321 "answers.com", | |
322 "http://www.answers.com/main/ntquery?s={searchTerms}&gwp=13")); | |
323 expected_data.push_back( | |
324 KeywordInfo("search.creativecommons.org", | |
325 "http://search.creativecommons.org/?q={searchTerms}")); | |
326 expected_data.push_back(KeywordInfo( | |
327 "search.ebay.com", | |
328 "http://search.ebay.com/search/search.dll?query={searchTerms}&" | |
329 "MfcISAPICommand=GetResult&ht=1&ebaytag1=ebayreg&srchdesc=n&" | |
330 "maxRecordsReturned=300&maxRecordsPerPage=50&SortProperty=MetaEndSort")); | |
331 expected_data.push_back(KeywordInfo( | |
332 "google.com", | |
333 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t")); | |
334 expected_data.push_back(KeywordInfo( | |
335 "en.wikipedia.org", | |
336 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}")); | |
337 expected_data.push_back( | |
338 KeywordInfo("search.yahoo.com", | |
339 "http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8")); | |
340 expected_data.push_back(KeywordInfo( | |
341 "flickr.com", "http://www.flickr.com/photos/tags/?q={searchTerms}")); | |
342 expected_data.push_back( | |
343 KeywordInfo("imdb.com", "http://www.imdb.com/find?q={searchTerms}")); | |
344 expected_data.push_back(KeywordInfo( | |
345 "webster.com", | |
346 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}")); | |
347 expected_data.push_back(KeywordInfo(base::WideToUTF8(L"\x4E2D\x6587").c_str(), | |
348 "http://www.google.com/")); | |
349 | |
288 FirefoxImporterBrowserTest( | 350 FirefoxImporterBrowserTest( |
289 "firefox35_profile", observer.get(), observer.get()); | 351 "firefox35_profile", observer.get(), observer.get()); |
352 | |
353 VerifyImportedSearchEngines(expected_data); | |
290 } | 354 } |
291 | 355 |
292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 356 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
293 MAYBE_IMPORTER(FirefoxImporter)) { | 357 MAYBE_IMPORTER(FirefoxImporter)) { |
294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 358 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
359 | |
360 // Expected data for search engine list and keywords. | |
Peter Kasting
2014/08/12 18:16:45
Nit: These comments don't seem very necessary (and
Nikhil
2014/08/13 05:52:41
Done.
| |
361 std::vector<KeywordInfo> expected_data; | |
362 expected_data.push_back( | |
363 KeywordInfo("amazon.com", | |
364 "http://www.amazon.com/exec/obidos/external-search/" | |
365 "?field-keywords={searchTerms}&mode=blended")); | |
366 expected_data.push_back(KeywordInfo( | |
367 "google.com", | |
368 "http://www.google.com/search?q={searchTerms}&ie=utf-8&oe=utf-8&aq=t")); | |
369 expected_data.push_back(KeywordInfo( | |
370 "wiki", | |
371 "http://en.wikipedia.org/wiki/Special:Search?search={searchTerms}")); | |
372 expected_data.push_back(KeywordInfo( | |
373 "webster.com", | |
374 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}")); | |
375 expected_data.push_back(KeywordInfo(base::WideToUTF8(L"\x4E2D\x6587").c_str(), | |
376 "http://www.google.com/")); | |
377 | |
378 // Import search engines. | |
295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | 379 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); |
380 | |
381 // Verify imported search engine list and keywords. | |
382 VerifyImportedSearchEngines(expected_data); | |
296 } | 383 } |
OLD | NEW |