OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 // The order of these includes is important. | 8 // The order of these includes is important. |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <unknwn.h> | 10 #include <unknwn.h> |
11 #include <intshcut.h> | 11 #include <intshcut.h> |
12 #include <pstore.h> | 12 #include <pstore.h> |
13 #include <urlhist.h> | 13 #include <urlhist.h> |
14 #include <shlguid.h> | 14 #include <shlguid.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "app/win/scoped_com_initializer.h" | 19 #include "app/win/scoped_com_initializer.h" |
20 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
21 #include "base/file_util.h" | 21 #include "base/file_util.h" |
22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
24 #include "base/stl_util-inl.h" | 24 #include "base/stl_util-inl.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/memory/scoped_temp_dir.h" |
27 #include "chrome/browser/history/history_types.h" | 28 #include "chrome/browser/history/history_types.h" |
28 #include "chrome/browser/importer/importer_bridge.h" | 29 #include "chrome/browser/importer/importer_bridge.h" |
29 #include "chrome/browser/importer/importer_data_types.h" | 30 #include "chrome/browser/importer/importer_data_types.h" |
30 #include "chrome/browser/importer/importer_host.h" | 31 #include "chrome/browser/importer/importer_host.h" |
31 #include "chrome/browser/importer/importer_progress_observer.h" | 32 #include "chrome/browser/importer/importer_progress_observer.h" |
32 #include "chrome/browser/search_engines/template_url.h" | 33 #include "chrome/browser/search_engines/template_url.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "content/browser/browser_thread.h" | 35 #include "content/browser/browser_thread.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 #include "webkit/glue/password_form.h" | 37 #include "webkit/glue/password_form.h" |
(...skipping 14 matching lines...) Expand all Loading... |
51 | 52 |
52 class ImporterTest : public testing::Test { | 53 class ImporterTest : public testing::Test { |
53 public: | 54 public: |
54 ImporterTest() | 55 ImporterTest() |
55 : ui_thread_(BrowserThread::UI, &message_loop_), | 56 : ui_thread_(BrowserThread::UI, &message_loop_), |
56 file_thread_(BrowserThread::FILE, &message_loop_) {} | 57 file_thread_(BrowserThread::FILE, &message_loop_) {} |
57 | 58 |
58 protected: | 59 protected: |
59 virtual void SetUp() { | 60 virtual void SetUp() { |
60 // Creates a new profile in a new subdirectory in the temp directory. | 61 // Creates a new profile in a new subdirectory in the temp directory. |
61 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_path_)); | 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
62 test_path_ = test_path_.AppendASCII("ImporterTest"); | 63 FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
63 file_util::Delete(test_path_, true); | 64 file_util::Delete(test_path, true); |
64 file_util::CreateDirectory(test_path_); | 65 file_util::CreateDirectory(test_path); |
65 profile_path_ = test_path_.AppendASCII("profile"); | 66 profile_path_ = test_path.AppendASCII("profile"); |
66 app_path_ = test_path_.AppendASCII("app"); | 67 app_path_ = test_path.AppendASCII("app"); |
67 file_util::CreateDirectory(app_path_); | 68 file_util::CreateDirectory(app_path_); |
68 } | 69 } |
69 | 70 |
70 virtual void TearDown() { | |
71 // Deletes the profile and cleans up the profile directory. | |
72 ASSERT_TRUE(file_util::Delete(test_path_, true)); | |
73 ASSERT_FALSE(file_util::PathExists(test_path_)); | |
74 } | |
75 | |
76 void Firefox3xImporterTest(std::string profile_dir, | 71 void Firefox3xImporterTest(std::string profile_dir, |
77 importer::ImporterProgressObserver* observer, | 72 importer::ImporterProgressObserver* observer, |
78 ProfileWriter* writer, | 73 ProfileWriter* writer, |
79 bool import_search_plugins) { | 74 bool import_search_plugins) { |
80 FilePath data_path; | 75 FilePath data_path; |
81 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 76 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
82 data_path = data_path.AppendASCII(profile_dir); | 77 data_path = data_path.AppendASCII(profile_dir); |
83 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); | 78 ASSERT_TRUE(file_util::CopyDirectory(data_path, profile_path_, true)); |
84 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 79 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
85 data_path = data_path.AppendASCII("firefox3_nss"); | 80 data_path = data_path.AppendASCII("firefox3_nss"); |
(...skipping 23 matching lines...) Expand all Loading... |
109 host->SetObserver(observer); | 104 host->SetObserver(observer); |
110 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; | 105 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; |
111 if (import_search_plugins) | 106 if (import_search_plugins) |
112 items = items | importer::SEARCH_ENGINES; | 107 items = items | importer::SEARCH_ENGINES; |
113 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), | 108 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), |
114 &ImporterHost::StartImportSettings, source_profile, | 109 &ImporterHost::StartImportSettings, source_profile, |
115 static_cast<Profile*>(NULL), items, make_scoped_refptr(writer), true)); | 110 static_cast<Profile*>(NULL), items, make_scoped_refptr(writer), true)); |
116 loop->Run(); | 111 loop->Run(); |
117 } | 112 } |
118 | 113 |
| 114 ScopedTempDir temp_dir_; |
119 MessageLoopForUI message_loop_; | 115 MessageLoopForUI message_loop_; |
120 BrowserThread ui_thread_; | 116 BrowserThread ui_thread_; |
121 BrowserThread file_thread_; | 117 BrowserThread file_thread_; |
122 FilePath test_path_; | |
123 FilePath profile_path_; | 118 FilePath profile_path_; |
124 FilePath app_path_; | 119 FilePath app_path_; |
125 }; | 120 }; |
126 | 121 |
127 const int kMaxPathSize = 5; | 122 const int kMaxPathSize = 5; |
128 | 123 |
129 struct BookmarkList { | 124 struct BookmarkList { |
130 const bool in_toolbar; | 125 const bool in_toolbar; |
131 const size_t path_size; | 126 const size_t path_size; |
132 const wchar_t* path[kMaxPathSize]; | 127 const wchar_t* path[kMaxPathSize]; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 HRESULT res = pstore->WriteItem(0, type, subtype, items[i].name, | 320 HRESULT res = pstore->WriteItem(0, type, subtype, items[i].name, |
326 items[i].data_size, reinterpret_cast<BYTE*>(items[i].data), | 321 items[i].data_size, reinterpret_cast<BYTE*>(items[i].data), |
327 NULL, 0, 0); | 322 NULL, 0, 0); |
328 ASSERT_TRUE(res == PST_E_OK); | 323 ASSERT_TRUE(res == PST_E_OK); |
329 } | 324 } |
330 } | 325 } |
331 | 326 |
332 TEST_F(ImporterTest, IEImporter) { | 327 TEST_F(ImporterTest, IEImporter) { |
333 // Sets up a favorites folder. | 328 // Sets up a favorites folder. |
334 app::win::ScopedCOMInitializer com_init; | 329 app::win::ScopedCOMInitializer com_init; |
335 std::wstring path = test_path_.AppendASCII("Favorites").value(); | 330 std::wstring path = temp_dir_.path().AppendASCII("Favorites").value(); |
336 CreateDirectory(path.c_str(), NULL); | 331 CreateDirectory(path.c_str(), NULL); |
337 CreateDirectory((path + L"\\SubFolder").c_str(), NULL); | 332 CreateDirectory((path + L"\\SubFolder").c_str(), NULL); |
338 CreateDirectory((path + L"\\Links").c_str(), NULL); | 333 CreateDirectory((path + L"\\Links").c_str(), NULL); |
339 CreateDirectory((path + L"\\Links\\SubFolderOfLinks").c_str(), NULL); | 334 CreateDirectory((path + L"\\Links\\SubFolderOfLinks").c_str(), NULL); |
340 CreateDirectory((path + L"\\\x0061").c_str(), NULL); | 335 CreateDirectory((path + L"\\\x0061").c_str(), NULL); |
341 ASSERT_TRUE(CreateUrlFile(path + L"\\Google Home Page.url", | 336 ASSERT_TRUE(CreateUrlFile(path + L"\\Google Home Page.url", |
342 L"http://www.google.com/")); | 337 L"http://www.google.com/")); |
343 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder\\Title.url", | 338 ASSERT_TRUE(CreateUrlFile(path + L"\\SubFolder\\Title.url", |
344 L"http://www.link.com/")); | 339 L"http://www.link.com/")); |
345 ASSERT_TRUE(CreateUrlFile(path + L"\\TheLink.url", | 340 ASSERT_TRUE(CreateUrlFile(path + L"\\TheLink.url", |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 ASSERT_TRUE(res == S_OK); | 384 ASSERT_TRUE(res == S_OK); |
390 | 385 |
391 // Starts to import the above settings. | 386 // Starts to import the above settings. |
392 MessageLoop* loop = MessageLoop::current(); | 387 MessageLoop* loop = MessageLoop::current(); |
393 scoped_refptr<ImporterHost> host(new ImporterHost); | 388 scoped_refptr<ImporterHost> host(new ImporterHost); |
394 | 389 |
395 TestObserver* observer = new TestObserver(); | 390 TestObserver* observer = new TestObserver(); |
396 host->SetObserver(observer); | 391 host->SetObserver(observer); |
397 importer::SourceProfile source_profile; | 392 importer::SourceProfile source_profile; |
398 source_profile.importer_type = importer::MS_IE; | 393 source_profile.importer_type = importer::MS_IE; |
399 source_profile.source_path = test_path_; | 394 source_profile.source_path = temp_dir_.path(); |
400 | 395 |
401 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), | 396 loop->PostTask(FROM_HERE, NewRunnableMethod(host.get(), |
402 &ImporterHost::StartImportSettings, | 397 &ImporterHost::StartImportSettings, |
403 source_profile, | 398 source_profile, |
404 static_cast<Profile*>(NULL), | 399 static_cast<Profile*>(NULL), |
405 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, | 400 importer::HISTORY | importer::PASSWORDS | importer::FAVORITES, |
406 observer, | 401 observer, |
407 true)); | 402 true)); |
408 loop->Run(); | 403 loop->Run(); |
409 | 404 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 true); | 875 true); |
881 } | 876 } |
882 | 877 |
883 TEST_F(ImporterTest, MAYBE(Firefox35Importer)) { | 878 TEST_F(ImporterTest, MAYBE(Firefox35Importer)) { |
884 bool import_search_engines = false; | 879 bool import_search_engines = false; |
885 scoped_refptr<Firefox3Observer> observer( | 880 scoped_refptr<Firefox3Observer> observer( |
886 new Firefox3Observer(import_search_engines)); | 881 new Firefox3Observer(import_search_engines)); |
887 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(), | 882 Firefox3xImporterTest("firefox35_profile", observer.get(), observer.get(), |
888 import_search_engines); | 883 import_search_engines); |
889 } | 884 } |
OLD | NEW |