Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: chrome/browser/importer/firefox_importer_browsertest.cc

Issue 247223003: Parsed search.json for importing search engine settings from FireFox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed overlooked comments on Patch Set 14. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/firefox_profile/README » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 { L"webster.com", 91 { L"webster.com",
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),
102 password_count_(0), keyword_count_(0), import_search_engines_(true) { 102 bookmark_count_(0),
103 } 103 history_count_(0),
104 104 password_count_(0),
105 explicit FirefoxObserver(bool import_search_engines) 105 keyword_count_(0) {}
106 : ProfileWriter(NULL), bookmark_count_(0), history_count_(0),
107 password_count_(0), keyword_count_(0),
108 import_search_engines_(import_search_engines) {
109 }
110 106
111 // importer::ImporterProgressObserver: 107 // importer::ImporterProgressObserver:
112 virtual void ImportStarted() OVERRIDE {} 108 virtual void ImportStarted() OVERRIDE {}
113 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {} 109 virtual void ImportItemStarted(importer::ImportItem item) OVERRIDE {}
114 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {} 110 virtual void ImportItemEnded(importer::ImportItem item) OVERRIDE {}
115 virtual void ImportEnded() OVERRIDE { 111 virtual void ImportEnded() OVERRIDE {
116 base::MessageLoop::current()->Quit(); 112 base::MessageLoop::current()->Quit();
117 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_); 113 EXPECT_EQ(arraysize(kFirefoxBookmarks), bookmark_count_);
118 EXPECT_EQ(1U, history_count_); 114 EXPECT_EQ(1U, history_count_);
119 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_); 115 EXPECT_EQ(arraysize(kFirefoxPasswords), password_count_);
120 if (import_search_engines_) 116 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_);
121 EXPECT_EQ(arraysize(kFirefoxKeywords), keyword_count_);
122 } 117 }
123 118
124 virtual bool BookmarkModelIsLoaded() const OVERRIDE { 119 virtual bool BookmarkModelIsLoaded() const OVERRIDE {
125 // Profile is ready for writing. 120 // Profile is ready for writing.
126 return true; 121 return true;
127 } 122 }
128 123
129 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE { 124 virtual bool TemplateURLServiceIsLoaded() const OVERRIDE {
130 return true; 125 return true;
131 } 126 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE { 189 const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE {
195 } 190 }
196 191
197 private: 192 private:
198 virtual ~FirefoxObserver() {} 193 virtual ~FirefoxObserver() {}
199 194
200 size_t bookmark_count_; 195 size_t bookmark_count_;
201 size_t history_count_; 196 size_t history_count_;
202 size_t password_count_; 197 size_t password_count_;
203 size_t keyword_count_; 198 size_t keyword_count_;
204 bool import_search_engines_;
205 }; 199 };
206 200
207 } // namespace 201 } // namespace
208 202
209 // These tests need to be browser tests in order to be able to run the OOP 203 // 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 204 // import (via ExternalProcessImporterHost) which launches a utility process on
211 // supported platforms. 205 // supported platforms.
212 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest { 206 class FirefoxProfileImporterBrowserTest : public InProcessBrowserTest {
213 protected: 207 protected:
214 virtual void SetUp() OVERRIDE { 208 virtual void SetUp() OVERRIDE {
215 // Creates a new profile in a new subdirectory in the temp directory. 209 // Creates a new profile in a new subdirectory in the temp directory.
216 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 210 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
217 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest"); 211 base::FilePath test_path = temp_dir_.path().AppendASCII("ImporterTest");
218 base::DeleteFile(test_path, true); 212 base::DeleteFile(test_path, true);
219 base::CreateDirectory(test_path); 213 base::CreateDirectory(test_path);
220 profile_path_ = test_path.AppendASCII("profile"); 214 profile_path_ = test_path.AppendASCII("profile");
221 app_path_ = test_path.AppendASCII("app"); 215 app_path_ = test_path.AppendASCII("app");
222 base::CreateDirectory(app_path_); 216 base::CreateDirectory(app_path_);
223 217
224 // This will launch the browser test and thus needs to happen last. 218 // This will launch the browser test and thus needs to happen last.
225 InProcessBrowserTest::SetUp(); 219 InProcessBrowserTest::SetUp();
226 } 220 }
227 221
228 void Firefox3xImporterBrowserTest( 222 void FirefoxImporterBrowserTest(std::string profile_dir,
229 std::string profile_dir, 223 importer::ImporterProgressObserver* observer,
230 importer::ImporterProgressObserver* observer, 224 ProfileWriter* writer) {
231 ProfileWriter* writer,
232 bool import_search_plugins) {
233 base::FilePath data_path; 225 base::FilePath data_path;
234 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
235 data_path = data_path.AppendASCII(profile_dir); 227 data_path = data_path.AppendASCII(profile_dir);
236 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true)); 228 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, true));
229
237 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 230 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
238 data_path = data_path.AppendASCII("firefox3_nss"); 231 data_path = data_path.AppendASCII("firefox3_nss");
239 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false)); 232 ASSERT_TRUE(base::CopyDirectory(data_path, profile_path_, false));
240 233
241 base::FilePath search_engine_path = app_path_; 234 // Create a directory to house default search engines.
242 search_engine_path = search_engine_path.AppendASCII("searchplugins"); 235 base::FilePath default_search_engine_path =
243 base::CreateDirectory(search_engine_path); 236 app_path_.AppendASCII("searchplugins");
244 if (import_search_plugins) { 237 base::CreateDirectory(default_search_engine_path);
245 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 238
246 data_path = data_path.AppendASCII("firefox3_searchplugins"); 239 // Create a directory to house custom/installed search engines.
247 if (!base::PathExists(data_path)) { 240 base::FilePath custom_search_engine_path =
248 // TODO(maruel): Create search test data that we can open source! 241 profile_path_.AppendASCII("searchplugins");
249 LOG(ERROR) << "Missing internal test data"; 242 base::CreateDirectory(custom_search_engine_path);
250 return; 243
251 } 244 // Copy over search engines.
252 ASSERT_TRUE(base::CopyDirectory(data_path, search_engine_path, false)); 245 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
253 } 246 data_path = data_path.AppendASCII("firefox_searchplugins");
247 base::FilePath default_search_engine_source_path =
248 data_path.AppendASCII("default");
249 base::FilePath custom_search_engine_source_path =
250 data_path.AppendASCII("custom");
251 ASSERT_TRUE(base::CopyDirectory(
252 default_search_engine_source_path, default_search_engine_path, false));
253 ASSERT_TRUE(base::CopyDirectory(
254 custom_search_engine_source_path, custom_search_engine_path, false));
254 255
255 importer::SourceProfile source_profile; 256 importer::SourceProfile source_profile;
256 source_profile.importer_type = importer::TYPE_FIREFOX; 257 source_profile.importer_type = importer::TYPE_FIREFOX;
257 source_profile.app_path = app_path_; 258 source_profile.app_path = app_path_;
258 source_profile.source_path = profile_path_; 259 source_profile.source_path = profile_path_;
259 source_profile.locale = "en-US"; 260 source_profile.locale = "en-US";
260 261
261 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES; 262 int items = importer::HISTORY | importer::PASSWORDS | importer::FAVORITES |
262 if (import_search_plugins) 263 importer::SEARCH_ENGINES;
263 items = items | importer::SEARCH_ENGINES;
264 264
265 // Deletes itself. 265 // Deletes itself.
266 ExternalProcessImporterHost* host = new ExternalProcessImporterHost; 266 ExternalProcessImporterHost* host = new ExternalProcessImporterHost;
267 host->set_observer(observer); 267 host->set_observer(observer);
268 host->StartImportSettings(source_profile, 268 host->StartImportSettings(
269 browser()->profile(), 269 source_profile, browser()->profile(), items, writer);
270 items,
271 make_scoped_refptr(writer).get());
272 base::MessageLoop::current()->Run(); 270 base::MessageLoop::current()->Run();
273 } 271 }
274 272
275 base::ScopedTempDir temp_dir_; 273 base::ScopedTempDir temp_dir_;
276 base::FilePath profile_path_; 274 base::FilePath profile_path_;
277 base::FilePath app_path_; 275 base::FilePath app_path_;
278 }; 276 };
279 277
280 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, 278 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest,
281 MAYBE_IMPORTER(Firefox30Importer)) { 279 MAYBE_IMPORTER(Firefox30Importer)) {
282 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver()); 280 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver());
283 Firefox3xImporterBrowserTest("firefox3_profile", observer.get(), 281 FirefoxImporterBrowserTest(
284 observer.get(), true); 282 "firefox3_profile", observer.get(), observer.get());
285 } 283 }
286 284
287 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest, 285 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest,
288 MAYBE_IMPORTER(Firefox35Importer)) { 286 MAYBE_IMPORTER(Firefox35Importer)) {
289 bool import_search_engines = false; 287 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver());
290 scoped_refptr<FirefoxObserver> observer( 288 FirefoxImporterBrowserTest(
291 new FirefoxObserver(import_search_engines)); 289 "firefox35_profile", observer.get(), observer.get());
292 Firefox3xImporterBrowserTest("firefox35_profile", observer.get(),
293 observer.get(), import_search_engines);
294 } 290 }
291
292 IN_PROC_BROWSER_TEST_F(FirefoxProfileImporterBrowserTest,
293 MAYBE_IMPORTER(FirefoxImporter)) {
294 scoped_refptr<FirefoxObserver> observer(new FirefoxObserver());
295 FirefoxImporterBrowserTest("firefox_profile", observer.get(), observer.get());
296 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/firefox_profile/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698