Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/importer/firefox_importer_unittest.cc

Issue 12314090: Add utf_string_conversions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { 149 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE {
150 return true; 150 return true;
151 } 151 }
152 152
153 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE { 153 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE {
154 PasswordInfo p = kFirefox2Passwords[password_count_]; 154 PasswordInfo p = kFirefox2Passwords[password_count_];
155 EXPECT_EQ(p.origin, form.origin.spec()); 155 EXPECT_EQ(p.origin, form.origin.spec());
156 EXPECT_EQ(p.realm, form.signon_realm); 156 EXPECT_EQ(p.realm, form.signon_realm);
157 EXPECT_EQ(p.action, form.action.spec()); 157 EXPECT_EQ(p.action, form.action.spec());
158 EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); 158 EXPECT_EQ(base::WideToUTF16(p.username_element), form.username_element);
159 EXPECT_EQ(WideToUTF16(p.username), form.username_value); 159 EXPECT_EQ(base::WideToUTF16(p.username), form.username_value);
160 EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); 160 EXPECT_EQ(base::WideToUTF16(p.password_element), form.password_element);
161 EXPECT_EQ(WideToUTF16(p.password), form.password_value); 161 EXPECT_EQ(base::WideToUTF16(p.password), form.password_value);
162 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); 162 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user);
163 ++password_count_; 163 ++password_count_;
164 } 164 }
165 165
166 virtual void AddHistoryPage(const history::URLRows& page, 166 virtual void AddHistoryPage(const history::URLRows& page,
167 history::VisitSource visit_source) OVERRIDE { 167 history::VisitSource visit_source) OVERRIDE {
168 ASSERT_EQ(1U, page.size()); 168 ASSERT_EQ(1U, page.size());
169 EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec()); 169 EXPECT_EQ("http://en-us.www.mozilla.com/", page[0].url().spec());
170 EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title()); 170 EXPECT_EQ(ASCIIToUTF16("Firefox Updated"), page[0].title());
171 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source); 171 EXPECT_EQ(history::SOURCE_FIREFOX_IMPORTED, visit_source);
(...skipping 11 matching lines...) Expand all
183 183
184 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, 184 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls,
185 bool unique_on_host_and_path) OVERRIDE { 185 bool unique_on_host_and_path) OVERRIDE {
186 for (size_t i = 0; i < template_urls.size(); ++i) { 186 for (size_t i = 0; i < template_urls.size(); ++i) {
187 // The order might not be deterministic, look in the expected list for 187 // The order might not be deterministic, look in the expected list for
188 // that template URL. 188 // that template URL.
189 bool found = false; 189 bool found = false;
190 string16 keyword = template_urls[i]->keyword(); 190 string16 keyword = template_urls[i]->keyword();
191 for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) { 191 for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) {
192 if (template_urls[i]->keyword() == 192 if (template_urls[i]->keyword() ==
193 WideToUTF16Hack(kFirefox2Keywords[j].keyword)) { 193 base::WideToUTF16Hack(kFirefox2Keywords[j].keyword)) {
194 EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url()); 194 EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url());
195 found = true; 195 found = true;
196 break; 196 break;
197 } 197 }
198 } 198 }
199 EXPECT_TRUE(found); 199 EXPECT_TRUE(found);
200 ++keyword_count_; 200 ++keyword_count_;
201 } 201 }
202 } 202 }
203 203
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 294
295 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { 295 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE {
296 return true; 296 return true;
297 } 297 }
298 298
299 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE { 299 virtual void AddPasswordForm(const content::PasswordForm& form) OVERRIDE {
300 PasswordInfo p = kFirefox3Passwords[password_count_]; 300 PasswordInfo p = kFirefox3Passwords[password_count_];
301 EXPECT_EQ(p.origin, form.origin.spec()); 301 EXPECT_EQ(p.origin, form.origin.spec());
302 EXPECT_EQ(p.realm, form.signon_realm); 302 EXPECT_EQ(p.realm, form.signon_realm);
303 EXPECT_EQ(p.action, form.action.spec()); 303 EXPECT_EQ(p.action, form.action.spec());
304 EXPECT_EQ(WideToUTF16(p.username_element), form.username_element); 304 EXPECT_EQ(base::WideToUTF16(p.username_element), form.username_element);
305 EXPECT_EQ(WideToUTF16(p.username), form.username_value); 305 EXPECT_EQ(base::WideToUTF16(p.username), form.username_value);
306 EXPECT_EQ(WideToUTF16(p.password_element), form.password_element); 306 EXPECT_EQ(base::WideToUTF16(p.password_element), form.password_element);
307 EXPECT_EQ(WideToUTF16(p.password), form.password_value); 307 EXPECT_EQ(base::WideToUTF16(p.password), form.password_value);
308 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user); 308 EXPECT_EQ(p.blacklisted, form.blacklisted_by_user);
309 ++password_count_; 309 ++password_count_;
310 } 310 }
311 311
312 virtual void AddHistoryPage(const history::URLRows& page, 312 virtual void AddHistoryPage(const history::URLRows& page,
313 history::VisitSource visit_source) OVERRIDE { 313 history::VisitSource visit_source) OVERRIDE {
314 ASSERT_EQ(3U, page.size()); 314 ASSERT_EQ(3U, page.size());
315 EXPECT_EQ("http://www.google.com/", page[0].url().spec()); 315 EXPECT_EQ("http://www.google.com/", page[0].url().spec());
316 EXPECT_EQ(ASCIIToUTF16("Google"), page[0].title()); 316 EXPECT_EQ(ASCIIToUTF16("Google"), page[0].title());
317 EXPECT_EQ("http://www.google.com/", page[1].url().spec()); 317 EXPECT_EQ("http://www.google.com/", page[1].url().spec());
(...skipping 16 matching lines...) Expand all
334 334
335 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls, 335 virtual void AddKeywords(ScopedVector<TemplateURL> template_urls,
336 bool unique_on_host_and_path) OVERRIDE { 336 bool unique_on_host_and_path) OVERRIDE {
337 for (size_t i = 0; i < template_urls.size(); ++i) { 337 for (size_t i = 0; i < template_urls.size(); ++i) {
338 // The order might not be deterministic, look in the expected list for 338 // The order might not be deterministic, look in the expected list for
339 // that template URL. 339 // that template URL.
340 bool found = false; 340 bool found = false;
341 string16 keyword = template_urls[i]->keyword(); 341 string16 keyword = template_urls[i]->keyword();
342 for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) { 342 for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) {
343 if (template_urls[i]->keyword() == 343 if (template_urls[i]->keyword() ==
344 WideToUTF16Hack(kFirefox3Keywords[j].keyword)) { 344 base::WideToUTF16Hack(kFirefox3Keywords[j].keyword)) {
345 EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url()); 345 EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url());
346 found = true; 346 found = true;
347 break; 347 break;
348 } 348 }
349 } 349 }
350 EXPECT_TRUE(found); 350 EXPECT_TRUE(found);
351 ++keyword_count_; 351 ++keyword_count_;
352 } 352 }
353 } 353 }
354 354
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 db_path = db_path.AppendASCII("firefox2_profile"); 500 db_path = db_path.AppendASCII("firefox2_profile");
501 501
502 FFUnitTestDecryptorProxy decryptor_proxy; 502 FFUnitTestDecryptorProxy decryptor_proxy;
503 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); 503 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
504 504
505 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); 505 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
506 EXPECT_EQ(ASCIIToUTF16("hello"), 506 EXPECT_EQ(ASCIIToUTF16("hello"),
507 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ" 507 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ"
508 "M63MpT9rtBAjMCm7qo/EhlA==")); 508 "M63MpT9rtBAjMCm7qo/EhlA=="));
509 // Test UTF-16 encoding. 509 // Test UTF-16 encoding.
510 EXPECT_EQ(WideToUTF16(L"\x4E2D"), 510 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"),
511 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECN9" 511 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECN9"
512 "OQ5ZFmhb8BAiFo1Z+fUvaIQ==")); 512 "OQ5ZFmhb8BAiFo1Z+fUvaIQ=="));
513 } 513 }
514 514
515 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { 515 TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) {
516 base::FilePath nss_path; 516 base::FilePath nss_path;
517 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path)); 517 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &nss_path));
518 #ifdef OS_MACOSX 518 #ifdef OS_MACOSX
519 nss_path = nss_path.AppendASCII("firefox3_nss_mac"); 519 nss_path = nss_path.AppendASCII("firefox3_nss_mac");
520 #else 520 #else
521 nss_path = nss_path.AppendASCII("firefox3_nss"); 521 nss_path = nss_path.AppendASCII("firefox3_nss");
522 #endif // !OS_MACOSX 522 #endif // !OS_MACOSX
523 base::FilePath db_path; 523 base::FilePath db_path;
524 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); 524 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
525 db_path = db_path.AppendASCII("firefox3_profile"); 525 db_path = db_path.AppendASCII("firefox3_profile");
526 526
527 FFUnitTestDecryptorProxy decryptor_proxy; 527 FFUnitTestDecryptorProxy decryptor_proxy;
528 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); 528 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
529 529
530 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); 530 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
531 EXPECT_EQ(ASCIIToUTF16("hello"), 531 EXPECT_EQ(ASCIIToUTF16("hello"),
532 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" 532 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"
533 "jtRg4qFSHBAhv9luFkXgDJA==")); 533 "jtRg4qFSHBAhv9luFkXgDJA=="));
534 // Test UTF-16 encoding. 534 // Test UTF-16 encoding.
535 EXPECT_EQ(WideToUTF16(L"\x4E2D"), 535 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"),
536 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" 536 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW"
537 "qqiccfQHWBAie74hxnULxlw==")); 537 "qqiccfQHWBAie74hxnULxlw=="));
538 } 538 }
539 539
540 TEST(FirefoxImporterTest, Firefox2BookmarkParse) { 540 TEST(FirefoxImporterTest, Firefox2BookmarkParse) {
541 bool result; 541 bool result;
542 542
543 // Tests charset. 543 // Tests charset.
544 std::string charset; 544 std::string charset;
545 result = Firefox2Importer::ParseCharsetFromLine( 545 result = Firefox2Importer::ParseCharsetFromLine(
(...skipping 28 matching lines...) Expand all
574 string16 title; 574 string16 title;
575 GURL url, favicon; 575 GURL url, favicon;
576 string16 shortcut; 576 string16 shortcut;
577 string16 post_data; 577 string16 post_data;
578 base::Time add_date; 578 base::Time add_date;
579 result = Firefox2Importer::ParseBookmarkFromLine( 579 result = Firefox2Importer::ParseBookmarkFromLine(
580 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" " 580 "<DT><A HREF=\"http://chinese.site.cn/path?query=1#ref\" "
581 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>", 581 "SHORTCUTURL=\"\xE4\xB8\xAD\">\xE4\xB8\xAD\xE6\x96\x87</A>",
582 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 582 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
583 EXPECT_TRUE(result); 583 EXPECT_TRUE(result);
584 EXPECT_EQ(L"\x4E2D\x6587", UTF16ToWide(title)); 584 EXPECT_EQ(L"\x4E2D\x6587", base::UTF16ToWide(title));
585 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec()); 585 EXPECT_EQ("http://chinese.site.cn/path?query=1#ref", url.spec());
586 EXPECT_EQ(L"\x4E2D", UTF16ToWide(shortcut)); 586 EXPECT_EQ(L"\x4E2D", base::UTF16ToWide(shortcut));
587 EXPECT_EQ(string16(), post_data); 587 EXPECT_EQ(string16(), post_data);
588 EXPECT_TRUE(base::Time() == add_date); 588 EXPECT_TRUE(base::Time() == add_date);
589 589
590 // No shortcut, and url contains %22 ('"' character). 590 // No shortcut, and url contains %22 ('"' character).
591 result = Firefox2Importer::ParseBookmarkFromLine( 591 result = Firefox2Importer::ParseBookmarkFromLine(
592 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>", 592 "<DT><A HREF=\"http://domain.com/?q=%22<>%22\">name</A>",
593 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data); 593 charset, &title, &url, &favicon, &shortcut, &add_date, &post_data);
594 EXPECT_TRUE(result); 594 EXPECT_TRUE(result);
595 EXPECT_EQ(ASCIIToUTF16("name"), title); 595 EXPECT_EQ(ASCIIToUTF16("name"), title);
596 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec()); 596 EXPECT_EQ("http://domain.com/?q=%22%3C%3E%22", url.spec());
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); 757 EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec());
758 EXPECT_EQ(0U, entry.path.size()); 758 EXPECT_EQ(0U, entry.path.size());
759 entry = *it++; 759 entry = *it++;
760 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title); 760 EXPECT_EQ(ASCIIToUTF16("Google"), entry.title);
761 EXPECT_EQ("http://www.google.com/", entry.url.spec()); 761 EXPECT_EQ("http://www.google.com/", entry.url.spec());
762 EXPECT_EQ(0U, entry.path.size()); 762 EXPECT_EQ(0U, entry.path.size());
763 } 763 }
764 764
765 importer->Release(); 765 importer->Release();
766 } 766 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox3_importer.cc ('k') | chrome/browser/importer/firefox_importer_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698