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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { | 194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { |
195 } | 195 } |
196 | 196 |
197 private: | 197 private: |
198 virtual ~FirefoxObserver() {} | 198 virtual ~FirefoxObserver() {} |
199 | 199 |
200 size_t bookmark_count_; | 200 size_t bookmark_count_; |
201 size_t history_count_; | 201 size_t history_count_; |
202 size_t password_count_; | 202 size_t password_count_; |
203 size_t keyword_count_; | 203 size_t keyword_count_; |
204 bool import_search_engines_; | 204 bool import_search_engines_; |
Ilya Sherman
2014/06/17 23:26:42
With your improvements to the tests, is it possibl
Tapu Ghose
2014/06/18 12:16:42
I agree with you.
| |
205 }; | 205 }; |
206 | 206 |
207 } // namespace | 207 } // namespace |
208 | 208 |
209 // These tests need to be browser tests in order to be able to run the OOP | 209 // 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 | 210 // import (via ExternalProcessImporterHost) which launches a utility process on |
211 // supported platforms. | 211 // supported platforms. |
212 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { | 212 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { |
213 protected: | 213 protected: |
214 virtual void SetUp() OVERRIDE { | 214 virtual void SetUp() OVERRIDE { |
215 // Creates a new profile in a new subdirectory in the temp directory. | 215 // Creates a new profile in a new subdirectory in the temp directory. |
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
217 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); | 217 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); |
218 base::DeleteFile(test_path, true); | 218 base::DeleteFile(test_path, true); |
219 base::CreateDirectory(test_path); | 219 base::CreateDirectory(test_path); |
220 profile_path_ = test_path.AppendASCII("profile"); | 220 profile_path_ = test_path.AppendASCII("profile"); |
221 app_path_ = test_path.AppendASCII("app"); | 221 app_path_ = test_path.AppendASCII("app"); |
222 base::CreateDirectory(app_path_); | 222 base::CreateDirectory(app_path_); |
223 | 223 |
224 // This will launch the browser test and thus needs to happen last. | 224 // This will launch the browser test and thus needs to happen last. |
225 InProcessBrowserTest::SetUp(); | 225 InProcessBrowserTest::SetUp(); |
226 } | 226 } |
227 | 227 |
228 void Firefox3xImporterBrowserTest( | 228 void FirefoxImporterBrowserTest(std::string profile_dir, |
229 std::string profile_dir, | 229 importer::ImporterProgressObserver* observer, |
230 importer::ImporterProgressObserver* observer, | 230 ProfileWriter* writer, |
231 ProfileWriter* writer, | 231 bool import_search_plugins) { |
Ilya Sherman
2014/06/17 23:26:42
Ditto for this variable.
| |
232 bool import_search_plugins) { | |
233 base::FilePath data_path; | 232 base::FilePath data_path; |
234 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 233 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
235 data_path = data_path.AppendASCII(profile_dir); | 234 data_path = data_path.AppendASCII(profile_dir); |
236 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); | 235 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); |
236 | |
237 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 237 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
238 data_path = data_path.AppendASCII("firefox3_nss"); | 238 data_path = data_path.AppendASCII("firefox3_nss"); |
239 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false)); | 239 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false)); |
240 | 240 |
241 base::FilePath search_engine_path = app_path_; | 241 // default search engines |
242 search_engine_path = search_engine_path.AppendASCII("searchplugins"); | 242 base::FilePath default_search_engine_path = app_path_; |
243 base::CreateDirectory(search_engine_path); | 243 default_search_engine_path = |
244 default_search_engine_path.AppendASCII("searchplugins"); | |
245 base::CreateDirectory(default_search_engine_path); | |
Ilya Sherman
2014/06/17 23:26:42
nit: I'd condense these five lines a bit, like so:
| |
246 | |
247 // custom/installed search engines | |
248 base::FilePath custom_search_engine_path = profile_path_; | |
249 custom_search_engine_path = | |
250 custom_search_engine_path.AppendASCII("searchplugins"); | |
Ilya Sherman
2014/06/17 23:26:42
Are you intentionally not calling base::CreateDire
Tapu Ghose
2014/06/18 12:16:42
It was unintentional.
| |
251 | |
244 if (import_search_plugins) { | 252 if (import_search_plugins) { |
245 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); | 253 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); |
246 data_path = data_path.AppendASCII("firefox3_searchplugins"); | 254 data_path = data_path.AppendASCII("firefox_searchplugins"); |
247 if (!base::PathExists(data_path)) { | 255 base::FilePath default_search_engine_source_path = data_path; |
248 // TODO(maruel): Create search test data that we can open source! | 256 base::FilePath custom_search_engine_source_path = data_path; |
249 LOG(ERROR) << "Missing internal test data"; | 257 default_search_engine_source_path = |
250 return; | 258 default_search_engine_source_path.AppendASCII("default"); |
251 } | 259 custom_search_engine_source_path = |
252 ASSERT_TRUE(base::CopyDirectory(data_path, search_engine_path, false)); | 260 custom_search_engine_source_path.AppendASCII("custom"); |
Ilya Sherman
2014/06/17 23:26:42
I'd similarly condense these six lines down to fou
| |
261 ASSERT_TRUE(base::CopyDirectory(default_search_engine_source_path, | |
262 default_search_engine_path, | |
263 false)); | |
264 ASSERT_TRUE(base::CopyDirectory( | |
265 custom_search_engine_source_path, custom_search_engine_path, false)); | |
253 } | 266 } |
254 | 267 |
255 importer::SourceProfile source_profile; | 268 importer::SourceProfile source_profile; |
256 source_profile.importer_type = importer::TYPE_FIREFOX; | 269 source_profile.importer_type = importer::TYPE_FIREFOX; |
257 source_profile.app_path = app_path_; | 270 source_profile.app_path = app_path_; |
258 source_profile.source_path = profile_path_; | 271 source_profile.source_path = profile_path_; |
259 source_profile.locale = "en-US"; | 272 source_profile.locale = "en-US"; |
260 | 273 |
261 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; | 274 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; |
262 if (import_search_plugins) | 275 if (import_search_plugins) |
263 items = items | importer::SEARCH_ENGINES; | 276 items = items | importer::SEARCH_ENGINES; |
264 | 277 |
265 // Deletes itself. | 278 // Deletes itself. |
266 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; | 279 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; |
267 host->set_observer(observer); | 280 host->set_observer(observer); |
268 host->StartImportSettings(source_profile, | 281 host->StartImportSettings(source_profile, |
269 browser()->profile(), | 282 browser()->profile(), |
270 items, | 283 items, |
271 make_scoped_refptr(writer).get()); | 284 make_scoped_refptr(writer).get()); |
Ilya Sherman
2014/06/17 23:26:42
The more I look at the pre-existing test code, the
Tapu Ghose
2014/06/18 12:16:42
Not a problem...I will make the change as you sugg
| |
272 base::MessageLoop::current()->Run(); | 285 base::MessageLoop::current()->Run(); |
273 } | 286 } |
274 | 287 |
275 base::ScopedTempDir temp_dir_; | 288 base::ScopedTempDir temp_dir_; |
276 base::FilePath profile_path_; | 289 base::FilePath profile_path_; |
277 base::FilePath app_path_; | 290 base::FilePath app_path_; |
278 }; | 291 }; |
279 | 292 |
280 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 293 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
281 MAYBE_IMPORTER(Firefox30Importer)) { | 294 MAYBE_IMPORTER(Firefox30Importer)) { |
282 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | 295 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); |
283 Firefox3xImporterBrowserTest("firefox3_profile", observer.get(), | 296 FirefoxImporterBrowserTest( |
284 observer.get(), true); | 297 "firefox3_profile", observer.get(), observer.get(), true); |
285 } | 298 } |
286 | 299 |
287 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, | 300 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, |
288 MAYBE_IMPORTER(Firefox35Importer)) { | 301 MAYBE_IMPORTER(Firefox35Importer)) { |
289 bool import_search_engines = false; | 302 bool import_search_engines = false; |
290 scoped_refptr<FirefoxObserver> observer( | 303 scoped_refptr<FirefoxObserver> observer( |
291 new FirefoxObserver(import_search_engines)); | 304 new FirefoxObserver(import_search_engines)); |
292 Firefox3xImporterBrowserTest("firefox35_profile", observer.get(), | 305 FirefoxImporterBrowserTest("firefox35_profile", |
293 observer.get(), import_search_engines); | 306 observer.get(), |
307 observer.get(), | |
308 import_search_engines); | |
294 } | 309 } |
310 | |
311 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, FirefoxImporter) { | |
312 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); | |
313 FirefoxImporterBrowserTest( | |
314 "firefox_profile", observer.get(), observer.get(), true); | |
315 } | |
OLD | NEW |