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 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, | 92 "http://www.webster.com/cgi-bin/dictionary?va={searchTerms}" }, |
93 // Search keywords. | 93 // Search keywords. |
94 { L"\x4E2D\x6587", "http://www.google.com/" }, | 94 { L"\x4E2D\x6587", "http://www.google.com/" }, |
95 }; | 95 }; |
96 | 96 |
97 class FirefoxObserver : public ProfileWriter, | 97 class FirefoxObserver : public ProfileWriter, |
98 public importer::ImporterProgressObserver { | 98 public importer::ImporterProgressObserver { |
99 public: | 99 public: |
100 FirefoxObserver() | 100 FirefoxObserver() |
101 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), | 101 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), |
102 password_count_(0), keyword_count_(0), import_search_engines_(true) { | 102 password_count_(0), keyword_count_(0) { |
103 } | 103 } |
104 | 104 |
105 explicit FirefoxObserver(bool import_search_engines) | 105 explicit FirefoxObserver(bool import_search_engines) |
106 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), | 106 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0), |
107 password_count_(0), keyword_count_(0), | 107 password_count_(0), keyword_count_(0) { |
108 import_search_engines_(import_search_engines) { | |
109 } | 108 } |
Ilya Sherman
2014/06/19 00:49:15
Please remove this constructor entirely.
| |
110 | 109 |
111 // importer::ImporterProgressObserver: | 110 // importer::ImporterProgressObserver: |
112 virtual void ImportStarted() OVERRIDE {} | 111 virtual void ImportStarted() OVERRIDE {} |
113 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} | 112 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} |
114 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} | 113 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} |
115 virtual void ImportEnded() OVERRIDE { | 114 virtual void ImportEnded() OVERRIDE { |
116 base::MessageLoop::current()->Quit(); | 115 base::MessageLoop::current()->Quit(); |
117 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); | 116 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); |
118 EXPECT_EQ(1U, history_count_); | 117 EXPECT_EQ(1U, history_count_); |
119 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); | 118 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); |
120 if (import_search_engines_) | 119 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); |
121 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_); | |
122 } | 120 } |
123 | 121 |
124 virtual bool BookmarkModelIsLoaded() const OVERRIDE { | 122 virtual bool BookmarkModelIsLoaded() const OVERRIDE { |
125 // Profile is ready for writing. | 123 // Profile is ready for writing. |
126 return true; | 124 return true; |
127 } | 125 } |
128 | 126 |
129 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { | 127 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { |
130 return true; | 128 return true; |
131 } | 129 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 192 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
195 } | 193 } |
196 | 194 |
197 private: | 195 private: |
198 virtual ~FirefoxObserver() {} | 196 virtual ~FirefoxObserver() {} |
199 | 197 |
200 size_t bookmark_count_; | 198 size_t bookmark_count_; |
201 size_t history_count_; | 199 size_t history_count_; |
202 size_t password_count_; | 200 size_t password_count_; |
203 size_t keyword_count_; | 201 size_t keyword_count_; |
204 bool import_search_engines_; | |
205 }; | 202 }; |
206 | 203 |
207 } // namespace | 204 } // namespace |
208 | 205 |
209 // These tests need to be browser tests in order to be able to run the OOP | 206 // These tests need to be browser tests in order to be able to run the OOP |
210 // import (via ExternalProcessImporterHost) which launches a utility process on | 207 // import (via ExternalProcessImporterHost) which launches a utility process on |
211 // supported platforms. | 208 // supported platforms. |
212 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 209 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
213 protected: | 210 protected: |
214 virtual void SetUp() OVERRIDE { | 211 virtual void SetUp() OVERRIDE { |
215 // Creates a new profile in a new subdirectory in the temp directory. | 212 // Creates a new profile in a new subdirectory in the temp directory. |
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 213 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
217 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | 214 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
218 base::DeleteFile(test_path, true); | 215 base::DeleteFile(test_path, true); |
219 base::CreateDirectory(test_path); | 216 base::CreateDirectory(test_path); |
220 profile_path_ = test_path.AppendASCII("profile"); | 217 profile_path_ = test_path.AppendASCII("profile"); |
221 app_path_ = test_path.AppendASCII("app"); | 218 app_path_ = test_path.AppendASCII("app"); |
222 base::CreateDirectory(app_path_); | 219 base::CreateDirectory(app_path_); |
223 | 220 |
224 // This will launch the browser test and thus needs to happen last. | 221 // This will launch the browser test and thus needs to happen last. |
225 InProcessBrowserTest::SetUp(); | 222 InProcessBrowserTest::SetUp(); |
226 } | 223 } |
227 | 224 |
228 void Firefox3xImporterBrowserTest( | 225 void FirefoxImporterBrowserTest(std::string profile_dir, |
229 std::string profile_dir, | 226 importer::ImporterProgressObserver* observer, |
230 importer::ImporterProgressObserver* observer, | 227 ProfileWriter* writer) { |
231 ProfileWriter* writer, | |
232 bool import_search_plugins) { | |
233 base::FilePath data_path; | 228 base::FilePath data_path; |
234 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 229 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
235 data_path = data_path.AppendASCII(profile_dir); | 230 data_path = data_path.AppendASCII(profile_dir); |
236 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); | 231 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); |
232 | |
237 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 233 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
238 data_path = data_path.AppendASCII("firefox3_nss"); | 234 data_path = data_path.AppendASCII("firefox3_nss"); |
239 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false)); | 235 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false)); |
240 | 236 |
241 base::FilePath search_engine_path = app_path_; | 237 // Create a directory to house default search engines. |
242 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | 238 base::FilePath default_search_engine_path = |
243 base::CreateDirectory(search_engine_path); | 239 app_path_.AppendASCII("searchplugins"); |
244 if (import_search_plugins) { | 240 base::CreateDirectory(default_search_engine_path); |
245 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 241 |
246 data_path = data_path.AppendASCII("firefox3_searchplugins"); | 242 // Create a directory to house custom/installed search engines. |
247 if (!base::PathExists(data_path)) { | 243 base::FilePath custom_search_engine_path = |
248 // TODO(maruel): Create search test data that we can open source! | 244 profile_path_.AppendASCII("searchplugins"); |
249 LOG(ERROR) << "Missing internal test data"; | 245 base::CreateDirectory(custom_search_engine_path); |
250 return; | 246 |
251 } | 247 // Import search engines |
Ilya Sherman
2014/06/19 00:49:15
nit: "Import" -> "Copy over"
Ilya Sherman
2014/06/19 00:49:16
nit: Please end the sentence with a period.
| |
252 ASSERT_TRUE(base::CopyDirectory(data_path, search_engine_path, false)); | 248 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
253 } | 249 data_path = data_path.AppendASCII("firefox_searchplugins"); |
250 base::FilePath default_search_engine_source_path = | |
251 data_path.AppendASCII("default"); | |
252 base::FilePath custom_search_engine_source_path = | |
253 data_path.AppendASCII("custom"); | |
254 ASSERT_TRUE(base::CopyDirectory( | |
255 default_search_engine_source_path, default_search_engine_path, false)); | |
256 ASSERT_TRUE(base::CopyDirectory( | |
257 custom_search_engine_source_path, custom_search_engine_path, false)); | |
254 | 258 |
255 importer::SourceProfile source_profile; | 259 importer::SourceProfile source_profile; |
256 source_profile.importer_type = importer::TYPE_FIREFOX; | 260 source_profile.importer_type = importer::TYPE_FIREFOX; |
257 source_profile.app_path = app_path_; | 261 source_profile.app_path = app_path_; |
258 source_profile.source_path = profile_path_; | 262 source_profile.source_path = profile_path_; |
259 source_profile.locale = "en-US"; | 263 source_profile.locale = "en-US"; |
260 | 264 |
261 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; | 265 int items = importer::HISTORY | importer::PASSWORDS | |
262 if (import_search_plugins) | 266 importer::FAVORITES | importer::SEARCH_ENGINES; |
263 items = items | importer::SEARCH_ENGINES; | |
264 | 267 |
265 // Deletes itself. | 268 // Deletes itself. |
266 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; | 269 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; |
267 host->set_observer(observer); | 270 host->set_observer(observer); |
268 host->StartImportSettings(source_profile, | 271 host->StartImportSettings(source_profile, |
269 browser()->profile(), | 272 browser()->profile(), |
270 items, | 273 items, |
271 make_scoped_refptr(writer).get()); | 274 writer); |
272 base::MessageLoop::current()->Run(); | 275 base::MessageLoop::current()->Run(); |
273 } | 276 } |
274 | 277 |
275 base::ScopedTempDir temp_dir_; | 278 base::ScopedTempDir temp_dir_; |
276 base::FilePath profile_path_; | 279 base::FilePath profile_path_; |
277 base::FilePath app_path_; | 280 base::FilePath app_path_; |
278 }; | 281 }; |
279 | 282 |
280 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 283 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
281 MAYBE_IMPORTER(Firefox30Importer)) { | 284 MAYBE_IMPORTER(Firefox30Importer)) { |
282 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 285 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
283 Firefox3xImporterBrowserTest("firefox3_profile", observer.get(), | 286 FirefoxImporterBrowserTest( |
284 observer.get(), true); | 287 "firefox3_profile", observer.get(), observer.get()); |
285 } | 288 } |
286 | 289 |
287 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 290 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
288 MAYBE_IMPORTER(Firefox35Importer)) { | 291 MAYBE_IMPORTER(Firefox35Importer)) { |
289 bool import_search_engines = false; | 292 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
290 scoped_refptr<FirefoxObserver> observer( | 293 FirefoxImporterBrowserTest( |
291 new FirefoxObserver(import_search_engines)); | 294 "firefox35_profile", observer.get(), observer.get()); |
292 Firefox3xImporterBrowserTest("firefox35_profile", observer.get(), | |
293 observer.get(), import_search_engines); | |
294 } | 295 } |
296 | |
297 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, FirefoxImporter) { | |
Ilya Sherman
2014/06/19 00:49:15
After looking at the tests more closely, I think y
| |
298 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | |
299 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get()); | |
300 } | |
OLD | NEW |