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

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

Issue 8816001: importer: Convert the wstrings in importer_unittest to string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 // The order of these includes is important. 8 // The order of these includes is important.
9 #include <windows.h> 9 #include <windows.h>
10 #include <unknwn.h> 10 #include <unknwn.h>
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 private: 264 private:
265 ~TestObserver() {} 265 ~TestObserver() {}
266 266
267 size_t bookmark_count_; 267 size_t bookmark_count_;
268 size_t history_count_; 268 size_t history_count_;
269 size_t password_count_; 269 size_t password_count_;
270 }; 270 };
271 271
272 bool CreateUrlFile(std::wstring file, std::wstring url) { 272 bool CreateUrlFile(const string16& file, const string16& url) {
273 base::win::ScopedComPtr<IUniformResourceLocator> locator; 273 base::win::ScopedComPtr<IUniformResourceLocator> locator;
274 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL, 274 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL,
275 CLSCTX_INPROC_SERVER); 275 CLSCTX_INPROC_SERVER);
276 if (FAILED(result)) 276 if (FAILED(result))
277 return false; 277 return false;
278 base::win::ScopedComPtr<IPersistFile> persist_file; 278 base::win::ScopedComPtr<IPersistFile> persist_file;
279 result = persist_file.QueryFrom(locator); 279 result = persist_file.QueryFrom(locator);
280 if (FAILED(result)) 280 if (FAILED(result))
281 return false; 281 return false;
282 result = locator->SetURL(url.c_str(), 0); 282 result = locator->SetURL(url.c_str(), 0);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 HRESULT res = pstore->WriteItem(0, type, subtype, items[i].name, 324 HRESULT res = pstore->WriteItem(0, type, subtype, items[i].name,
325 items[i].data_size, reinterpret_cast<BYTE*>(items[i].data), 325 items[i].data_size, reinterpret_cast<BYTE*>(items[i].data),
326 NULL, 0, 0); 326 NULL, 0, 0);
327 ASSERT_TRUE(res == PST_E_OK); 327 ASSERT_TRUE(res == PST_E_OK);
328 } 328 }
329 } 329 }
330 330
331 TEST_F(ImporterTest, IEImporter) { 331 TEST_F(ImporterTest, IEImporter) {
332 // Sets up a favorites folder. 332 // Sets up a favorites folder.
333 base::win::ScopedCOMInitializer com_init; 333 base::win::ScopedCOMInitializer com_init;
334 std::wstring path = temp_dir_.path().AppendASCII("Favorites").value(); 334 string16 path = temp_dir_.path().AppendASCII("Favorites").value();
335 CreateDirectory(path.c_str(), NULL); 335 CreateDirectory(path.c_str(), NULL);
336 CreateDirectory((path + L"\\SubFolder").c_str(), NULL); 336 CreateDirectory((path + L"\\SubFolder").c_str(), NULL);
337 CreateDirectory((path + L"\\Links").c_str(), NULL); 337 CreateDirectory((path + L"\\Links").c_str(), NULL);
338 CreateDirectory((path + L"\\Links\\SubFolderOfLinks").c_str(), NULL); 338 CreateDirectory((path + L"\\Links\\SubFolderOfLinks").c_str(), NULL);
339 CreateDirectory((path + L"\\\x0061").c_str(), NULL); 339 CreateDirectory((path + L"\\\x0061").c_str(), NULL);
340 ASSERT_TRUE(CreateUrlFile(path + L"\\Google Home Page.url", 340 ASSERT_TRUE(CreateUrlFile(path + L"\\Google Home Page.url",
341 L"http://www.google.com/")); 341 L"http://www.google.com/"));
342 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder\\Title.url", 342 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder\\Title.url",
343 L"http://www.link.com/")); 343 L"http://www.link.com/"));
344 ASSERT_TRUE(CreateUrlFile(path + L"\\TheLink.url", 344 ASSERT_TRUE(CreateUrlFile(path + L"\\TheLink.url",
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 417
418 418
419 std::vector<unsigned char> decrypted_data1; 419 std::vector<unsigned char> decrypted_data1;
420 decrypted_data1.resize(arraysize(data1)); 420 decrypted_data1.resize(arraysize(data1));
421 memcpy(&decrypted_data1.front(), data1, sizeof(data1)); 421 memcpy(&decrypted_data1.front(), data1, sizeof(data1));
422 422
423 std::vector<unsigned char> decrypted_data2; 423 std::vector<unsigned char> decrypted_data2;
424 decrypted_data2.resize(arraysize(data2)); 424 decrypted_data2.resize(arraysize(data2));
425 memcpy(&decrypted_data2.front(), data2, sizeof(data2)); 425 memcpy(&decrypted_data2.front(), data2, sizeof(data2));
426 426
427 std::wstring password; 427 string16 password;
428 std::wstring username; 428 string16 username;
429 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username, 429 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username,
430 &password)); 430 &password));
431 EXPECT_EQ(L"abcdefgh", username); 431 EXPECT_EQ(L"abcdefgh", username);
432 EXPECT_EQ(L"abcdefghijkl", password); 432 EXPECT_EQ(L"abcdefghijkl", password);
433 433
434 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username, 434 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username,
435 &password)); 435 &password));
436 EXPECT_EQ(L"abcdefghi", username); 436 EXPECT_EQ(L"abcdefghi", username);
437 EXPECT_EQ(L"abcdefg", password); 437 EXPECT_EQ(L"abcdefg", password);
438 } 438 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 virtual void ImportStarted() OVERRIDE {} 535 virtual void ImportStarted() OVERRIDE {}
536 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} 536 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {}
537 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} 537 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {}
538 virtual void ImportEnded() OVERRIDE { 538 virtual void ImportEnded() OVERRIDE {
539 MessageLoop::current()->Quit(); 539 MessageLoop::current()->Quit();
540 EXPECT_EQ(arraysize(kFirefox2Bookmarks), bookmark_count_); 540 EXPECT_EQ(arraysize(kFirefox2Bookmarks), bookmark_count_);
541 EXPECT_EQ(1U, history_count_); 541 EXPECT_EQ(1U, history_count_);
542 EXPECT_EQ(arraysize(kFirefox2Passwords), password_count_); 542 EXPECT_EQ(arraysize(kFirefox2Passwords), password_count_);
543 EXPECT_EQ(arraysize(kFirefox2Keywords), keyword_count_); 543 EXPECT_EQ(arraysize(kFirefox2Keywords), keyword_count_);
544 EXPECT_EQ(kFirefox2Keywords[kDefaultFirefox2KeywordIndex].keyword, 544 EXPECT_EQ(kFirefox2Keywords[kDefaultFirefox2KeywordIndex].keyword,
545 default_keyword_); 545 UTF16ToWideHack(default_keyword_));
546 EXPECT_EQ(kFirefox2Keywords[kDefaultFirefox2KeywordIndex].url, 546 EXPECT_EQ(kFirefox2Keywords[kDefaultFirefox2KeywordIndex].url,
547 default_keyword_url_); 547 default_keyword_url_);
548 } 548 }
549 549
550 virtual bool BookmarkModelIsLoaded() const { 550 virtual bool BookmarkModelIsLoaded() const {
551 // Profile is ready for writing. 551 // Profile is ready for writing.
552 return true; 552 return true;
553 } 553 }
554 554
555 virtual bool TemplateURLServiceIsLoaded() const { 555 virtual bool TemplateURLServiceIsLoaded() const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 break; 603 break;
604 } 604 }
605 } 605 }
606 EXPECT_TRUE(found); 606 EXPECT_TRUE(found);
607 ++keyword_count_; 607 ++keyword_count_;
608 } 608 }
609 609
610 if (default_keyword_index != -1) { 610 if (default_keyword_index != -1) {
611 EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); 611 EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size()));
612 TemplateURL* default_turl = template_urls[default_keyword_index]; 612 TemplateURL* default_turl = template_urls[default_keyword_index];
613 default_keyword_ = UTF16ToWideHack(default_turl->keyword()); 613 default_keyword_ = default_turl->keyword();
614 default_keyword_url_ = default_turl->url()->url(); 614 default_keyword_url_ = default_turl->url()->url();
615 } 615 }
616 616
617 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); 617 STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
618 } 618 }
619 619
620 void AddFavicons(const std::vector<history::ImportedFaviconUsage>& favicons) { 620 void AddFavicons(const std::vector<history::ImportedFaviconUsage>& favicons) {
621 } 621 }
622 622
623 private: 623 private:
624 ~FirefoxObserver() {} 624 ~FirefoxObserver() {}
625 625
626 size_t bookmark_count_; 626 size_t bookmark_count_;
627 size_t history_count_; 627 size_t history_count_;
628 size_t password_count_; 628 size_t password_count_;
629 size_t keyword_count_; 629 size_t keyword_count_;
630 std::wstring default_keyword_; 630 string16 default_keyword_;
631 std::string default_keyword_url_; 631 std::string default_keyword_url_;
632 }; 632 };
633 633
634 TEST_F(ImporterTest, MAYBE(Firefox2Importer)) { 634 TEST_F(ImporterTest, MAYBE(Firefox2Importer)) {
635 FilePath data_path; 635 FilePath data_path;
636 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 636 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
637 data_path = data_path.AppendASCII("firefox2_profile"); 637 data_path = data_path.AppendASCII("firefox2_profile");
638 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); 638 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true));
639 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 639 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
640 data_path = data_path.AppendASCII("firefox2_nss"); 640 data_path = data_path.AppendASCII("firefox2_nss");
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} 738 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {}
739 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} 739 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {}
740 virtual void ImportEnded() OVERRIDE { 740 virtual void ImportEnded() OVERRIDE {
741 MessageLoop::current()->Quit(); 741 MessageLoop::current()->Quit();
742 EXPECT_EQ(arraysize(kFirefox3Bookmarks), bookmark_count_); 742 EXPECT_EQ(arraysize(kFirefox3Bookmarks), bookmark_count_);
743 EXPECT_EQ(1U, history_count_); 743 EXPECT_EQ(1U, history_count_);
744 EXPECT_EQ(arraysize(kFirefox3Passwords), password_count_); 744 EXPECT_EQ(arraysize(kFirefox3Passwords), password_count_);
745 if (import_search_engines_) { 745 if (import_search_engines_) {
746 EXPECT_EQ(arraysize(kFirefox3Keywords), keyword_count_); 746 EXPECT_EQ(arraysize(kFirefox3Keywords), keyword_count_);
747 EXPECT_EQ(kFirefox3Keywords[kDefaultFirefox3KeywordIndex].keyword, 747 EXPECT_EQ(kFirefox3Keywords[kDefaultFirefox3KeywordIndex].keyword,
748 default_keyword_); 748 UTF16ToWideHack(default_keyword_));
749 EXPECT_EQ(kFirefox3Keywords[kDefaultFirefox3KeywordIndex].url, 749 EXPECT_EQ(kFirefox3Keywords[kDefaultFirefox3KeywordIndex].url,
750 default_keyword_url_); 750 default_keyword_url_);
751 } 751 }
752 } 752 }
753 753
754 virtual bool BookmarkModelIsLoaded() const { 754 virtual bool BookmarkModelIsLoaded() const {
755 // Profile is ready for writing. 755 // Profile is ready for writing.
756 return true; 756 return true;
757 } 757 }
758 758
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 break; 812 break;
813 } 813 }
814 } 814 }
815 EXPECT_TRUE(found); 815 EXPECT_TRUE(found);
816 ++keyword_count_; 816 ++keyword_count_;
817 } 817 }
818 818
819 if (default_keyword_index != -1) { 819 if (default_keyword_index != -1) {
820 EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); 820 EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size()));
821 TemplateURL* default_turl = template_urls[default_keyword_index]; 821 TemplateURL* default_turl = template_urls[default_keyword_index];
822 default_keyword_ = UTF16ToWideHack(default_turl->keyword()); 822 default_keyword_ = default_turl->keyword();
823 default_keyword_url_ = default_turl->url()->url(); 823 default_keyword_url_ = default_turl->url()->url();
824 } 824 }
825 825
826 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); 826 STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
827 } 827 }
828 828
829 void AddFavicons(const std::vector<history::ImportedFaviconUsage>& favicons) { 829 void AddFavicons(const std::vector<history::ImportedFaviconUsage>& favicons) {
830 } 830 }
831 831
832 private: 832 private:
833 ~Firefox3Observer() {} 833 ~Firefox3Observer() {}
834 834
835 size_t bookmark_count_; 835 size_t bookmark_count_;
836 size_t history_count_; 836 size_t history_count_;
837 size_t password_count_; 837 size_t password_count_;
838 size_t keyword_count_; 838 size_t keyword_count_;
839 bool import_search_engines_; 839 bool import_search_engines_;
840 std::wstring default_keyword_; 840 string16 default_keyword_;
841 std::string default_keyword_url_; 841 std::string default_keyword_url_;
842 }; 842 };
843 843
844 TEST_F(ImporterTest, MAYBE(Firefox30Importer)) { 844 TEST_F(ImporterTest, MAYBE(Firefox30Importer)) {
845 scoped_refptr<Firefox3Observer> observer(new Firefox3Observer()); 845 scoped_refptr<Firefox3Observer> observer(new Firefox3Observer());
846 Firefox3xImporterTest("firefox3_profile", observer.get(), observer.get(), 846 Firefox3xImporterTest("firefox3_profile", observer.get(), observer.get(),
847 true); 847 true);
848 } 848 }
849 849
850 TEST_F(ImporterTest, MAYBE(Firefox35Importer)) { 850 TEST_F(ImporterTest, MAYBE(Firefox35Importer)) {
851 bool import_search_engines = false; 851 bool import_search_engines = false;
852 scoped_refptr<Firefox3Observer> observer( 852 scoped_refptr<Firefox3Observer> observer(
853 new Firefox3Observer(import_search_engines)); 853 new Firefox3Observer(import_search_engines));
854 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(), 854 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(),
855 import_search_engines); 855 import_search_engines);
856 } 856 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698