OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 // The order of these includes is important. | 7 // The order of these includes is important. |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <unknwn.h> | 9 #include <unknwn.h> |
10 #include <intshcut.h> | 10 #include <intshcut.h> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ERROR_SUCCESS) { | 128 ERROR_SUCCESS) { |
129 return false; | 129 return false; |
130 } | 130 } |
131 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != | 131 if (key.WriteValue(L"Order", &blob[0], blob.size(), REG_BINARY) != |
132 ERROR_SUCCESS) { | 132 ERROR_SUCCESS) { |
133 return false; | 133 return false; |
134 } | 134 } |
135 return true; | 135 return true; |
136 } | 136 } |
137 | 137 |
138 bool CreateUrlFile(const string16& file, const string16& url) { | 138 bool CreateUrlFile(const FilePath& file, const string16& url) { |
139 base::win::ScopedComPtr<IUniformResourceLocator> locator; | 139 base::win::ScopedComPtr<IUniformResourceLocator> locator; |
140 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL, | 140 HRESULT result = locator.CreateInstance(CLSID_InternetShortcut, NULL, |
141 CLSCTX_INPROC_SERVER); | 141 CLSCTX_INPROC_SERVER); |
142 if (FAILED(result)) | 142 if (FAILED(result)) |
143 return false; | 143 return false; |
144 base::win::ScopedComPtr<IPersistFile> persist_file; | 144 base::win::ScopedComPtr<IPersistFile> persist_file; |
145 result = persist_file.QueryFrom(locator); | 145 result = persist_file.QueryFrom(locator); |
146 if (FAILED(result)) | 146 if (FAILED(result)) |
147 return false; | 147 return false; |
148 result = locator->SetURL(url.c_str(), 0); | 148 result = locator->SetURL(url.c_str(), 0); |
149 if (FAILED(result)) | 149 if (FAILED(result)) |
150 return false; | 150 return false; |
151 result = persist_file->Save(file.c_str(), TRUE); | 151 result = persist_file->Save(file.value().c_str(), TRUE); |
152 if (FAILED(result)) | 152 if (FAILED(result)) |
153 return false; | 153 return false; |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 void ClearPStoreType(IPStore* pstore, const GUID* type, const GUID* subtype) { | 157 void ClearPStoreType(IPStore* pstore, const GUID* type, const GUID* subtype) { |
158 base::win::ScopedComPtr<IEnumPStoreItems, NULL> item; | 158 base::win::ScopedComPtr<IEnumPStoreItems, NULL> item; |
159 HRESULT result = pstore->EnumItems(0, type, subtype, 0, item.Receive()); | 159 HRESULT result = pstore->EnumItems(0, type, subtype, 0, item.Receive()); |
160 if (result == PST_E_OK) { | 160 if (result == PST_E_OK) { |
161 char16* item_name; | 161 char16* item_name; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 KEY_ALL_ACCESS); | 346 KEY_ALL_ACCESS); |
347 key.DeleteKey(L""); | 347 key.DeleteKey(L""); |
348 } | 348 } |
349 | 349 |
350 base::win::RegKey temp_hkcu_hive_key_; | 350 base::win::RegKey temp_hkcu_hive_key_; |
351 }; | 351 }; |
352 | 352 |
353 TEST_F(IEImporterTest, IEImporter) { | 353 TEST_F(IEImporterTest, IEImporter) { |
354 // Sets up a favorites folder. | 354 // Sets up a favorites folder. |
355 base::win::ScopedCOMInitializer com_init; | 355 base::win::ScopedCOMInitializer com_init; |
356 string16 path = temp_dir_.path().AppendASCII("Favorites").value(); | 356 FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
357 CreateDirectory(path.c_str(), NULL); | 357 CreateDirectory(path.value().c_str(), NULL); |
358 CreateDirectory((path + L"\\SubFolder").c_str(), NULL); | 358 CreateDirectory(path.AppendASCII("SubFolder").value().c_str(), NULL); |
359 CreateDirectory((path + L"\\Links").c_str(), NULL); | 359 FilePath links_path = path.AppendASCII("Links"); |
360 CreateDirectory((path + L"\\Links\\SubFolderOfLinks").c_str(), NULL); | 360 CreateDirectory(links_path.value().c_str(), NULL); |
361 CreateDirectory((path + L"\\\x0061").c_str(), NULL); | 361 CreateDirectory(links_path.AppendASCII("SubFolderOfLinks").value().c_str(), |
362 ASSERT_TRUE(CreateUrlFile(path + L"\\Google Home Page.url", | 362 NULL); |
| 363 CreateDirectory(path.AppendASCII("\x0061").value().c_str(), NULL); |
| 364 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("Google Home Page.url"), |
363 L"http://www.google.com/")); | 365 L"http://www.google.com/")); |
364 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder\\Title.url", | 366 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("SubFolder\\Title.url"), |
365 L"http://www.link.com/")); | 367 L"http://www.link.com/")); |
366 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder.url", | 368 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("SubFolder.url"), |
367 L"http://www.subfolder.com/")); | 369 L"http://www.subfolder.com/")); |
368 ASSERT_TRUE(CreateUrlFile(path + L"\\TheLink.url", | 370 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("TheLink.url"), |
369 L"http://www.links-thelink.com/")); | 371 L"http://www.links-thelink.com/")); |
370 ASSERT_TRUE(CreateUrlFile(path + L"\\WithPortAndQuery.url", | 372 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("WithPortAndQuery.url"), |
371 L"http://host:8080/cgi?q=query")); | 373 L"http://host:8080/cgi?q=query")); |
372 ASSERT_TRUE(CreateUrlFile(path + L"\\\x0061\\\x4E2D\x6587.url", | 374 ASSERT_TRUE(CreateUrlFile( |
373 L"http://chinese-title-favorite/")); | 375 path.AppendASCII("\x0061").Append(L"\x4E2D\x6587.url"), |
374 ASSERT_TRUE(CreateUrlFile(path + L"\\Links\\TheLink.url", | 376 L"http://chinese-title-favorite/")); |
| 377 ASSERT_TRUE(CreateUrlFile(links_path.AppendASCII("TheLink.url"), |
375 L"http://www.links-thelink.com/")); | 378 L"http://www.links-thelink.com/")); |
376 ASSERT_TRUE(CreateUrlFile(path + L"\\Links\\SubFolderOfLinks\\SubLink.url", | 379 ASSERT_TRUE(CreateUrlFile( |
377 L"http://www.links-sublink.com/")); | 380 links_path.AppendASCII("SubFolderOfLinks").AppendASCII("SubLink.url"), |
378 file_util::WriteFile(path + L"\\InvalidUrlFile.url", "x", 1); | 381 L"http://www.links-sublink.com/")); |
379 file_util::WriteFile(path + L"\\PlainTextFile.txt", "x", 1); | 382 file_util::WriteFile(path.AppendASCII("InvalidUrlFile.url"), "x", 1); |
| 383 file_util::WriteFile(path.AppendASCII("PlainTextFile.txt"), "x", 1); |
380 | 384 |
381 const char16* root_links[] = { | 385 const char16* root_links[] = { |
382 L"Links", | 386 L"Links", |
383 L"Google Home Page.url", | 387 L"Google Home Page.url", |
384 L"TheLink.url", | 388 L"TheLink.url", |
385 L"SubFolder", | 389 L"SubFolder", |
386 L"WithPortAndQuery.url", | 390 L"WithPortAndQuery.url", |
387 L"a", | 391 L"a", |
388 L"SubFolder.url", | 392 L"SubFolder.url", |
389 }; | 393 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 loop->Run(); | 429 loop->Run(); |
426 | 430 |
427 // Cleans up. | 431 // Cleans up. |
428 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); | 432 url_history_stg2->DeleteUrl(kIEIdentifyUrl, 0); |
429 url_history_stg2.Release(); | 433 url_history_stg2.Release(); |
430 } | 434 } |
431 | 435 |
432 TEST_F(IEImporterTest, IEImporterMalformedFavoritesRegistry) { | 436 TEST_F(IEImporterTest, IEImporterMalformedFavoritesRegistry) { |
433 // Sets up a favorites folder. | 437 // Sets up a favorites folder. |
434 base::win::ScopedCOMInitializer com_init; | 438 base::win::ScopedCOMInitializer com_init; |
435 string16 path = temp_dir_.path().AppendASCII("Favorites").value(); | 439 FilePath path = temp_dir_.path().AppendASCII("Favorites"); |
436 CreateDirectory(path.c_str(), NULL); | 440 CreateDirectory(path.value().c_str(), NULL); |
437 CreateDirectory((path + L"\\b").c_str(), NULL); | 441 CreateDirectory(path.AppendASCII("b").value().c_str(), NULL); |
438 ASSERT_TRUE(CreateUrlFile(path + L"\\a.url", | 442 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("a.url"), |
439 L"http://www.google.com/0")); | 443 L"http://www.google.com/0")); |
440 ASSERT_TRUE(CreateUrlFile(path + L"\\b\\a.url", | 444 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("a.url"), |
441 L"http://www.google.com/1")); | 445 L"http://www.google.com/1")); |
442 ASSERT_TRUE(CreateUrlFile(path + L"\\b\\b.url", | 446 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("b").AppendASCII("b.url"), |
443 L"http://www.google.com/2")); | 447 L"http://www.google.com/2")); |
444 ASSERT_TRUE(CreateUrlFile(path + L"\\c.url", | 448 ASSERT_TRUE(CreateUrlFile(path.AppendASCII("c.url"), |
445 L"http://www.google.com/3")); | 449 L"http://www.google.com/3")); |
446 | 450 |
447 struct BadBinaryData { | 451 struct BadBinaryData { |
448 const char* data; | 452 const char* data; |
449 int length; | 453 int length; |
450 }; | 454 }; |
451 static const BadBinaryData kBadBinary[] = { | 455 static const BadBinaryData kBadBinary[] = { |
452 // number_of_items field is truncated | 456 // number_of_items field is truncated |
453 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | 457 {"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" |
454 "\x00\xff\xff\xff", 17}, | 458 "\x00\xff\xff\xff", 17}, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username, | 549 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data1, &username, |
546 &password)); | 550 &password)); |
547 EXPECT_EQ(L"abcdefgh", username); | 551 EXPECT_EQ(L"abcdefgh", username); |
548 EXPECT_EQ(L"abcdefghijkl", password); | 552 EXPECT_EQ(L"abcdefghijkl", password); |
549 | 553 |
550 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username, | 554 ASSERT_TRUE(ie7_password::GetUserPassFromData(decrypted_data2, &username, |
551 &password)); | 555 &password)); |
552 EXPECT_EQ(L"abcdefghi", username); | 556 EXPECT_EQ(L"abcdefghi", username); |
553 EXPECT_EQ(L"abcdefg", password); | 557 EXPECT_EQ(L"abcdefg", password); |
554 } | 558 } |
OLD | NEW |