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

Side by Side Diff: chrome/utility/importer/firefox_importer_unittest.cc

Issue 2296633002: Fix Firefox bookmarks import. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 4 years, 1 month 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 | « chrome/utility/importer/firefox_importer.cc ('k') | no next file » | 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) 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/common/chrome_paths.h" 10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/importer/importer_data_types.h"
12 #include "chrome/common/importer/mock_importer_bridge.h"
13 #include "chrome/utility/importer/firefox_importer.h"
11 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" 14 #include "chrome/utility/importer/firefox_importer_unittest_utils.h"
12 #include "chrome/utility/importer/nss_decryptor.h" 15 #include "chrome/utility/importer/nss_decryptor.h"
13 #include "sql/connection.h" 16 #include "sql/connection.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 18
16 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688 19 // TODO(jschuh): Disabled on Win64 build. http://crbug.com/179688
17 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) 20 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64)
18 #define MAYBE_NSS(x) DISABLED_##x 21 #define MAYBE_NSS(x) DISABLED_##x
19 #else 22 #else
20 #define MAYBE_NSS(x) x 23 #define MAYBE_NSS(x) x
(...skipping 11 matching lines...) Expand all
32 nss_path = nss_path.AppendASCII("firefox3_nss"); 35 nss_path = nss_path.AppendASCII("firefox3_nss");
33 #endif // !OS_MACOSX 36 #endif // !OS_MACOSX
34 base::FilePath db_path; 37 base::FilePath db_path;
35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path)); 38 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &db_path));
36 db_path = db_path.AppendASCII("firefox3_profile"); 39 db_path = db_path.AppendASCII("firefox3_profile");
37 40
38 FFUnitTestDecryptorProxy decryptor_proxy; 41 FFUnitTestDecryptorProxy decryptor_proxy;
39 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); 42 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
40 43
41 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); 44 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
42 EXPECT_EQ(base::ASCIIToUTF16("hello"), 45 EXPECT_EQ(
46 base::ASCIIToUTF16("hello"),
43 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" 47 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"
44 "jtRg4qFSHBAhv9luFkXgDJA==")); 48 "jtRg4qFSHBAhv9luFkXgDJA=="));
45 // Test UTF-16 encoding. 49 // Test UTF-16 encoding.
46 EXPECT_EQ(base::WideToUTF16(L"\x4E2D"), 50 EXPECT_EQ(
51 base::WideToUTF16(L"\x4E2D"),
47 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW" 52 decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECLW"
48 "qqiccfQHWBAie74hxnULxlw==")); 53 "qqiccfQHWBAie74hxnULxlw=="));
49 54
50 // Test empty string edge case. 55 // Test empty string edge case.
51 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string())); 56 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt(std::string()));
52 57
53 // Test invalid base64. 58 // Test invalid base64.
54 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!")); 59 EXPECT_EQ(base::string16(), decryptor_proxy.Decrypt("Not! Valid! Base64!"));
55 } 60 }
56 61
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); 112 ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
108 113
109 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); 114 ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
110 std::vector<autofill::PasswordForm> forms = 115 std::vector<autofill::PasswordForm> forms =
111 decryptor_proxy.ParseSignons(signons_path); 116 decryptor_proxy.ParseSignons(signons_path);
112 117
113 ASSERT_EQ(2u, forms.size()); 118 ASSERT_EQ(2u, forms.size());
114 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme); 119 EXPECT_EQ(autofill::PasswordForm::SCHEME_BASIC, forms[0].scheme);
115 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme); 120 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, forms[1].scheme);
116 } 121 }
122
123 TEST(FirefoxImporterTest, ImportBookmarks) {
124 using ::testing::_;
125 base::FilePath places_path;
126 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path));
127 places_path =
128 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII(
129 "48.0.2");
130 scoped_refptr<FirefoxImporter> importer = new FirefoxImporter;
131 importer::SourceProfile profile;
132 profile.source_path = places_path;
133 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge;
134 std::vector<ImportedBookmarkEntry> bookmarks;
135 favicon_base::FaviconUsageDataList favicons;
Ilya Sherman 2016/10/27 22:00:25 nit: Please #include the appropriate headers for t
kszatan 2016/11/02 08:17:34 Done.
136 EXPECT_CALL(*bridge, NotifyStarted());
137 EXPECT_CALL(*bridge, NotifyItemStarted(importer::FAVORITES));
138 EXPECT_CALL(*bridge, AddBookmarks(_, _))
139 .WillOnce(::testing::SaveArg<0>(&(bookmarks)));
Ilya Sherman 2016/10/27 22:00:25 nit: No need for the parens around bookmarks; ditt
kszatan 2016/11/02 08:17:34 Done.
140 EXPECT_CALL(*bridge, SetFavicons(_))
141 .WillOnce(::testing::SaveArg<0>(&(favicons)));
142 EXPECT_CALL(*bridge, NotifyItemEnded(importer::FAVORITES));
143 EXPECT_CALL(*bridge, NotifyEnded());
144 importer->StartImport(profile, importer::FAVORITES, bridge.get());
145 ASSERT_EQ(6, bookmarks.size());
146 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/central/",
147 bookmarks[0].url.spec());
148 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/help/",
149 bookmarks[1].url.spec());
150 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/customize/",
151 bookmarks[2].url.spec());
152 EXPECT_EQ("https://www.mozilla.org/en-US/contribute/",
153 bookmarks[3].url.spec());
154 EXPECT_EQ("https://www.mozilla.org/en-US/about/", bookmarks[4].url.spec());
155 EXPECT_EQ("https://www.google.com/", bookmarks[5].url.spec());
156 ASSERT_EQ(5, favicons.size());
157 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/0-1473403921346",
158 favicons[0].favicon_url.spec());
159 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/1-1473403921347",
160 favicons[1].favicon_url.spec());
161 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/2-1473403921348",
162 favicons[2].favicon_url.spec());
163 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/3-1473403921349",
164 favicons[3].favicon_url.spec());
165 EXPECT_EQ("http://www.mozilla.org/2005/made-up-favicon/4-1473403921349",
166 favicons[4].favicon_url.spec());
167 }
168
169 TEST(FirefoxImporterTest, ImportHistorySchema) {
170 using ::testing::_;
171 base::FilePath places_path;
172 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &places_path));
173 places_path =
174 places_path.AppendASCII("import").AppendASCII("firefox").AppendASCII(
175 "48.0.2");
176 scoped_refptr<FirefoxImporter> ff_importer = new FirefoxImporter;
177 importer::SourceProfile profile;
178 profile.source_path = places_path;
179 scoped_refptr<MockImporterBridge> bridge = new MockImporterBridge;
180 std::vector<ImporterURLRow> history;
181 EXPECT_CALL(*bridge, NotifyStarted());
182 EXPECT_CALL(*bridge, NotifyItemStarted(importer::HISTORY));
183 EXPECT_CALL(*bridge, SetHistoryItems(_, _))
184 .WillOnce(::testing::SaveArg<0>(&(history)));
185 EXPECT_CALL(*bridge, NotifyItemEnded(importer::HISTORY));
186 EXPECT_CALL(*bridge, NotifyEnded());
187 ff_importer->StartImport(profile, importer::HISTORY, bridge.get());
188 ASSERT_EQ(3, history.size());
189 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/learnmore/",
190 history[0].url.spec());
191 EXPECT_EQ("https://www.mozilla.org/en-US/firefox/48.0.2/firstrun/",
192 history[1].url.spec());
193 EXPECT_EQ("http://google.com/", history[2].url.spec());
194 }
OLDNEW
« no previous file with comments | « chrome/utility/importer/firefox_importer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698