| 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 13 matching lines...) Expand all Loading... |
| 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/bookmarks/imported_bookmark_entry.h" | 31 #include "chrome/browser/bookmarks/imported_bookmark_entry.h" |
| 32 #include "chrome/browser/favicon/imported_favicon_usage.h" | 32 #include "chrome/browser/favicon/imported_favicon_usage.h" |
| 33 #include "chrome/browser/importer/ie_importer.h" | 33 #include "chrome/browser/importer/ie_importer.h" |
| 34 #include "chrome/browser/importer/ie_importer_utils_win.h" |
| 34 #include "chrome/browser/importer/ie_importer_test_registry_overrider_win.h" | 35 #include "chrome/browser/importer/ie_importer_test_registry_overrider_win.h" |
| 35 #include "chrome/browser/importer/importer_bridge.h" | 36 #include "chrome/browser/importer/importer_bridge.h" |
| 36 #include "chrome/browser/importer/importer_data_types.h" | 37 #include "chrome/browser/importer/importer_data_types.h" |
| 37 #include "chrome/browser/importer/importer_host.h" | 38 #include "chrome/browser/importer/importer_host.h" |
| 38 #include "chrome/browser/importer/importer_progress_observer.h" | 39 #include "chrome/browser/importer/importer_progress_observer.h" |
| 39 #include "chrome/browser/importer/importer_unittest_utils.h" | 40 #include "chrome/browser/importer/importer_unittest_utils.h" |
| 40 #include "chrome/browser/importer/pstore_declarations.h" | 41 #include "chrome/browser/importer/pstore_declarations.h" |
| 41 #include "chrome/browser/search_engines/template_url.h" | 42 #include "chrome/browser/search_engines/template_url.h" |
| 42 #include "chrome/browser/ui/browser.h" | 43 #include "chrome/browser/ui/browser.h" |
| 43 #include "chrome/common/chrome_paths.h" | 44 #include "chrome/common/chrome_paths.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 {false, 1, {L"b"}, L"a", "http://www.google.com/1"}, | 81 {false, 1, {L"b"}, L"a", "http://www.google.com/1"}, |
| 81 {false, 1, {L"b"}, L"b", "http://www.google.com/2"}, | 82 {false, 1, {L"b"}, L"b", "http://www.google.com/2"}, |
| 82 {false, 0, {}, L"c", "http://www.google.com/3"}, | 83 {false, 0, {}, L"c", "http://www.google.com/3"}, |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 const char16 kIEIdentifyUrl[] = | 86 const char16 kIEIdentifyUrl[] = |
| 86 L"http://A79029D6-753E-4e27-B807-3D46AB1545DF.com:8080/path?key=value"; | 87 L"http://A79029D6-753E-4e27-B807-3D46AB1545DF.com:8080/path?key=value"; |
| 87 const char16 kIEIdentifyTitle[] = | 88 const char16 kIEIdentifyTitle[] = |
| 88 L"Unittest GUID"; | 89 L"Unittest GUID"; |
| 89 | 90 |
| 90 const char16 kIEFavoritesOrderKey[] = | |
| 91 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\" | |
| 92 L"MenuOrder\\Favorites"; | |
| 93 | |
| 94 const char16 kFaviconStreamSuffix[] = L"url:favicon:$DATA"; | 91 const char16 kFaviconStreamSuffix[] = L"url:favicon:$DATA"; |
| 95 const char kDummyFaviconImageData[] = | 92 const char kDummyFaviconImageData[] = |
| 96 "\x42\x4D" // Magic signature 'BM' | 93 "\x42\x4D" // Magic signature 'BM' |
| 97 "\x1E\x00\x00\x00" // File size | 94 "\x1E\x00\x00\x00" // File size |
| 98 "\x00\x00\x00\x00" // Reserved | 95 "\x00\x00\x00\x00" // Reserved |
| 99 "\x1A\x00\x00\x00" // Offset of the pixel data | 96 "\x1A\x00\x00\x00" // Offset of the pixel data |
| 100 "\x0C\x00\x00\x00" // Header Size | 97 "\x0C\x00\x00\x00" // Header Size |
| 101 "\x01\x00\x01\x00" // Size: 1x1 | 98 "\x01\x00\x01\x00" // Size: 1x1 |
| 102 "\x01\x00" // Reserved | 99 "\x01\x00" // Reserved |
| 103 "\x18\x00" // 24-bits | 100 "\x18\x00" // 24-bits |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 blob.resize(blob.size() + 8); | 137 blob.resize(blob.size() + 8); |
| 141 uint32 total_size = id_list_size + 8; | 138 uint32 total_size = id_list_size + 8; |
| 142 memcpy(&blob[blob.size() - 8], &total_size, 4); | 139 memcpy(&blob[blob.size() - 8], &total_size, 4); |
| 143 uint32 sort_index = i; | 140 uint32 sort_index = i; |
| 144 memcpy(&blob[blob.size() - 4], &sort_index, 4); | 141 memcpy(&blob[blob.size() - 4], &sort_index, 4); |
| 145 blob.resize(blob.size() + id_list_size); | 142 blob.resize(blob.size() + id_list_size); |
| 146 memcpy(&blob[blob.size() - id_list_size], id_list, id_list_size); | 143 memcpy(&blob[blob.size() - id_list_size], id_list, id_list_size); |
| 147 ILFree(id_list_full); | 144 ILFree(id_list_full); |
| 148 } | 145 } |
| 149 | 146 |
| 150 string16 key_path = kIEFavoritesOrderKey; | 147 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
| 151 if (!path.empty()) | 148 if (!path.empty()) |
| 152 key_path += L"\\" + path; | 149 key_path += L"\\" + path; |
| 153 base::win::RegKey key; | 150 base::win::RegKey key; |
| 154 if (key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE) != | 151 if (key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE) != |
| 155 ERROR_SUCCESS) { | 152 ERROR_SUCCESS) { |
| 156 return false; | 153 return false; |
| 157 } | 154 } |
| 158 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != | 155 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != |
| 159 ERROR_SUCCESS) { | 156 ERROR_SUCCESS) { |
| 160 return false; | 157 return false; |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 | 405 |
| 409 } // namespace | 406 } // namespace |
| 410 | 407 |
| 411 // These tests need to be browser tests in order to be able to run the OOP | 408 // These tests need to be browser tests in order to be able to run the OOP |
| 412 // import (via ExternalProcessImporterHost) which launches a utility process. | 409 // import (via ExternalProcessImporterHost) which launches a utility process. |
| 413 class IEImporterBrowserTest : public InProcessBrowserTest { | 410 class IEImporterBrowserTest : public InProcessBrowserTest { |
| 414 protected: | 411 protected: |
| 415 virtual void SetUp() OVERRIDE { | 412 virtual void SetUp() OVERRIDE { |
| 416 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 413 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 417 | 414 |
| 418 // Turn the override on for this process and flag child processes that they | 415 // Generate a random registry key to be used by this process and its child |
| 419 // should do so as well. | 416 // processes instead of the default. |
| 420 ASSERT_TRUE(test_registry_overrider_.SetRegistryOverride()); | 417 ASSERT_TRUE(test_registry_overrider_.SetTestRegistryOverride()); |
| 421 | 418 |
| 422 // This will launch the browser test and thus needs to happen last. | 419 // This will launch the browser test and thus needs to happen last. |
| 423 InProcessBrowserTest::SetUp(); | 420 InProcessBrowserTest::SetUp(); |
| 424 } | 421 } |
| 425 | 422 |
| 426 base::ScopedTempDir temp_dir_; | 423 base::ScopedTempDir temp_dir_; |
| 427 IEImporterTestRegistryOverrider test_registry_overrider_; | 424 IEImporterTestRegistryOverrider test_registry_overrider_; |
| 428 }; | 425 }; |
| 429 | 426 |
| 430 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { | 427 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // number_of_items = 1, size_of_item = 16, size_of_shid is too big. | 546 // number_of_items = 1, size_of_item = 16, size_of_shid is too big. |
| 550 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | 547 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
| 551 "\x01\x00\x00\x00" | 548 "\x01\x00\x00\x00" |
| 552 "\x10\x00\x00\x00\x00\x00\x00\x00" | 549 "\x10\x00\x00\x00\x00\x00\x00\x00" |
| 553 "\x06\x00\x00\x00" "\x00\x00\x00\x00", 36}, | 550 "\x06\x00\x00\x00" "\x00\x00\x00\x00", 36}, |
| 554 }; | 551 }; |
| 555 | 552 |
| 556 // Verify malformed registry data are safely ignored and alphabetical | 553 // Verify malformed registry data are safely ignored and alphabetical |
| 557 // sort is performed. | 554 // sort is performed. |
| 558 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { | 555 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { |
| 556 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
| 559 base::win::RegKey key; | 557 base::win::RegKey key; |
| 560 ASSERT_EQ(ERROR_SUCCESS, | 558 ASSERT_EQ(ERROR_SUCCESS, |
| 561 key.Create(HKEY_CURRENT_USER, kIEFavoritesOrderKey, KEY_WRITE)); | 559 key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE)); |
| 562 ASSERT_EQ(ERROR_SUCCESS, | 560 ASSERT_EQ(ERROR_SUCCESS, |
| 563 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, | 561 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, |
| 564 REG_BINARY)); | 562 REG_BINARY)); |
| 565 | 563 |
| 566 // Starts to import the above settings. | 564 // Starts to import the above settings. |
| 567 // Deletes itself. | 565 // Deletes itself. |
| 568 // TODO(gab): Use ExternalProcessImporterHost on Windows. | 566 // TODO(gab): Use ExternalProcessImporterHost on Windows. |
| 569 ImporterHost* host = new ImporterHost; | 567 ImporterHost* host = new ImporterHost; |
| 570 MalformedFavoritesRegistryTestObserver* observer = | 568 MalformedFavoritesRegistryTestObserver* observer = |
| 571 new MalformedFavoritesRegistryTestObserver(); | 569 new MalformedFavoritesRegistryTestObserver(); |
| 572 host->SetObserver(observer); | 570 host->SetObserver(observer); |
| 573 | 571 |
| 574 importer::SourceProfile source_profile; | 572 importer::SourceProfile source_profile; |
| 575 source_profile.importer_type = importer::TYPE_IE; | 573 source_profile.importer_type = importer::TYPE_IE; |
| 576 source_profile.source_path = temp_dir_.path(); | 574 source_profile.source_path = temp_dir_.path(); |
| 577 | 575 |
| 578 host->StartImportSettings( | 576 host->StartImportSettings( |
| 579 source_profile, | 577 source_profile, |
| 580 browser()->profile(), | 578 browser()->profile(), |
| 581 importer::FAVORITES, | 579 importer::FAVORITES, |
| 582 observer); | 580 observer); |
| 583 MessageLoop::current()->Run(); | 581 MessageLoop::current()->Run(); |
| 584 } | 582 } |
| 585 } | 583 } |
| OLD | NEW |