| 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 // The order of these includes is important. | 5 // The order of these includes is important. |
| 6 #include <windows.h> | 6 #include <windows.h> |
| 7 #include <unknwn.h> | 7 #include <unknwn.h> |
| 8 #include <intshcut.h> | 8 #include <intshcut.h> |
| 9 #include <shlguid.h> | 9 #include <shlguid.h> |
| 10 #include <urlhist.h> | 10 #include <urlhist.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 24 #include "base/string16.h" | 24 #include "base/string16.h" |
| 25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 27 #include "base/win/registry.h" | 27 #include "base/win/registry.h" |
| 28 #include "base/win/scoped_comptr.h" | 28 #include "base/win/scoped_comptr.h" |
| 29 #include "base/win/scoped_propvariant.h" | 29 #include "base/win/scoped_propvariant.h" |
| 30 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
| 31 #include "chrome/browser/history/history_types.h" | 31 #include "chrome/browser/history/history_types.h" |
| 32 #include "chrome/browser/importer/ie_importer.h" | 32 #include "chrome/browser/importer/ie_importer.h" |
| 33 #include "chrome/browser/importer/ie_importer_test_registry_overrider_win.h" |
| 33 #include "chrome/browser/importer/importer_bridge.h" | 34 #include "chrome/browser/importer/importer_bridge.h" |
| 34 #include "chrome/browser/importer/importer_data_types.h" | 35 #include "chrome/browser/importer/importer_data_types.h" |
| 35 #include "chrome/browser/importer/importer_host.h" | 36 #include "chrome/browser/importer/importer_host.h" |
| 36 #include "chrome/browser/importer/importer_progress_observer.h" | 37 #include "chrome/browser/importer/importer_progress_observer.h" |
| 37 #include "chrome/browser/importer/importer_unittest_utils.h" | 38 #include "chrome/browser/importer/importer_unittest_utils.h" |
| 38 #include "chrome/browser/importer/pstore_declarations.h" | 39 #include "chrome/browser/importer/pstore_declarations.h" |
| 39 #include "chrome/browser/search_engines/template_url.h" | 40 #include "chrome/browser/search_engines/template_url.h" |
| 40 #include "chrome/browser/ui/browser.h" | 41 #include "chrome/browser/ui/browser.h" |
| 41 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 42 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
| 43 #include "chrome/test/base/testing_profile.h" | 44 #include "chrome/test/base/testing_profile.h" |
| 44 #include "content/public/common/password_form.h" | 45 #include "content/public/common/password_form.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 const char16 kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; | |
| 50 const char16 kUnitTestUserOverrideSubKey[] = | |
| 51 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; | |
| 52 | |
| 53 const BookmarkInfo kIEBookmarks[] = { | 50 const BookmarkInfo kIEBookmarks[] = { |
| 54 {true, 2, {L"Links", L"SubFolderOfLinks"}, | 51 {true, 2, {L"Links", L"SubFolderOfLinks"}, |
| 55 L"SubLink", | 52 L"SubLink", |
| 56 "http://www.links-sublink.com/"}, | 53 "http://www.links-sublink.com/"}, |
| 57 {true, 1, {L"Links"}, | 54 {true, 1, {L"Links"}, |
| 58 L"TheLink", | 55 L"TheLink", |
| 59 "http://www.links-thelink.com/"}, | 56 "http://www.links-thelink.com/"}, |
| 60 {false, 0, {}, | 57 {false, 0, {}, |
| 61 L"Google Home Page", | 58 L"Google Home Page", |
| 62 "http://www.google.com/"}, | 59 "http://www.google.com/"}, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 }; | 406 }; |
| 410 | 407 |
| 411 } // namespace | 408 } // namespace |
| 412 | 409 |
| 413 // These tests need to be browser tests in order to be able to run the OOP | 410 // These tests need to be browser tests in order to be able to run the OOP |
| 414 // import (via ExternalProcessImporterHost) which launches a utility process. | 411 // import (via ExternalProcessImporterHost) which launches a utility process. |
| 415 class IEImporterBrowserTest : public InProcessBrowserTest { | 412 class IEImporterBrowserTest : public InProcessBrowserTest { |
| 416 protected: | 413 protected: |
| 417 virtual void SetUp() OVERRIDE { | 414 virtual void SetUp() OVERRIDE { |
| 418 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 415 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 419 StartRegistryOverride(); | 416 |
| 417 // Turn the override on for this process and flag child processes that they |
| 418 // should do so as well. |
| 419 ASSERT_TRUE(test_registry_overrider_.SetRegistryOverride()); |
| 420 | 420 |
| 421 // This will launch the browser test and thus needs to happen last. | 421 // This will launch the browser test and thus needs to happen last. |
| 422 InProcessBrowserTest::SetUp(); | 422 InProcessBrowserTest::SetUp(); |
| 423 } | 423 } |
| 424 | 424 |
| 425 virtual void TearDown() OVERRIDE { | |
| 426 EndRegistryOverride(); | |
| 427 } | |
| 428 | |
| 429 void StartRegistryOverride() { | |
| 430 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | |
| 431 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, | |
| 432 kUnitTestUserOverrideSubKey, | |
| 433 KEY_ALL_ACCESS); | |
| 434 EXPECT_TRUE(temp_hkcu_hive_key_.Valid()); | |
| 435 EXPECT_EQ(ERROR_SUCCESS, | |
| 436 RegOverridePredefKey(HKEY_CURRENT_USER, | |
| 437 temp_hkcu_hive_key_.Handle())); | |
| 438 } | |
| 439 | |
| 440 void EndRegistryOverride() { | |
| 441 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | |
| 442 temp_hkcu_hive_key_.Close(); | |
| 443 base::win::RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, | |
| 444 KEY_ALL_ACCESS); | |
| 445 key.DeleteKey(L""); | |
| 446 } | |
| 447 | |
| 448 base::ScopedTempDir temp_dir_; | 425 base::ScopedTempDir temp_dir_; |
| 449 base::win::RegKey temp_hkcu_hive_key_; | 426 IEImporterTestRegistryOverrider test_registry_overrider_; |
| 450 }; | 427 }; |
| 451 | 428 |
| 452 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { | 429 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { |
| 453 // Sets up a favorites folder. | 430 // Sets up a favorites folder. |
| 454 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); | 431 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
| 455 CreateDirectory(path.value().c_str(), NULL); | 432 CreateDirectory(path.value().c_str(), NULL); |
| 456 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); | 433 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); |
| 457 base::FilePath links_path = path.AppendASCII("Links"); | 434 base::FilePath links_path = path.AppendASCII("Links"); |
| 458 CreateDirectory(links_path.value().c_str(), NULL); | 435 CreateDirectory(links_path.value().c_str(), NULL); |
| 459 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), | 436 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // Deletes itself. | 490 // Deletes itself. |
| 514 // TODO(gab): Use ExternalProcessImporterHost on Windows. | 491 // TODO(gab): Use ExternalProcessImporterHost on Windows. |
| 515 ImporterHost* host = new ImporterHost; | 492 ImporterHost* host = new ImporterHost; |
| 516 TestObserver* observer = new TestObserver(); | 493 TestObserver* observer = new TestObserver(); |
| 517 host->SetObserver(observer); | 494 host->SetObserver(observer); |
| 518 | 495 |
| 519 importer::SourceProfile source_profile; | 496 importer::SourceProfile source_profile; |
| 520 source_profile.importer_type = importer::TYPE_IE; | 497 source_profile.importer_type = importer::TYPE_IE; |
| 521 source_profile.source_path = temp_dir_.path(); | 498 source_profile.source_path = temp_dir_.path(); |
| 522 | 499 |
| 523 // IUrlHistoryStg2::AddUrl seems to reset the override. Ensure it here. | |
| 524 StartRegistryOverride(); | |
| 525 | |
| 526 host->StartImportSettings( | 500 host->StartImportSettings( |
| 527 source_profile, | 501 source_profile, |
| 528 browser()->profile(), | 502 browser()->profile(), |
| 529 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, | 503 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, |
| 530 observer); | 504 observer); |
| 531 MessageLoop::current()->Run(); | 505 MessageLoop::current()->Run(); |
| 532 | 506 |
| 533 // Cleans up. | 507 // Cleans up. |
| 534 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); | 508 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); |
| 535 url_history_stg2.Release(); | 509 url_history_stg2.Release(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 source_profile.source_path = temp_dir_.path(); | 575 source_profile.source_path = temp_dir_.path(); |
| 602 | 576 |
| 603 host->StartImportSettings( | 577 host->StartImportSettings( |
| 604 source_profile, | 578 source_profile, |
| 605 browser()->profile(), | 579 browser()->profile(), |
| 606 importer::FAVORITES, | 580 importer::FAVORITES, |
| 607 observer); | 581 observer); |
| 608 MessageLoop::current()->Run(); | 582 MessageLoop::current()->Run(); |
| 609 } | 583 } |
| 610 } | 584 } |
| OLD | NEW |