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

Side by Side Diff: chrome/utility/importer/safari_importer_unittest.mm

Issue 119833002: [Import] [OSX] Don't create an empty folder when importing from Safari with an empty Bookmarks Menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extraneous files, update READMEs Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/utility/importer/safari_importer.mm ('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 "chrome/utility/importer/safari_importer.h" 5 #include "chrome/utility/importer/safari_importer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/utility/importer/safari_importer.h" 21 #include "chrome/utility/importer/safari_importer.h"
22 #include "sql/connection.h" 22 #include "sql/connection.h"
23 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
24 24
25 using base::ASCIIToUTF16; 25 using base::ASCIIToUTF16;
26 26
27 // In order to test the Safari import functionality effectively, we store a 27 // In order to test the Safari import functionality effectively, we store a
28 // simulated Library directory containing dummy data files in the same 28 // simulated Library directory containing dummy data files in the same
29 // structure as ~/Library in the Chrome test data directory. 29 // structure as ~/Library in the Chrome test data directory.
30 // This function returns the path to that directory. 30 // This function returns the path to that directory.
31 base::FilePath GetTestSafariLibraryPath() { 31 base::FilePath GetTestSafariLibraryPath(const std::string& suffix) {
32 base::FilePath test_dir; 32 base::FilePath test_dir;
33 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); 33 PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
34 34
35 // Our simulated ~/Library directory 35 // Our simulated ~/Library directory
36 test_dir = test_dir.AppendASCII("safari_import"); 36 return
37 return test_dir; 37 test_dir.AppendASCII("import").AppendASCII("safari").AppendASCII(suffix);
38 } 38 }
39 39
40 class SafariImporterTest : public PlatformTest { 40 class SafariImporterTest : public PlatformTest {
41 public: 41 public:
42 SafariImporter* GetSafariImporter() { 42 SafariImporter* GetSafariImporter() {
43 base::FilePath test_library_dir = GetTestSafariLibraryPath(); 43 return GetSafariImporterWithPathSuffix("default");
44 CHECK(base::PathExists(test_library_dir)) << 44 }
45 "Missing test data directory";
46 45
46 SafariImporter* GetSafariImporterWithPathSuffix(const std::string& suffix) {
47 base::FilePath test_library_dir = GetTestSafariLibraryPath(suffix);
48 CHECK(base::PathExists(test_library_dir));
47 return new SafariImporter(test_library_dir); 49 return new SafariImporter(test_library_dir);
48 } 50 }
49 }; 51 };
50 52
51 TEST_F(SafariImporterTest, HistoryImport) { 53 TEST_F(SafariImporterTest, HistoryImport) {
52 scoped_refptr<SafariImporter> importer(GetSafariImporter()); 54 scoped_refptr<SafariImporter> importer(GetSafariImporter());
53 55
54 std::vector<ImporterURLRow> history_items; 56 std::vector<ImporterURLRow> history_items;
55 importer->ParseHistoryItems(&history_items); 57 importer->ParseHistoryItems(&history_items);
56 58
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 Tokenize(kImportedBookmarksData[i].path, ASCIIToUTF16("/"), &path); 148 Tokenize(kImportedBookmarksData[i].path, ASCIIToUTF16("/"), &path);
147 ASSERT_EQ(path.size(), entry.path.size()); 149 ASSERT_EQ(path.size(), entry.path.size());
148 for (size_t j = 0; j < path.size(); ++j) { 150 for (size_t j = 0; j < path.size(); ++j) {
149 EXPECT_EQ(path[j], entry.path[j]); 151 EXPECT_EQ(path[j], entry.path[j]);
150 } 152 }
151 153
152 EXPECT_EQ(kImportedBookmarksData[i].title, entry.title); 154 EXPECT_EQ(kImportedBookmarksData[i].title, entry.title);
153 } 155 }
154 } 156 }
155 157
158 TEST_F(SafariImporterTest, BookmarkImportWithEmptyBookmarksMenu) {
159 // Expected results.
160 const struct {
161 bool in_toolbar;
162 GURL url;
163 // We store the path with levels of nesting delimited by forward slashes.
164 base::string16 path;
165 base::string16 title;
166 } kImportedBookmarksData[] = {
167 {
168 true,
169 GURL("http://www.apple.com/"),
170 ASCIIToUTF16("Toolbar/"),
171 ASCIIToUTF16("Apple")
172 },
173 {
174 true,
175 GURL("http://www.yahoo.com/"),
176 ASCIIToUTF16("Toolbar/"),
177 ASCIIToUTF16("Yahoo!")
178 },
179 {
180 true,
181 GURL("http://www.cnn.com/"),
182 ASCIIToUTF16("Toolbar/News"),
183 ASCIIToUTF16("CNN")
184 },
185 {
186 true,
187 GURL("http://www.nytimes.com/"),
188 ASCIIToUTF16("Toolbar/News"),
189 ASCIIToUTF16("The New York Times")
190 },
191 {
192 false,
193 GURL("http://www.webkit.org/blog/"),
194 base::string16(),
195 ASCIIToUTF16("Surfin' Safari - The WebKit Blog")
196 },
197 };
198
199 scoped_refptr<SafariImporter> importer(
200 GetSafariImporterWithPathSuffix("empty_bookmarks_menu"));
201 std::vector<ImportedBookmarkEntry> bookmarks;
202 importer->ParseBookmarks(ASCIIToUTF16("Toolbar"), &bookmarks);
203 size_t num_bookmarks = bookmarks.size();
204 ASSERT_EQ(ARRAYSIZE_UNSAFE(kImportedBookmarksData), num_bookmarks);
205
206 for (size_t i = 0; i < num_bookmarks; ++i) {
207 ImportedBookmarkEntry& entry = bookmarks[i];
208 EXPECT_EQ(kImportedBookmarksData[i].in_toolbar, entry.in_toolbar);
209 EXPECT_EQ(kImportedBookmarksData[i].url, entry.url);
210
211 std::vector<base::string16> path;
212 Tokenize(kImportedBookmarksData[i].path, ASCIIToUTF16("/"), &path);
213 ASSERT_EQ(path.size(), entry.path.size());
214 for (size_t j = 0; j < path.size(); ++j) {
215 EXPECT_EQ(path[j], entry.path[j]);
216 }
217
218 EXPECT_EQ(kImportedBookmarksData[i].title, entry.title);
219 }
220 }
221
156 TEST_F(SafariImporterTest, FaviconImport) { 222 TEST_F(SafariImporterTest, FaviconImport) {
157 scoped_refptr<SafariImporter> importer(GetSafariImporter()); 223 scoped_refptr<SafariImporter> importer(GetSafariImporter());
158 sql::Connection db; 224 sql::Connection db;
159 ASSERT_TRUE(importer->OpenDatabase(&db)); 225 ASSERT_TRUE(importer->OpenDatabase(&db));
160 226
161 SafariImporter::FaviconMap favicon_map; 227 SafariImporter::FaviconMap favicon_map;
162 importer->ImportFaviconURLs(&db, &favicon_map); 228 importer->ImportFaviconURLs(&db, &favicon_map);
163 229
164 std::vector<ImportedFaviconUsage> favicons; 230 std::vector<ImportedFaviconUsage> favicons;
165 importer->LoadFaviconData(&db, favicon_map, &favicons); 231 importer->LoadFaviconData(&db, favicon_map, &favicons);
(...skipping 17 matching lines...) Expand all
183 EXPECT_TRUE(fav1.urls.find(GURL("http://www.opensearch.org/Home")) 249 EXPECT_TRUE(fav1.urls.find(GURL("http://www.opensearch.org/Home"))
184 != fav1.urls.end()); 250 != fav1.urls.end());
185 251
186 EXPECT_TRUE(fav1.urls.find( 252 EXPECT_TRUE(fav1.urls.find(
187 GURL("http://www.opensearch.org/Special:Search?search=lalala&go=Search")) 253 GURL("http://www.opensearch.org/Special:Search?search=lalala&go=Search"))
188 != fav1.urls.end()); 254 != fav1.urls.end());
189 } 255 }
190 256
191 TEST_F(SafariImporterTest, CanImport) { 257 TEST_F(SafariImporterTest, CanImport) {
192 uint16 items = importer::NONE; 258 uint16 items = importer::NONE;
193 EXPECT_TRUE(SafariImporterCanImport(GetTestSafariLibraryPath(), &items)); 259 EXPECT_TRUE(SafariImporterCanImport(
260 GetTestSafariLibraryPath("default"), &items));
194 EXPECT_EQ(items, importer::HISTORY | importer::FAVORITES); 261 EXPECT_EQ(items, importer::HISTORY | importer::FAVORITES);
195 EXPECT_EQ(items & importer::COOKIES, importer::NONE); 262 EXPECT_EQ(items & importer::COOKIES, importer::NONE);
196 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE); 263 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE);
197 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE); 264 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE);
198 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); 265 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE);
199 266
200 // Check that we don't import anything from a bogus library directory. 267 // Check that we don't import anything from a bogus library directory.
201 base::ScopedTempDir fake_library_dir; 268 base::ScopedTempDir fake_library_dir;
202 ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir()); 269 ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir());
203 EXPECT_FALSE(SafariImporterCanImport(fake_library_dir.path(), &items)); 270 EXPECT_FALSE(SafariImporterCanImport(fake_library_dir.path(), &items));
204 } 271 }
OLDNEW
« no previous file with comments | « chrome/utility/importer/safari_importer.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698