OLD | NEW |
1 // Copyright (c) 2012 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 #include "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 // The order of these includes is important. | 5 // The order of these includes is important. |
8 #include <windows.h> | 6 #include <windows.h> |
9 #include <unknwn.h> | 7 #include <unknwn.h> |
10 #include <intshcut.h> | 8 #include <intshcut.h> |
11 #include <shlguid.h> | 9 #include <shlguid.h> |
12 #include <urlhist.h> | 10 #include <urlhist.h> |
13 #include <shlobj.h> | 11 #include <shlobj.h> |
14 #include <propvarutil.h> | 12 #include <propvarutil.h> |
15 | 13 |
16 #include <algorithm> | 14 #include <algorithm> |
17 #include <vector> | 15 #include <vector> |
18 | 16 |
19 #include "base/bind.h" | 17 #include "base/bind.h" |
20 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
21 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 20 #include "base/files/scoped_temp_dir.h" |
22 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
23 #include "base/path_service.h" | 22 #include "base/path_service.h" |
24 #include "base/stl_util.h" | 23 #include "base/stl_util.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_com_initializer.h" | |
29 #include "base/win/scoped_comptr.h" | 28 #include "base/win/scoped_comptr.h" |
30 #include "base/win/scoped_propvariant.h" | 29 #include "base/win/scoped_propvariant.h" |
31 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
32 #include "chrome/browser/history/history_types.h" | 31 #include "chrome/browser/history/history_types.h" |
33 #include "chrome/browser/importer/ie_importer.h" | 32 #include "chrome/browser/importer/ie_importer.h" |
34 #include "chrome/browser/importer/importer_bridge.h" | 33 #include "chrome/browser/importer/importer_bridge.h" |
35 #include "chrome/browser/importer/importer_data_types.h" | 34 #include "chrome/browser/importer/importer_data_types.h" |
36 #include "chrome/browser/importer/importer_host.h" | 35 #include "chrome/browser/importer/importer_host.h" |
37 #include "chrome/browser/importer/importer_progress_observer.h" | 36 #include "chrome/browser/importer/importer_progress_observer.h" |
38 #include "chrome/browser/importer/importer_unittest_utils.h" | 37 #include "chrome/browser/importer/importer_unittest_utils.h" |
39 #include "chrome/browser/importer/pstore_declarations.h" | 38 #include "chrome/browser/importer/pstore_declarations.h" |
40 #include "chrome/browser/search_engines/template_url.h" | 39 #include "chrome/browser/search_engines/template_url.h" |
| 40 #include "chrome/browser/ui/browser.h" |
41 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
| 42 #include "chrome/test/base/in_process_browser_test.h" |
42 #include "chrome/test/base/testing_profile.h" | 43 #include "chrome/test/base/testing_profile.h" |
43 #include "components/webdata/encryptor/ie7_password.h" | |
44 #include "content/public/common/password_form.h" | 44 #include "content/public/common/password_form.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
48 const char16 kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; | 49 const char16 kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; |
49 const char16 kUnitTestUserOverrideSubKey[] = | 50 const char16 kUnitTestUserOverrideSubKey[] = |
50 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; | 51 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; |
51 | 52 |
52 const BookmarkInfo kIEBookmarks[] = { | 53 const BookmarkInfo kIEBookmarks[] = { |
53 {true, 2, {L"Links", L"SubFolderOfLinks"}, | 54 {true, 2, {L"Links", L"SubFolderOfLinks"}, |
54 L"SubLink", | 55 L"SubLink", |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return false; | 158 return false; |
158 } | 159 } |
159 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != | 160 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != |
160 ERROR_SUCCESS) { | 161 ERROR_SUCCESS) { |
161 return false; | 162 return false; |
162 } | 163 } |
163 return true; | 164 return true; |
164 } | 165 } |
165 | 166 |
166 bool CreateUrlFileWithFavicon(const base::FilePath& file, | 167 bool CreateUrlFileWithFavicon(const base::FilePath& file, |
167 const std::wstring& url, | 168 const string16& url, |
168 const std::wstring& favicon_url) { | 169 const string16& favicon_url) { |
169 base::win::ScopedComPtr<IUniformResourceLocator> locator; | 170 base::win::ScopedComPtr<IUniformResourceLocator> locator; |
170 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL, | 171 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL, |
171 CLSCTX_INPROC_SERVER); | 172 CLSCTX_INPROC_SERVER); |
172 if (FAILED(result)) | 173 if (FAILED(result)) |
173 return false; | 174 return false; |
174 base::win::ScopedComPtr<IPersistFile> persist_file; | 175 base::win::ScopedComPtr<IPersistFile> persist_file; |
175 result = persist_file.QueryFrom(locator); | 176 result = persist_file.QueryFrom(locator); |
176 if (FAILED(result)) | 177 if (FAILED(result)) |
177 return false; | 178 return false; |
178 result = locator->SetURL(url.c_str(), 0); | 179 result = locator->SetURL(url.c_str(), 0); |
(...skipping 26 matching lines...) Expand all Loading... |
205 result = persist_file->Save(file.value().c_str(), TRUE); | 206 result = persist_file->Save(file.value().c_str(), TRUE); |
206 if (FAILED(result)) | 207 if (FAILED(result)) |
207 return false; | 208 return false; |
208 | 209 |
209 // Write dummy favicon image data in NTFS alternate data stream. | 210 // Write dummy favicon image data in NTFS alternate data stream. |
210 return favicon_url.empty() || (file_util::WriteFile( | 211 return favicon_url.empty() || (file_util::WriteFile( |
211 file.ReplaceExtension(kFaviconStreamSuffix), kDummyFaviconImageData, | 212 file.ReplaceExtension(kFaviconStreamSuffix), kDummyFaviconImageData, |
212 sizeof kDummyFaviconImageData) != -1); | 213 sizeof kDummyFaviconImageData) != -1); |
213 } | 214 } |
214 | 215 |
215 bool CreateUrlFile(const base::FilePath& file, const std::wstring& url) { | 216 bool CreateUrlFile(const base::FilePath& file, const string16& url) { |
216 return CreateUrlFileWithFavicon(file, url, std::wstring()); | 217 return CreateUrlFileWithFavicon(file, url, string16()); |
217 } | 218 } |
218 | 219 |
219 void ClearPStoreType(IPStore* pstore, const GUID* type, const GUID* subtype) { | 220 void ClearPStoreType(IPStore* pstore, const GUID* type, const GUID* subtype) { |
220 base::win::ScopedComPtr<IEnumPStoreItems, NULL> item; | 221 base::win::ScopedComPtr<IEnumPStoreItems, NULL> item; |
221 HRESULT result = pstore->EnumItems(0, type, subtype, 0, item.Receive()); | 222 HRESULT result = pstore->EnumItems(0, type, subtype, 0, item.Receive()); |
222 if (result == PST_E_OK) { | 223 if (result == PST_E_OK) { |
223 char16* item_name; | 224 char16* item_name; |
224 while (SUCCEEDED(item->Next(1, &item_name, 0))) { | 225 while (SUCCEEDED(item->Next(1, &item_name, 0))) { |
225 pstore->DeleteItem(0, type, subtype, item_name, NULL, 0); | 226 pstore->DeleteItem(0, type, subtype, item_name, NULL, 0); |
226 CoTaskMemFree(item_name); | 227 CoTaskMemFree(item_name); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 309 } |
309 EXPECT_EQ(history::SOURCE_IE_IMPORTED, visit_source); | 310 EXPECT_EQ(history::SOURCE_IE_IMPORTED, visit_source); |
310 } | 311 } |
311 | 312 |
312 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | 313 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
313 const string16& top_level_folder_name) OVERRIDE { | 314 const string16& top_level_folder_name) OVERRIDE { |
314 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kIEBookmarks)); | 315 ASSERT_LE(bookmark_count_ + bookmarks.size(), arraysize(kIEBookmarks)); |
315 // Importer should import the IE Favorites folder the same as the list, | 316 // Importer should import the IE Favorites folder the same as the list, |
316 // in the same order. | 317 // in the same order. |
317 for (size_t i = 0; i < bookmarks.size(); ++i) { | 318 for (size_t i = 0; i < bookmarks.size(); ++i) { |
318 EXPECT_TRUE(EqualBookmarkEntry(bookmarks[i], | 319 EXPECT_NO_FATAL_FAILURE( |
319 kIEBookmarks[bookmark_count_])); | 320 TestEqualBookmarkEntry(bookmarks[i], |
| 321 kIEBookmarks[bookmark_count_])) << i; |
320 ++bookmark_count_; | 322 ++bookmark_count_; |
321 } | 323 } |
322 } | 324 } |
323 | 325 |
324 virtual void AddKeyword(std::vector<TemplateURL*> template_url, | 326 virtual void AddKeyword(std::vector<TemplateURL*> template_url, |
325 int default_keyword_index) { | 327 int default_keyword_index) { |
326 // TODO(jcampan): bug 1169230: we should test keyword importing for IE. | 328 // TODO(jcampan): bug 1169230: we should test keyword importing for IE. |
327 // In order to do that we'll probably need to mock the Windows registry. | 329 // In order to do that we'll probably need to mock the Windows registry. |
328 NOTREACHED(); | 330 NOTREACHED(); |
329 STLDeleteContainerPointers(template_url.begin(), template_url.end()); | 331 STLDeleteContainerPointers(template_url.begin(), template_url.end()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 virtual void AddPasswordForm(const content::PasswordForm& form) {} | 388 virtual void AddPasswordForm(const content::PasswordForm& form) {} |
387 virtual void AddHistoryPage(const history::URLRows& page, | 389 virtual void AddHistoryPage(const history::URLRows& page, |
388 history::VisitSource visit_source) {} | 390 history::VisitSource visit_source) {} |
389 virtual void AddKeyword(std::vector<TemplateURL*> template_url, | 391 virtual void AddKeyword(std::vector<TemplateURL*> template_url, |
390 int default_keyword_index) {} | 392 int default_keyword_index) {} |
391 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | 393 virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
392 const string16& top_level_folder_name) OVERRIDE { | 394 const string16& top_level_folder_name) OVERRIDE { |
393 ASSERT_LE(bookmark_count_ + bookmarks.size(), | 395 ASSERT_LE(bookmark_count_ + bookmarks.size(), |
394 arraysize(kIESortedBookmarks)); | 396 arraysize(kIESortedBookmarks)); |
395 for (size_t i = 0; i < bookmarks.size(); ++i) { | 397 for (size_t i = 0; i < bookmarks.size(); ++i) { |
396 EXPECT_TRUE(EqualBookmarkEntry(bookmarks[i], | 398 EXPECT_NO_FATAL_FAILURE( |
397 kIESortedBookmarks[bookmark_count_])); | 399 TestEqualBookmarkEntry(bookmarks[i], |
| 400 kIESortedBookmarks[bookmark_count_])) << i; |
398 ++bookmark_count_; | 401 ++bookmark_count_; |
399 } | 402 } |
400 } | 403 } |
401 | 404 |
402 private: | 405 private: |
403 ~MalformedFavoritesRegistryTestObserver() {} | 406 ~MalformedFavoritesRegistryTestObserver() {} |
404 | 407 |
405 size_t bookmark_count_; | 408 size_t bookmark_count_; |
406 }; | 409 }; |
407 | 410 |
408 } // namespace | 411 } // namespace |
409 | 412 |
410 class IEImporterTest : public ImporterTest { | 413 // 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. |
| 415 class IEImporterBrowserTest : public InProcessBrowserTest { |
411 protected: | 416 protected: |
412 virtual void SetUp() OVERRIDE { | 417 virtual void SetUp() OVERRIDE { |
413 ImporterTest::SetUp(); | 418 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
414 StartRegistryOverride(); | 419 StartRegistryOverride(); |
| 420 |
| 421 // This will launch the browser test and thus needs to happen last. |
| 422 InProcessBrowserTest::SetUp(); |
415 } | 423 } |
416 | 424 |
417 virtual void TearDown() OVERRIDE { | 425 virtual void TearDown() OVERRIDE { |
418 EndRegistryOverride(); | 426 EndRegistryOverride(); |
419 } | 427 } |
420 | 428 |
421 void StartRegistryOverride() { | 429 void StartRegistryOverride() { |
422 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | 430 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); |
423 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, | 431 temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, |
424 kUnitTestUserOverrideSubKey, | 432 kUnitTestUserOverrideSubKey, |
425 KEY_ALL_ACCESS); | 433 KEY_ALL_ACCESS); |
426 EXPECT_TRUE(temp_hkcu_hive_key_.Valid()); | 434 EXPECT_TRUE(temp_hkcu_hive_key_.Valid()); |
427 EXPECT_EQ(ERROR_SUCCESS, | 435 EXPECT_EQ(ERROR_SUCCESS, |
428 RegOverridePredefKey(HKEY_CURRENT_USER, | 436 RegOverridePredefKey(HKEY_CURRENT_USER, |
429 temp_hkcu_hive_key_.Handle())); | 437 temp_hkcu_hive_key_.Handle())); |
430 } | 438 } |
431 | 439 |
432 void EndRegistryOverride() { | 440 void EndRegistryOverride() { |
433 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | 441 EXPECT_EQ(ERROR_SUCCESS, RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); |
434 temp_hkcu_hive_key_.Close(); | 442 temp_hkcu_hive_key_.Close(); |
435 base::win::RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, | 443 base::win::RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, |
436 KEY_ALL_ACCESS); | 444 KEY_ALL_ACCESS); |
437 key.DeleteKey(L""); | 445 key.DeleteKey(L""); |
438 } | 446 } |
439 | 447 |
| 448 base::ScopedTempDir temp_dir_; |
440 base::win::RegKey temp_hkcu_hive_key_; | 449 base::win::RegKey temp_hkcu_hive_key_; |
441 }; | 450 }; |
442 | 451 |
443 TEST_F(IEImporterTest, IEImporter) { | 452 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, IEImporter) { |
444 // Sets up a favorites folder. | 453 // Sets up a favorites folder. |
445 base::win::ScopedCOMInitializer com_init; | |
446 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); | 454 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
447 CreateDirectory(path.value().c_str(), NULL); | 455 CreateDirectory(path.value().c_str(), NULL); |
448 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); | 456 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); |
449 base::FilePath links_path = path.AppendASCII("Links"); | 457 base::FilePath links_path = path.AppendASCII("Links"); |
450 CreateDirectory(links_path.value().c_str(), NULL); | 458 CreateDirectory(links_path.value().c_str(), NULL); |
451 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), | 459 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), |
452 NULL); | 460 NULL); |
453 CreateDirectory(path.AppendASCII("\x0061").value().c_str(), NULL); | 461 CreateDirectory(path.AppendASCII("\x0061").value().c_str(), NULL); |
454 ASSERT_TRUE(CreateUrlFileWithFavicon(path.AppendASCII("Google Home Page.url"), | 462 ASSERT_TRUE(CreateUrlFileWithFavicon(path.AppendASCII("Google Home Page.url"), |
455 L"http://www.google.com/", | 463 L"http://www.google.com/", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 | 503 |
496 // Sets up a special history link. | 504 // Sets up a special history link. |
497 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; | 505 base::win::ScopedComPtr<IUrlHistoryStg2> url_history_stg2; |
498 res = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, | 506 res = url_history_stg2.CreateInstance(CLSID_CUrlHistory, NULL, |
499 CLSCTX_INPROC_SERVER); | 507 CLSCTX_INPROC_SERVER); |
500 ASSERT_TRUE(res == S_OK); | 508 ASSERT_TRUE(res == S_OK); |
501 res = url_history_stg2->AddUrl(kIEIdentifyUrl, kIEIdentifyTitle, 0); | 509 res = url_history_stg2->AddUrl(kIEIdentifyUrl, kIEIdentifyTitle, 0); |
502 ASSERT_TRUE(res == S_OK); | 510 ASSERT_TRUE(res == S_OK); |
503 | 511 |
504 // Starts to import the above settings. | 512 // Starts to import the above settings. |
505 MessageLoop* loop = MessageLoop::current(); | 513 // TODO(gab): Use ExternalProcessImporterHost on Windows. |
506 scoped_refptr<ImporterHost> host(new ImporterHost); | 514 scoped_refptr<ImporterHost> host(new ImporterHost); |
507 | |
508 TestObserver* observer = new TestObserver(); | 515 TestObserver* observer = new TestObserver(); |
509 host->SetObserver(observer); | 516 host->SetObserver(observer); |
| 517 |
510 importer::SourceProfile source_profile; | 518 importer::SourceProfile source_profile; |
511 source_profile.importer_type = importer::TYPE_IE; | 519 source_profile.importer_type = importer::TYPE_IE; |
512 source_profile.source_path = temp_dir_.path(); | 520 source_profile.source_path = temp_dir_.path(); |
513 | 521 |
514 // IUrlHistoryStg2::AddUrl seems to reset the override. Ensure it here. | 522 // IUrlHistoryStg2::AddUrl seems to reset the override. Ensure it here. |
515 StartRegistryOverride(); | 523 StartRegistryOverride(); |
516 | 524 |
517 loop->PostTask(FROM_HERE, base::Bind( | 525 host->StartImportSettings( |
518 &ImporterHost::StartImportSettings, | |
519 host.get(), | |
520 source_profile, | 526 source_profile, |
521 profile_.get(), | 527 browser()->profile(), |
522 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, | 528 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, |
523 observer)); | 529 observer); |
524 loop->Run(); | 530 MessageLoop::current()->Run(); |
525 | 531 |
526 // Cleans up. | 532 // Cleans up. |
527 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); | 533 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); |
528 url_history_stg2.Release(); | 534 url_history_stg2.Release(); |
529 } | 535 } |
530 | 536 |
531 TEST_F(IEImporterTest, IEImporterMalformedFavoritesRegistry) { | 537 IN_PROC_BROWSER_TEST_F(IEImporterBrowserTest, |
| 538 IEImporterMalformedFavoritesRegistry) { |
532 // Sets up a favorites folder. | 539 // Sets up a favorites folder. |
533 base::win::ScopedCOMInitializer com_init; | |
534 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); | 540 base::FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
535 CreateDirectory(path.value().c_str(), NULL); | 541 CreateDirectory(path.value().c_str(), NULL); |
536 CreateDirectory(path.AppendASCII("b").value().c_str(), NULL); | 542 CreateDirectory(path.AppendASCII("b").value().c_str(), NULL); |
537 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("a.url"), | 543 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("a.url"), |
538 L"http://www.google.com/0")); | 544 L"http://www.google.com/0")); |
539 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("a.url"), | 545 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("a.url"), |
540 L"http://www.google.com/1")); | 546 L"http://www.google.com/1")); |
541 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("b.url"), | 547 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("b.url"), |
542 L"http://www.google.com/2")); | 548 L"http://www.google.com/2")); |
543 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("c.url"), | 549 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("c.url"), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 // sort is performed. | 581 // sort is performed. |
576 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { | 582 for (size_t i = 0; i < arraysize(kBadBinary); ++i) { |
577 base::win::RegKey key; | 583 base::win::RegKey key; |
578 ASSERT_EQ(ERROR_SUCCESS, | 584 ASSERT_EQ(ERROR_SUCCESS, |
579 key.Create(HKEY_CURRENT_USER, kIEFavoritesOrderKey, KEY_WRITE)); | 585 key.Create(HKEY_CURRENT_USER, kIEFavoritesOrderKey, KEY_WRITE)); |
580 ASSERT_EQ(ERROR_SUCCESS, | 586 ASSERT_EQ(ERROR_SUCCESS, |
581 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, | 587 key.WriteValue(L"Order", kBadBinary[i].data, kBadBinary[i].length, |
582 REG_BINARY)); | 588 REG_BINARY)); |
583 | 589 |
584 // Starts to import the above settings. | 590 // Starts to import the above settings. |
585 MessageLoop* loop = MessageLoop::current(); | 591 // TODO(gab): Use ExternalProcessImporterHost on Windows. |
586 scoped_refptr<ImporterHost> host(new ImporterHost); | 592 scoped_refptr<ImporterHost> host(new ImporterHost); |
587 | |
588 MalformedFavoritesRegistryTestObserver* observer = | 593 MalformedFavoritesRegistryTestObserver* observer = |
589 new MalformedFavoritesRegistryTestObserver(); | 594 new MalformedFavoritesRegistryTestObserver(); |
590 host->SetObserver(observer); | 595 host->SetObserver(observer); |
| 596 |
591 importer::SourceProfile source_profile; | 597 importer::SourceProfile source_profile; |
592 source_profile.importer_type = importer::TYPE_IE; | 598 source_profile.importer_type = importer::TYPE_IE; |
593 source_profile.source_path = temp_dir_.path(); | 599 source_profile.source_path = temp_dir_.path(); |
594 | 600 |
595 loop->PostTask(FROM_HERE, base::Bind( | 601 host->StartImportSettings( |
596 &ImporterHost::StartImportSettings, | |
597 host.get(), | |
598 source_profile, | 602 source_profile, |
599 profile_.get(), | 603 browser()->profile(), |
600 importer::FAVORITES, | 604 importer::FAVORITES, |
601 observer)); | 605 observer); |
602 loop->Run(); | 606 MessageLoop::current()->Run(); |
603 } | 607 } |
604 } | 608 } |
605 | |
606 TEST_F(IEImporterTest, IE7Importer) { | |
607 // This is the unencrypted values of my keys under Storage2. | |
608 // The passwords have been manually changed to abcdef... but the size remains | |
609 // the same. | |
610 unsigned char data1[] = "\x0c\x00\x00\x00\x38\x00\x00\x00\x2c\x00\x00\x00" | |
611 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" | |
612 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" | |
613 "\x00\x00\x00\x00\x4e\xfa\x67\x76\x22\x94\xc8\x01" | |
614 "\x08\x00\x00\x00\x12\x00\x00\x00\x4e\xfa\x67\x76" | |
615 "\x22\x94\xc8\x01\x0c\x00\x00\x00\x61\x00\x62\x00" | |
616 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" | |
617 "\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00\x65\x00" | |
618 "\x66\x00\x67\x00\x68\x00\x69\x00\x6a\x00\x6b\x00" | |
619 "\x6c\x00\x00\x00"; | |
620 | |
621 unsigned char data2[] = "\x0c\x00\x00\x00\x38\x00\x00\x00\x24\x00\x00\x00" | |
622 "\x57\x49\x43\x4b\x18\x00\x00\x00\x02\x00\x00\x00" | |
623 "\x67\x00\x72\x00\x01\x00\x00\x00\x00\x00\x00\x00" | |
624 "\x00\x00\x00\x00\xa8\xea\xf4\xe5\x9f\x9a\xc8\x01" | |
625 "\x09\x00\x00\x00\x14\x00\x00\x00\xa8\xea\xf4\xe5" | |
626 "\x9f\x9a\xc8\x01\x07\x00\x00\x00\x61\x00\x62\x00" | |
627 "\x63\x00\x64\x00\x65\x00\x66\x00\x67\x00\x68\x00" | |
628 "\x69\x00\x00\x00\x61\x00\x62\x00\x63\x00\x64\x00" | |
629 "\x65\x00\x66\x00\x67\x00\x00\x00"; | |
630 | |
631 | |
632 | |
633 std::vector<unsigned char> decrypted_data1; | |
634 decrypted_data1.resize(arraysize(data1)); | |
635 memcpy(&decrypted_data1.front(), data1, sizeof(data1)); | |
636 | |
637 std::vector<unsigned char> decrypted_data2; | |
638 decrypted_data2.resize(arraysize(data2)); | |
639 memcpy(&decrypted_data2.front(), data2, sizeof(data2)); | |
640 | |
641 string16 password; | |
642 string16 username; | |
643 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username, | |
644 &password)); | |
645 EXPECT_EQ(L"abcdefgh", username); | |
646 EXPECT_EQ(L"abcdefghijkl", password); | |
647 | |
648 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username, | |
649 &password)); | |
650 EXPECT_EQ(L"abcdefghi", username); | |
651 EXPECT_EQ(L"abcdefg", password); | |
652 } | |
OLD | NEW |