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 | |
419 // should do so as well. | |
420 ASSERT_TRUE(test_registry_overrider_.SetRegistryOverride()); | |
421 | |
422 // This will launch the browser test and thus needs to happen last. | 415 // This will launch the browser test and thus needs to happen last. |
423 InProcessBrowserTest::SetUp(); | 416 InProcessBrowserTest::SetUp(); |
424 } | 417 } |
425 | 418 |
426 base::ScopedTempDir temp_dir_; | 419 base::ScopedTempDir temp_dir_; |
| 420 |
| 421 // Overrides the default registry key for IE's favorites order blob. |
427 IEImporterTestRegistryOverrider test_registry_overrider_; | 422 IEImporterTestRegistryOverrider test_registry_overrider_; |
428 }; | 423 }; |
429 | 424 |
430 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { | 425 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { |
431 // Sets up a favorites folder. | 426 // Sets up a favorites folder. |
432 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); | 427 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
433 CreateDirectory(path.value().c_str(), NULL); | 428 CreateDirectory(path.value().c_str(), NULL); |
434 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); | 429 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); |
435 base::FilePath links_path = path.AppendASCII("Links"); | 430 base::FilePath links_path = path.AppendASCII("Links"); |
436 CreateDirectory(links_path.value().c_str(), NULL); | 431 CreateDirectory(links_path.value().c_str(), NULL); |
(...skipping 112 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. | 544 // 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" | 545 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
551 "\x01\x00\x00\x00" | 546 "\x01\x00\x00\x00" |
552 "\x10\x00\x00\x00\x00\x00\x00\x00" | 547 "\x10\x00\x00\x00\x00\x00\x00\x00" |
553 "\x06\x00\x00\x00" "\x00\x00\x00\x00", 36}, | 548 "\x06\x00\x00\x00" "\x00\x00\x00\x00", 36}, |
554 }; | 549 }; |
555 | 550 |
556 // Verify malformed registry data are safely ignored and alphabetical | 551 // Verify malformed registry data are safely ignored and alphabetical |
557 // sort is performed. | 552 // sort is performed. |
558 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { | 553 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { |
| 554 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
559 base::win::RegKey key; | 555 base::win::RegKey key; |
560 ASSERT_EQ(ERROR_SUCCESS, | 556 ASSERT_EQ(ERROR_SUCCESS, |
561 key.Create(HKEY_CURRENT_USER, kIEFavoritesOrderKey, KEY_WRITE)); | 557 key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE)); |
562 ASSERT_EQ(ERROR_SUCCESS, | 558 ASSERT_EQ(ERROR_SUCCESS, |
563 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, | 559 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, |
564 REG_BINARY)); | 560 REG_BINARY)); |
565 | 561 |
566 // Starts to import the above settings. | 562 // Starts to import the above settings. |
567 // Deletes itself. | 563 // Deletes itself. |
568 // TODO(gab): Use ExternalProcessImporterHost on Windows. | 564 // TODO(gab): Use ExternalProcessImporterHost on Windows. |
569 ImporterHost* host = new ImporterHost; | 565 ImporterHost* host = new ImporterHost; |
570 MalformedFavoritesRegistryTestObserver* observer = | 566 MalformedFavoritesRegistryTestObserver* observer = |
571 new MalformedFavoritesRegistryTestObserver(); | 567 new MalformedFavoritesRegistryTestObserver(); |
572 host->SetObserver(observer); | 568 host->SetObserver(observer); |
573 | 569 |
574 importer::SourceProfile source_profile; | 570 importer::SourceProfile source_profile; |
575 source_profile.importer_type = importer::TYPE_IE; | 571 source_profile.importer_type = importer::TYPE_IE; |
576 source_profile.source_path = temp_dir_.path(); | 572 source_profile.source_path = temp_dir_.path(); |
577 | 573 |
578 host->StartImportSettings( | 574 host->StartImportSettings( |
579 source_profile, | 575 source_profile, |
580 browser()->profile(), | 576 browser()->profile(), |
581 importer::FAVORITES, | 577 importer::FAVORITES, |
582 observer); | 578 observer); |
583 MessageLoop::current()->Run(); | 579 MessageLoop::current()->Run(); |
584 } | 580 } |
585 } | 581 } |
OLD | NEW |