OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/importer/safari_importer.h" | 5 #include "chrome/browser/importer/safari_importer.h" |
6 | 6 |
7 #include "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
| 13 #include "base/string_util.h" |
13 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/history/history_types.h" | 16 #include "chrome/browser/history/history_types.h" |
16 #include "chrome/browser/importer/importer_bridge.h" | 17 #include "chrome/browser/importer/importer_bridge.h" |
17 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
18 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
19 | 20 |
20 // In order to test the Safari import functionality effectively, we store a | 21 // In order to test the Safari import functionality effectively, we store a |
21 // simulated Library directory containing dummy data files in the same | 22 // simulated Library directory containing dummy data files in the same |
22 // structure as ~/Library in the Chrome test data directory. | 23 // structure as ~/Library in the Chrome test data directory. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_EQ(it2.typed_count(), 0); | 70 EXPECT_EQ(it2.typed_count(), 0); |
70 EXPECT_EQ(it2.last_visit().ToDoubleT(), | 71 EXPECT_EQ(it2.last_visit().ToDoubleT(), |
71 importer->HistoryTimeToEpochTime(@"270598231.4")); | 72 importer->HistoryTimeToEpochTime(@"270598231.4")); |
72 } | 73 } |
73 | 74 |
74 TEST_F(SafariImporterTest, BookmarkImport) { | 75 TEST_F(SafariImporterTest, BookmarkImport) { |
75 // Expected results | 76 // Expected results |
76 const struct { | 77 const struct { |
77 bool in_toolbar; | 78 bool in_toolbar; |
78 GURL url; | 79 GURL url; |
79 // If the path array for an element is entry set this to true. | 80 // We store the path with levels of nesting delimited by forward slashes. |
80 bool path_is_empty; | 81 string16 path; |
81 // We ony support one level of nesting in paths, this makes testing a little | 82 string16 title; |
82 // easier. | |
83 std::wstring path; | |
84 std::wstring title; | |
85 } kImportedBookmarksData[] = { | 83 } kImportedBookmarksData[] = { |
86 {true, GURL("http://www.apple.com/"), true, L"", L"Apple"}, | 84 { |
87 {true, GURL("http://www.yahoo.com/"), true, L"", L"Yahoo!"}, | 85 true, |
88 {true, GURL("http://www.cnn.com/"), false, L"News", L"CNN"}, | 86 GURL("http://www.apple.com/"), |
89 {true, GURL("http://www.nytimes.com/"), false, L"News", | 87 ASCIIToUTF16("Toolbar/"), |
90 L"The New York Times"}, | 88 ASCIIToUTF16("Apple") |
91 {false, GURL("http://www.reddit.com/"), true, L"", | 89 }, |
92 L"reddit.com: what's new online!"}, | 90 { |
| 91 true, |
| 92 GURL("http://www.yahoo.com/"), |
| 93 ASCIIToUTF16("Toolbar/"), |
| 94 ASCIIToUTF16("Yahoo!") |
| 95 }, |
| 96 { |
| 97 true, |
| 98 GURL("http://www.cnn.com/"), |
| 99 ASCIIToUTF16("Toolbar/News"), |
| 100 ASCIIToUTF16("CNN") |
| 101 }, |
| 102 { |
| 103 true, |
| 104 GURL("http://www.nytimes.com/"), |
| 105 ASCIIToUTF16("Toolbar/News"), |
| 106 ASCIIToUTF16("The New York Times") |
| 107 }, |
| 108 { |
| 109 false, |
| 110 GURL("http://www.reddit.com/"), |
| 111 ASCIIToUTF16(""), |
| 112 ASCIIToUTF16("reddit.com: what's new online!") |
| 113 }, |
| 114 { |
| 115 false, |
| 116 GURL(), |
| 117 ASCIIToUTF16(""), |
| 118 ASCIIToUTF16("Empty Folder") |
| 119 }, |
| 120 { |
| 121 false, |
| 122 GURL("http://www.webkit.org/blog/"), |
| 123 ASCIIToUTF16(""), |
| 124 ASCIIToUTF16("Surfin' Safari - The WebKit Blog") |
| 125 }, |
93 }; | 126 }; |
94 | 127 |
95 scoped_refptr<SafariImporter> importer(GetSafariImporter()); | 128 scoped_refptr<SafariImporter> importer(GetSafariImporter()); |
96 std::vector<ProfileWriter::BookmarkEntry> bookmarks; | 129 std::vector<ProfileWriter::BookmarkEntry> bookmarks; |
97 importer->ParseBookmarks(&bookmarks); | 130 importer->ParseBookmarks(ASCIIToUTF16("Toolbar"), &bookmarks); |
98 size_t num_bookmarks = bookmarks.size(); | 131 size_t num_bookmarks = bookmarks.size(); |
99 EXPECT_EQ(num_bookmarks, ARRAYSIZE_UNSAFE(kImportedBookmarksData)); | 132 ASSERT_EQ(ARRAYSIZE_UNSAFE(kImportedBookmarksData), num_bookmarks); |
100 | 133 |
101 for (size_t i = 0; i < num_bookmarks; ++i) { | 134 for (size_t i = 0; i < num_bookmarks; ++i) { |
102 ProfileWriter::BookmarkEntry& entry = bookmarks[i]; | 135 ProfileWriter::BookmarkEntry& entry = bookmarks[i]; |
103 EXPECT_EQ(entry.in_toolbar, kImportedBookmarksData[i].in_toolbar); | 136 EXPECT_EQ(kImportedBookmarksData[i].in_toolbar, entry.in_toolbar); |
104 EXPECT_EQ(entry.url, kImportedBookmarksData[i].url); | 137 EXPECT_EQ(kImportedBookmarksData[i].url, entry.url); |
105 if (kImportedBookmarksData[i].path_is_empty) { | 138 |
106 EXPECT_EQ(entry.path.size(), 0U); | 139 std::vector<string16> path; |
107 } else { | 140 Tokenize(kImportedBookmarksData[i].path, ASCIIToUTF16("/"), &path); |
108 EXPECT_EQ(entry.path.size(), 1U); | 141 ASSERT_EQ(path.size(), entry.path.size()); |
109 EXPECT_EQ(UTF16ToWideHack(entry.path[0]), kImportedBookmarksData[i].path); | 142 for (size_t j = 0; j < path.size(); ++j) { |
110 EXPECT_EQ(UTF16ToWideHack(entry.title), kImportedBookmarksData[i].title); | 143 EXPECT_EQ(path[j], entry.path[j]); |
111 } | 144 } |
| 145 |
| 146 EXPECT_EQ(kImportedBookmarksData[i].title, entry.title); |
112 } | 147 } |
113 } | 148 } |
114 | 149 |
115 TEST_F(SafariImporterTest, FaviconImport) { | 150 TEST_F(SafariImporterTest, FaviconImport) { |
116 scoped_refptr<SafariImporter> importer(GetSafariImporter()); | 151 scoped_refptr<SafariImporter> importer(GetSafariImporter()); |
117 sql::Connection db; | 152 sql::Connection db; |
118 ASSERT_TRUE(importer->OpenDatabase(&db)); | 153 ASSERT_TRUE(importer->OpenDatabase(&db)); |
119 | 154 |
120 SafariImporter::FaviconMap favicon_map; | 155 SafariImporter::FaviconMap favicon_map; |
121 importer->ImportFaviconURLs(&db, &favicon_map); | 156 importer->ImportFaviconURLs(&db, &favicon_map); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 EXPECT_EQ(items & importer::COOKIES, importer::NONE); | 189 EXPECT_EQ(items & importer::COOKIES, importer::NONE); |
155 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE); | 190 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE); |
156 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE); | 191 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE); |
157 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); | 192 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); |
158 | 193 |
159 // Check that we don't import anything from a bogus library directory. | 194 // Check that we don't import anything from a bogus library directory. |
160 ScopedTempDir fake_library_dir; | 195 ScopedTempDir fake_library_dir; |
161 ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir()); | 196 ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir()); |
162 EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir.path(), &items)); | 197 EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir.path(), &items)); |
163 } | 198 } |
OLD | NEW |