Remove aura enum from DesktopMediaID to fix desktop mirroring audio (CrOS).
[chromium-blink-merge.git] / chrome / browser / importer / ie_importer_browsertest_win.cc
blobc1a8eb440e7c684da6b91dfc0c201e064951ccdd
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
3 // found in the LICENSE file.
5 // The order of these includes is important.
6 #include <windows.h>
7 #include <unknwn.h>
8 #include <intshcut.h>
9 #include <propvarutil.h>
10 #include <shlguid.h>
11 #include <shlobj.h>
12 #include <urlhist.h>
14 #include <algorithm>
15 #include <vector>
17 #include "base/bind.h"
18 #include "base/compiler_specific.h"
19 #include "base/files/file_util.h"
20 #include "base/files/scoped_temp_dir.h"
21 #include "base/message_loop/message_loop.h"
22 #include "base/stl_util.h"
23 #include "base/strings/string16.h"
24 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h"
26 #include "base/win/registry.h"
27 #include "base/win/scoped_comptr.h"
28 #include "base/win/scoped_propvariant.h"
29 #include "base/win/windows_version.h"
30 #include "chrome/browser/importer/external_process_importer_host.h"
31 #include "chrome/browser/importer/importer_progress_observer.h"
32 #include "chrome/browser/importer/importer_unittest_utils.h"
33 #include "chrome/browser/ui/browser.h"
34 #include "chrome/common/chrome_paths.h"
35 #include "chrome/common/importer/ie_importer_test_registry_overrider_win.h"
36 #include "chrome/common/importer/ie_importer_utils_win.h"
37 #include "chrome/common/importer/imported_bookmark_entry.h"
38 #include "chrome/common/importer/importer_bridge.h"
39 #include "chrome/common/importer/importer_data_types.h"
40 #include "chrome/test/base/in_process_browser_test.h"
41 #include "chrome/test/base/testing_profile.h"
42 #include "components/autofill/core/common/password_form.h"
43 #include "components/favicon_base/favicon_usage_data.h"
44 #include "components/os_crypt/ie7_password_win.h"
45 #include "components/search_engines/template_url.h"
46 #include "testing/gtest/include/gtest/gtest.h"
48 namespace {
50 const BookmarkInfo kIEBookmarks[] = {
51 {true, 2, {"Links", "SubFolderOfLinks"},
52 L"SubLink",
53 "http://www.links-sublink.com/"},
54 {true, 1, {"Links"},
55 L"TheLink",
56 "http://www.links-thelink.com/"},
57 {false, 0, {},
58 L"Google Home Page",
59 "http://www.google.com/"},
60 {false, 0, {},
61 L"TheLink",
62 "http://www.links-thelink.com/"},
63 {false, 1, {"SubFolder"},
64 L"Title",
65 "http://www.link.com/"},
66 {false, 0, {},
67 L"WithPortAndQuery",
68 "http://host:8080/cgi?q=query"},
69 {false, 1, {"a"},
70 L"\x4E2D\x6587",
71 "http://chinese-title-favorite/"},
72 {false, 0, {},
73 L"SubFolder",
74 "http://www.subfolder.com/"},
77 const BookmarkInfo kIESortedBookmarks[] = {
78 {false, 0, {}, L"a", "http://www.google.com/0"},
79 {false, 1, {"b"}, L"a", "http://www.google.com/1"},
80 {false, 1, {"b"}, L"b", "http://www.google.com/2"},
81 {false, 0, {}, L"c", "http://www.google.com/3"},
84 const base::char16 kIEIdentifyUrl[] =
85 L"http://A79029D6-753E-4e27-B807-3D46AB1545DF.com:8080/path?key=value";
86 const base::char16 kIEIdentifyTitle[] =
87 L"Unittest GUID";
88 const base::char16 kIECacheItemUrl[] =
89 L"http://B2EF40C8-2569-4D7E-97EA-BAD9DF468D9C.com";
90 const base::char16 kIECacheItemTitle[] =
91 L"Unittest Cache Item GUID";
93 const base::char16 kFaviconStreamSuffix[] = L"url:favicon:$DATA";
94 const char kDummyFaviconImageData[] =
95 "\x42\x4D" // Magic signature 'BM'
96 "\x1E\x00\x00\x00" // File size
97 "\x00\x00\x00\x00" // Reserved
98 "\x1A\x00\x00\x00" // Offset of the pixel data
99 "\x0C\x00\x00\x00" // Header Size
100 "\x01\x00\x01\x00" // Size: 1x1
101 "\x01\x00" // Reserved
102 "\x18\x00" // 24-bits
103 "\x00\xFF\x00\x00"; // The pixel
105 struct FaviconGroup {
106 const base::char16* favicon_url;
107 const base::char16* site_url[2];
110 const FaviconGroup kIEFaviconGroup[2] = {
111 {L"http://www.google.com/favicon.ico",
112 {L"http://www.google.com/",
113 L"http://www.subfolder.com/"}},
114 {L"http://example.com/favicon.ico",
115 {L"http://host:8080/cgi?q=query",
116 L"http://chinese-title-favorite/"}},
119 bool CreateOrderBlob(const base::FilePath& favorites_folder,
120 const base::string16& path,
121 const std::vector<base::string16>& entries) {
122 if (entries.size() > 255)
123 return false;
125 // Create a binary sequence for setting a specific order of favorites.
126 // The format depends on the version of Shell32.dll, so we cannot embed
127 // a binary constant here.
128 std::vector<uint8> blob(20, 0);
129 blob[16] = static_cast<uint8>(entries.size());
131 for (size_t i = 0; i < entries.size(); ++i) {
132 PIDLIST_ABSOLUTE id_list_full = ILCreateFromPath(
133 favorites_folder.Append(path).Append(entries[i]).value().c_str());
134 PUITEMID_CHILD id_list = ILFindLastID(id_list_full);
135 // Include the trailing zero-length item id. Don't include the single
136 // element array.
137 size_t id_list_size = id_list->mkid.cb + sizeof(id_list->mkid.cb);
139 blob.resize(blob.size() + 8);
140 uint32 total_size = id_list_size + 8;
141 memcpy(&blob[blob.size() - 8], &total_size, 4);
142 uint32 sort_index = i;
143 memcpy(&blob[blob.size() - 4], &sort_index, 4);
144 blob.resize(blob.size() + id_list_size);
145 memcpy(&blob[blob.size() - id_list_size], id_list, id_list_size);
146 ILFree(id_list_full);
149 base::string16 key_path(importer::GetIEFavoritesOrderKey());
150 if (!path.empty())
151 key_path += L"\\" + path;
152 base::win::RegKey key;
153 if (key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE) !=
154 ERROR_SUCCESS) {
155 return false;
157 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) !=
158 ERROR_SUCCESS) {
159 return false;
161 return true;
164 bool CreateUrlFileWithFavicon(const base::FilePath& file,
165 const base::string16& url,
166 const base::string16& favicon_url) {
167 base::win::ScopedComPtr<IUniformResourceLocator> locator;
168 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL,
169 CLSCTX_INPROC_SERVER);
170 if (FAILED(result))
171 return false;
172 base::win::ScopedComPtr<IPersistFile> persist_file;
173 result = persist_file.QueryFrom(locator.get());
174 if (FAILED(result))
175 return false;
176 result = locator->SetURL(url.c_str(), 0);
177 if (FAILED(result))
178 return false;
180 // Write favicon url if specified.
181 if (!favicon_url.empty()) {
182 base::win::ScopedComPtr<IPropertySetStorage> property_set_storage;
183 if (FAILED(property_set_storage.QueryFrom(locator.get())))
184 return false;
185 base::win::ScopedComPtr<IPropertyStorage> property_storage;
186 if (FAILED(property_set_storage->Open(FMTID_Intshcut,
187 STGM_WRITE,
188 property_storage.Receive()))) {
189 return false;
191 PROPSPEC properties[] = {{PRSPEC_PROPID, {PID_IS_ICONFILE}}};
192 // WriteMultiple takes an array of PROPVARIANTs, but since this code only
193 // needs an array of size 1: a pointer to |pv_icon| is equivalent.
194 base::win::ScopedPropVariant pv_icon;
195 if (FAILED(InitPropVariantFromString(favicon_url.c_str(),
196 pv_icon.Receive())) ||
197 FAILED(
198 property_storage->WriteMultiple(1, properties, pv_icon.ptr(), 0))) {
199 return false;
203 // Save the .url file.
204 result = persist_file->Save(file.value().c_str(), TRUE);
205 if (FAILED(result))
206 return false;
208 // Write dummy favicon image data in NTFS alternate data stream.
209 return favicon_url.empty() || (base::WriteFile(
210 file.ReplaceExtension(kFaviconStreamSuffix), kDummyFaviconImageData,
211 sizeof kDummyFaviconImageData) != -1);
214 bool CreateUrlFile(const base::FilePath& file, const base::string16& url) {
215 return CreateUrlFileWithFavicon(file, url, base::string16());
218 class TestObserver : public ProfileWriter,
219 public importer::ImporterProgressObserver {
220 public:
221 enum TestIEVersion {
222 IE6,
223 IE7,
226 explicit TestObserver(uint16 importer_items, TestIEVersion ie_version)
227 : ProfileWriter(NULL),
228 bookmark_count_(0),
229 history_count_(0),
230 password_count_(0),
231 favicon_count_(0),
232 homepage_count_(0),
233 ie7_password_count_(0),
234 importer_items_(importer_items),
235 ie_version_(ie_version) {
238 // importer::ImporterProgressObserver:
239 void ImportStarted() override {}
240 void ImportItemStarted(importer::ImportItem item) override {}
241 void ImportItemEnded(importer::ImportItem item) override {}
242 void ImportEnded() override {
243 base::MessageLoop::current()->Quit();
244 if (importer_items_ & importer::FAVORITES) {
245 EXPECT_EQ(arraysize(kIEBookmarks), bookmark_count_);
246 EXPECT_EQ(arraysize(kIEFaviconGroup), favicon_count_);
248 if (importer_items_ & importer::HISTORY)
249 EXPECT_EQ(2, history_count_);
250 if (importer_items_ & importer::HOME_PAGE)
251 EXPECT_EQ(1, homepage_count_);
252 if ((importer_items_ & importer::PASSWORDS) && (ie_version_ == IE7))
253 EXPECT_EQ(1, ie7_password_count_);
254 // We need to test the IE6 password importer code.
255 // https://crbug.com/257100
256 // EXPECT_EQ(1, password_count_);
259 // ProfileWriter:
260 bool BookmarkModelIsLoaded() const override {
261 // Profile is ready for writing.
262 return true;
265 bool TemplateURLServiceIsLoaded() const override {
266 return true;
269 void AddPasswordForm(const autofill::PasswordForm& form) override {
270 // Importer should obtain this password form only.
271 EXPECT_EQ(GURL("http://localhost:8080/security/index.htm"), form.origin);
272 EXPECT_EQ("http://localhost:8080/", form.signon_realm);
273 EXPECT_EQ(L"user", form.username_element);
274 EXPECT_EQ(L"1", form.username_value);
275 EXPECT_EQ(L"", form.password_element);
276 EXPECT_EQ(L"2", form.password_value);
277 EXPECT_EQ("", form.action.spec());
278 ++password_count_;
281 void AddHistoryPage(const history::URLRows& page,
282 history::VisitSource visit_source) override {
283 bool cache_item_found = false;
284 bool history_item_found = false;
285 // Importer should read the specified URL.
286 for (size_t i = 0; i < page.size(); ++i) {
287 if (page[i].title() == kIEIdentifyTitle &&
288 page[i].url() == GURL(kIEIdentifyUrl)) {
289 EXPECT_FALSE(page[i].hidden());
290 history_item_found = true;
291 ++history_count_;
293 if (page[i].title() == kIECacheItemTitle &&
294 page[i].url() == GURL(kIECacheItemUrl)) {
295 EXPECT_TRUE(page[i].hidden());
296 cache_item_found = true;
297 ++history_count_;
300 EXPECT_TRUE(history_item_found);
301 EXPECT_TRUE(cache_item_found);
302 EXPECT_EQ(history::SOURCE_IE_IMPORTED, visit_source);
305 void AddBookmarks(const std::vector<ImportedBookmarkEntry>& bookmarks,
306 const base::string16& top_level_folder_name) override {
307 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kIEBookmarks));
308 // Importer should import the IE Favorites folder the same as the list,
309 // in the same order.
310 for (size_t i = 0; i < bookmarks.size(); ++i) {
311 EXPECT_NO_FATAL_FAILURE(
312 TestEqualBookmarkEntry(bookmarks[i],
313 kIEBookmarks[bookmark_count_])) << i;
314 ++bookmark_count_;
318 virtual void AddKeyword(std::vector<TemplateURL*> template_url,
319 int default_keyword_index) {
320 // TODO(jcampan): bug 1169230: we should test keyword importing for IE.
321 // In order to do that we'll probably need to mock the Windows registry.
322 NOTREACHED();
323 STLDeleteContainerPointers(template_url.begin(), template_url.end());
326 void AddFavicons(const favicon_base::FaviconUsageDataList& usage) override {
327 // Importer should group the favicon information for each favicon URL.
328 for (size_t i = 0; i < arraysize(kIEFaviconGroup); ++i) {
329 GURL favicon_url(kIEFaviconGroup[i].favicon_url);
330 std::set<GURL> urls;
331 for (size_t j = 0; j < arraysize(kIEFaviconGroup[i].site_url); ++j)
332 urls.insert(GURL(kIEFaviconGroup[i].site_url[j]));
334 SCOPED_TRACE(testing::Message() << "Expected Favicon: " << favicon_url);
336 bool expected_favicon_url_found = false;
337 for (size_t j = 0; j < usage.size(); ++j) {
338 if (usage[j].favicon_url == favicon_url) {
339 EXPECT_EQ(urls, usage[j].urls);
340 expected_favicon_url_found = true;
341 break;
344 EXPECT_TRUE(expected_favicon_url_found);
347 favicon_count_ += usage.size();
350 void AddIE7PasswordInfo(const IE7PasswordInfo& info) override {
351 // This function also gets called for the IEImporter test. Ignore.
352 if (ie_version_ == IE7) {
353 EXPECT_EQ(L"Test1", info.url_hash);
354 EXPECT_EQ(1, info.encrypted_data[0]);
355 EXPECT_EQ(4, info.encrypted_data.size());
356 ++ie7_password_count_;
360 void AddHomepage(const GURL& homepage) override {
361 EXPECT_EQ(homepage.spec(), "http://www.test.com/");
362 ++homepage_count_;
365 private:
366 ~TestObserver() override {}
368 size_t bookmark_count_;
369 size_t history_count_;
370 size_t password_count_;
371 size_t favicon_count_;
372 size_t homepage_count_;
373 size_t ie7_password_count_;
374 uint16 importer_items_;
375 TestIEVersion ie_version_;
378 class MalformedFavoritesRegistryTestObserver
379 : public ProfileWriter,
380 public importer::ImporterProgressObserver {
381 public:
382 MalformedFavoritesRegistryTestObserver() : ProfileWriter(NULL) {
383 bookmark_count_ = 0;
386 // importer::ImporterProgressObserver:
387 void ImportStarted() override {}
388 void ImportItemStarted(importer::ImportItem item) override {}
389 void ImportItemEnded(importer::ImportItem item) override {}
390 void ImportEnded() override {
391 base::MessageLoop::current()->Quit();
392 EXPECT_EQ(arraysize(kIESortedBookmarks), bookmark_count_);
395 // ProfileWriter:
396 bool BookmarkModelIsLoaded() const override { return true; }
397 bool TemplateURLServiceIsLoaded() const override { return true; }
399 void AddPasswordForm(const autofill::PasswordForm& form) override {}
400 void AddHistoryPage(const history::URLRows& page,
401 history::VisitSource visit_source) override {}
402 void AddKeywords(ScopedVector<TemplateURL> template_urls,
403 bool unique_on_host_and_path) override {}
404 void AddBookmarks(const std::vector<ImportedBookmarkEntry>& bookmarks,
405 const base::string16& top_level_folder_name) override {
406 ASSERT_LE(bookmark_count_ + bookmarks.size(),
407 arraysize(kIESortedBookmarks));
408 for (size_t i = 0; i < bookmarks.size(); ++i) {
409 EXPECT_NO_FATAL_FAILURE(
410 TestEqualBookmarkEntry(bookmarks[i],
411 kIESortedBookmarks[bookmark_count_])) << i;
412 ++bookmark_count_;
416 private:
417 ~MalformedFavoritesRegistryTestObserver() override {}
419 size_t bookmark_count_;
422 } // namespace
424 // These tests need to be browser tests in order to be able to run the OOP
425 // import (via ExternalProcessImporterHost) which launches a utility process.
426 class IEImporterBrowserTest : public InProcessBrowserTest {
427 protected:
428 void SetUp() override {
429 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
431 // This will launch the browser test and thus needs to happen last.
432 InProcessBrowserTest::SetUp();
435 base::ScopedTempDir temp_dir_;
437 // Overrides the default registry key for IE registry keys like favorites,
438 // settings, password store, etc.
439 IEImporterTestRegistryOverrider test_registry_overrider_;
442 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) {
443 // Sets up a favorites folder.
444 base::FilePath path = temp_dir_.path().AppendASCII("Favorites");
445 CreateDirectory(path.value().c_str(), NULL);
446 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL);
447 base::FilePath links_path = path.AppendASCII("Links");
448 CreateDirectory(links_path.value().c_str(), NULL);
449 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(),
450 NULL);
451 CreateDirectory(path.AppendASCII("\x0061").value().c_str(), NULL);
452 ASSERT_TRUE(CreateUrlFileWithFavicon(path.AppendASCII("Google Home Page.url"),
453 L"http://www.google.com/",
454 L"http://www.google.com/favicon.ico"));
455 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("SubFolder\\Title.url"),
456 L"http://www.link.com/"));
457 ASSERT_TRUE(CreateUrlFileWithFavicon(path.AppendASCII("SubFolder.url"),
458 L"http://www.subfolder.com/",
459 L"http://www.google.com/favicon.ico"));
460 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("TheLink.url"),
461 L"http://www.links-thelink.com/"));
462 ASSERT_TRUE(CreateUrlFileWithFavicon(path.AppendASCII("WithPortAndQuery.url"),
463 L"http://host:8080/cgi?q=query",
464 L"http://example.com/favicon.ico"));
465 ASSERT_TRUE(CreateUrlFileWithFavicon(
466 path.AppendASCII("\x0061").Append(L"\x4E2D\x6587.url"),
467 L"http://chinese-title-favorite/",
468 L"http://example.com/favicon.ico"));
469 ASSERT_TRUE(CreateUrlFile(links_path.AppendASCII("TheLink.url"),
470 L"http://www.links-thelink.com/"));
471 ASSERT_TRUE(CreateUrlFile(
472 links_path.AppendASCII("SubFolderOfLinks").AppendASCII("SubLink.url"),
473 L"http://www.links-sublink.com/"));
474 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("IEDefaultLink.url"),
475 L"http://go.microsoft.com/fwlink/?linkid=140813"));
476 base::WriteFile(path.AppendASCII("InvalidUrlFile.url"), "x", 1);
477 base::WriteFile(path.AppendASCII("PlainTextFile.txt"), "x", 1);
479 const base::char16* root_links[] = {
480 L"Links",
481 L"Google Home Page.url",
482 L"TheLink.url",
483 L"SubFolder",
484 L"WithPortAndQuery.url",
485 L"a",
486 L"SubFolder.url",
488 ASSERT_TRUE(CreateOrderBlob(
489 base::FilePath(path), L"",
490 std::vector<base::string16>(root_links,
491 root_links + arraysize(root_links))));
493 // Sets up a special history link.
494 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2;
495 ASSERT_EQ(S_OK, url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL,
496 CLSCTX_INPROC_SERVER));
497 // Usage of ADDURL_ADDTOHISTORYANDCACHE and ADDURL_ADDTOCACHE flags
498 // is explained in the article:
499 // http://msdn.microsoft.com/ru-ru/aa767730
500 ASSERT_EQ(S_OK, url_history_stg2->AddUrl(kIEIdentifyUrl, kIEIdentifyTitle,
501 ADDURL_ADDTOHISTORYANDCACHE));
502 ASSERT_EQ(S_OK, url_history_stg2->AddUrl(kIECacheItemUrl, kIECacheItemTitle,
503 ADDURL_ADDTOCACHE));
505 // Starts to import the above settings.
506 // Deletes itself.
507 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
508 TestObserver* observer = new TestObserver(
509 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES,
510 TestObserver::IE6);
511 host->set_observer(observer);
513 importer::SourceProfile source_profile;
514 source_profile.importer_type = importer::TYPE_IE;
515 source_profile.source_path = temp_dir_.path();
517 host->StartImportSettings(
518 source_profile,
519 browser()->profile(),
520 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES,
521 observer);
522 base::MessageLoop::current()->Run();
524 // Cleans up.
525 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0);
526 url_history_stg2->DeleteUrl(kIECacheItemUrl, 0);
527 url_history_stg2.Release();
530 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest,
531 IEImporterMalformedFavoritesRegistry) {
532 // Sets up a favorites folder.
533 base::FilePath path = temp_dir_.path().AppendASCII("Favorites");
534 CreateDirectory(path.value().c_str(), NULL);
535 CreateDirectory(path.AppendASCII("b").value().c_str(), NULL);
536 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("a.url"),
537 L"http://www.google.com/0"));
538 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("a.url"),
539 L"http://www.google.com/1"));
540 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("b.url"),
541 L"http://www.google.com/2"));
542 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("c.url"),
543 L"http://www.google.com/3"));
545 struct BadBinaryData {
546 const char* data;
547 int length;
549 static const BadBinaryData kBadBinary[] = {
550 // number_of_items field is truncated
551 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
552 "\x00\xff\xff\xff", 17},
553 // number_of_items = 0xffff, but the byte sequence is too short.
554 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
555 "\xff\xff\x00\x00", 20},
556 // number_of_items = 1, size_of_item is too big.
557 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
558 "\x01\x00\x00\x00"
559 "\xff\xff\x00\x00\x00\x00\x00\x00"
560 "\x00\x00\x00\x00", 32},
561 // number_of_items = 1, size_of_item = 16, size_of_shid is too big.
562 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
563 "\x01\x00\x00\x00"
564 "\x10\x00\x00\x00\x00\x00\x00\x00"
565 "\xff\x7f\x00\x00" "\x00\x00\x00\x00", 36},
566 // number_of_items = 1, size_of_item = 16, size_of_shid is too big.
567 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
568 "\x01\x00\x00\x00"
569 "\x10\x00\x00\x00\x00\x00\x00\x00"
570 "\x06\x00\x00\x00" "\x00\x00\x00\x00", 36},
573 // Verify malformed registry data are safely ignored and alphabetical
574 // sort is performed.
575 for (size_t i = 0; i < arraysize(kBadBinary); ++i) {
576 base::string16 key_path(importer::GetIEFavoritesOrderKey());
577 base::win::RegKey key;
578 ASSERT_EQ(ERROR_SUCCESS,
579 key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE));
580 ASSERT_EQ(ERROR_SUCCESS,
581 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length,
582 REG_BINARY));
584 // Starts to import the above settings.
585 // Deletes itself.
586 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
587 MalformedFavoritesRegistryTestObserver* observer =
588 new MalformedFavoritesRegistryTestObserver();
589 host->set_observer(observer);
591 importer::SourceProfile source_profile;
592 source_profile.importer_type = importer::TYPE_IE;
593 source_profile.source_path = temp_dir_.path();
595 host->StartImportSettings(
596 source_profile,
597 browser()->profile(),
598 importer::FAVORITES,
599 observer);
600 base::MessageLoop::current()->Run();
604 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IE7ImporterPasswordsTest) {
605 // Starts to import the IE7 passwords.
606 // Deletes itself.
607 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
608 TestObserver* observer = new TestObserver(importer::PASSWORDS,
609 TestObserver::IE7);
610 host->set_observer(observer);
612 base::string16 key_path(importer::GetIE7PasswordsKey());
613 base::win::RegKey key;
614 ASSERT_EQ(ERROR_SUCCESS,
615 key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE));
616 key.WriteValue(L"Test1", 1);
618 importer::SourceProfile source_profile;
619 source_profile.importer_type = importer::TYPE_IE;
620 source_profile.source_path = temp_dir_.path();
622 host->StartImportSettings(
623 source_profile,
624 browser()->profile(),
625 importer::PASSWORDS,
626 observer);
627 base::MessageLoop::current()->Run();
630 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporterHomePageTest) {
631 // Starts to import the IE home page.
632 // Deletes itself.
633 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
634 TestObserver* observer = new TestObserver(importer::HOME_PAGE,
635 TestObserver::IE6);
636 host->set_observer(observer);
638 base::string16 key_path(importer::GetIESettingsKey());
639 base::win::RegKey key;
640 ASSERT_EQ(ERROR_SUCCESS,
641 key.Create(HKEY_CURRENT_USER, key_path.c_str(), KEY_WRITE));
642 key.WriteValue(L"Start Page", L"http://www.test.com/");
644 importer::SourceProfile source_profile;
645 source_profile.importer_type = importer::TYPE_IE;
646 source_profile.source_path = temp_dir_.path();
648 host->StartImportSettings(
649 source_profile,
650 browser()->profile(),
651 importer::HOME_PAGE,
652 observer);
653 base::MessageLoop::current()->Run();