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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 class BookmarkHTMLWriterTest : public TestingBrowserProcessTest { | 44 class BookmarkHTMLWriterTest : public TestingBrowserProcessTest { |
45 protected: | 45 protected: |
46 virtual void SetUp() { | 46 virtual void SetUp() { |
47 TestingBrowserProcessTest::SetUp(); | 47 TestingBrowserProcessTest::SetUp(); |
48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
49 path_ = temp_dir_.path().AppendASCII("bookmarks.html"); | 49 path_ = temp_dir_.path().AppendASCII("bookmarks.html"); |
50 } | 50 } |
51 | 51 |
52 // Converts a BookmarkEntry to a string suitable for assertion testing. | 52 // Converts a BookmarkEntry to a string suitable for assertion testing. |
53 string16 BookmarkEntryToString( | 53 string16 BookmarkEntryToString(const ProfileWriter::BookmarkEntry& entry) { |
54 const ProfileWriter::BookmarkEntry& entry) { | |
55 string16 result; | 54 string16 result; |
56 result.append(ASCIIToUTF16("on_toolbar=")); | 55 result.append(ASCIIToUTF16("on_toolbar=")); |
57 if (entry.in_toolbar) | 56 if (entry.in_toolbar) |
| 57 result.append(ASCIIToUTF16("true")); |
| 58 else |
58 result.append(ASCIIToUTF16("false")); | 59 result.append(ASCIIToUTF16("false")); |
59 else | |
60 result.append(ASCIIToUTF16("true")); | |
61 | 60 |
62 result.append(ASCIIToUTF16(" url=") + UTF8ToUTF16(entry.url.spec())); | 61 result.append(ASCIIToUTF16(" url=") + UTF8ToUTF16(entry.url.spec())); |
63 | 62 |
64 result.append(ASCIIToUTF16(" path=")); | 63 result.append(ASCIIToUTF16(" path=")); |
65 for (size_t i = 0; i < entry.path.size(); ++i) { | 64 for (size_t i = 0; i < entry.path.size(); ++i) { |
66 if (i != 0) | 65 if (i != 0) |
67 result.append(ASCIIToUTF16("/")); | 66 result.append(ASCIIToUTF16("/")); |
68 result.append(entry.path[i]); | 67 result.append(entry.path[i]); |
69 } | 68 } |
70 | 69 |
71 result.append(ASCIIToUTF16(" title=")); | 70 result.append(ASCIIToUTF16(" title=")); |
72 result.append(entry.title); | 71 result.append(entry.title); |
73 | 72 |
74 result.append(ASCIIToUTF16(" time=")); | 73 result.append(ASCIIToUTF16(" time=")); |
75 result.append(base::TimeFormatFriendlyDateAndTime(entry.creation_time)); | 74 result.append(base::TimeFormatFriendlyDateAndTime(entry.creation_time)); |
76 return result; | 75 return result; |
77 } | 76 } |
78 | 77 |
79 // Creates a set of bookmark values to a string for assertion testing. | 78 // Creates a set of bookmark values to a string for assertion testing. |
80 string16 BookmarkValuesToString(bool on_toolbar, | 79 string16 BookmarkValuesToString(bool on_toolbar, |
81 const GURL& url, | 80 const GURL& url, |
82 const string16& title, | 81 const string16& title, |
83 base::Time creation_time, | 82 base::Time creation_time, |
84 const string16& f1, | 83 const string16& f1, |
85 const string16& f2, | 84 const string16& f2, |
86 const string16& f3) { | 85 const string16& f3) { |
87 ProfileWriter::BookmarkEntry entry; | 86 ProfileWriter::BookmarkEntry entry; |
88 entry.in_toolbar = on_toolbar; | 87 entry.in_toolbar = on_toolbar; |
89 entry.url = url; | 88 entry.url = url; |
90 // The first path element should always be 'x', as that is what we passed | |
91 // to the importer. | |
92 entry.path.push_back(ASCIIToUTF16("x")); | |
93 if (!f1.empty()) { | 89 if (!f1.empty()) { |
94 entry.path.push_back(f1); | 90 entry.path.push_back(f1); |
95 if (!f2.empty()) { | 91 if (!f2.empty()) { |
96 entry.path.push_back(f2); | 92 entry.path.push_back(f2); |
97 if (!f3.empty()) | 93 if (!f3.empty()) |
98 entry.path.push_back(f3); | 94 entry.path.push_back(f3); |
99 } | 95 } |
100 } | 96 } |
101 entry.title = title; | 97 entry.title = title; |
102 entry.creation_time = creation_time; | 98 entry.creation_time = creation_time; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 std::vector<unsigned char> empty_data; | 214 std::vector<unsigned char> empty_data; |
219 profile.GetFaviconService(Profile::EXPLICIT_ACCESS)->SetFavicon(url1, | 215 profile.GetFaviconService(Profile::EXPLICIT_ACCESS)->SetFavicon(url1, |
220 url1_favicon, empty_data, history::FAVICON); | 216 url1_favicon, empty_data, history::FAVICON); |
221 message_loop.RunAllPending(); | 217 message_loop.RunAllPending(); |
222 | 218 |
223 // Read the bookmarks back in. | 219 // Read the bookmarks back in. |
224 std::vector<ProfileWriter::BookmarkEntry> parsed_bookmarks; | 220 std::vector<ProfileWriter::BookmarkEntry> parsed_bookmarks; |
225 std::vector<history::ImportedFaviconUsage> favicons; | 221 std::vector<history::ImportedFaviconUsage> favicons; |
226 Firefox2Importer::ImportBookmarksFile(path_, | 222 Firefox2Importer::ImportBookmarksFile(path_, |
227 std::set<GURL>(), | 223 std::set<GURL>(), |
228 false, | |
229 ASCIIToUTF16("x"), | |
230 NULL, | 224 NULL, |
231 &parsed_bookmarks, | 225 &parsed_bookmarks, |
232 NULL, | 226 NULL, |
233 &favicons); | 227 &favicons); |
234 | 228 |
235 // Check loaded favicon (url1 is represents by 3 separate bookmarks). | 229 // Check loaded favicon (url1 is represents by 3 separate bookmarks). |
236 EXPECT_EQ(3U, favicons.size()); | 230 EXPECT_EQ(3U, favicons.size()); |
237 for (size_t i = 0; i < favicons.size(); i++) { | 231 for (size_t i = 0; i < favicons.size(); i++) { |
238 if (url1_favicon == favicons[i].favicon_url) { | 232 if (url1_favicon == favicons[i].favicon_url) { |
239 EXPECT_EQ(1U, favicons[i].urls.size()); | 233 EXPECT_EQ(1U, favicons[i].urls.size()); |
240 std::set<GURL>::const_iterator iter = favicons[i].urls.find(url1); | 234 std::set<GURL>::const_iterator iter = favicons[i].urls.find(url1); |
241 ASSERT_TRUE(iter != favicons[i].urls.end()); | 235 ASSERT_TRUE(iter != favicons[i].urls.end()); |
242 ASSERT_TRUE(*iter == url1); | 236 ASSERT_TRUE(*iter == url1); |
243 ASSERT_TRUE(favicons[i].png_data == icon_data); | 237 ASSERT_TRUE(favicons[i].png_data == icon_data); |
244 } | 238 } |
245 } | 239 } |
246 | 240 |
247 // Verify we got back what we wrote. | 241 // Verify we got back what we wrote. |
248 ASSERT_EQ(7U, parsed_bookmarks.size()); | 242 ASSERT_EQ(7U, parsed_bookmarks.size()); |
249 // Windows and ChromeOS builds use Sentence case. | 243 // Windows and ChromeOS builds use Sentence case. |
250 string16 bookmark_folder_name = | 244 string16 bookmark_folder_name = |
251 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME); | 245 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME); |
252 AssertBookmarkEntryEquals(parsed_bookmarks[0], false, url1, url1_title, t1, | 246 AssertBookmarkEntryEquals(parsed_bookmarks[0], true, url1, url1_title, t1, |
253 bookmark_folder_name, f1_title, string16()); | 247 bookmark_folder_name, f1_title, string16()); |
254 AssertBookmarkEntryEquals(parsed_bookmarks[1], false, url2, url2_title, t2, | 248 AssertBookmarkEntryEquals(parsed_bookmarks[1], true, url2, url2_title, t2, |
255 bookmark_folder_name, f1_title, f2_title); | 249 bookmark_folder_name, f1_title, f2_title); |
256 AssertBookmarkEntryEquals(parsed_bookmarks[2], false, url3, url3_title, t3, | 250 AssertBookmarkEntryEquals(parsed_bookmarks[2], true, url3, url3_title, t3, |
257 bookmark_folder_name, string16(), string16()); | 251 bookmark_folder_name, string16(), string16()); |
258 AssertBookmarkEntryEquals(parsed_bookmarks[3], false, url4, url4_title, t4, | 252 AssertBookmarkEntryEquals(parsed_bookmarks[3], true, url4, url4_title, t4, |
259 bookmark_folder_name, string16(), string16()); | 253 bookmark_folder_name, string16(), string16()); |
260 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, | 254 AssertBookmarkEntryEquals(parsed_bookmarks[4], false, url1, url1_title, t1, |
261 string16(), string16(), string16()); | 255 string16(), string16(), string16()); |
262 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, | 256 AssertBookmarkEntryEquals(parsed_bookmarks[5], false, url2, url2_title, t2, |
263 string16(), string16(), string16()); | 257 string16(), string16(), string16()); |
264 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, | 258 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, |
265 f3_title, f4_title, string16()); | 259 f3_title, f4_title, string16()); |
266 } | 260 } |
OLD | NEW |