Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/bookmarks/bookmark_html_writer.h" | 5 #include "chrome/browser/bookmarks/bookmark_html_writer.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/favicon/favicon_service.h" | 16 #include "chrome/browser/favicon/favicon_service.h" |
| 17 #include "chrome/browser/favicon/favicon_service_factory.h" | 17 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 18 #include "chrome/browser/history/history_service.h" | 18 #include "chrome/browser/history/history_service.h" |
| 19 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
| 20 #include "chrome/common/importer/imported_bookmark_entry.h" | 20 #include "chrome/common/importer/imported_bookmark_entry.h" |
| 21 #include "chrome/common/importer/importer_data_types.h" | |
|
Ilya Sherman
2014/11/07 00:22:34
nit: The presubmit warning was warning you that th
Tapu Ghose
2014/11/09 14:03:06
Done.
| |
| 21 #include "chrome/common/importer/imported_favicon_usage.h" | 22 #include "chrome/common/importer/imported_favicon_usage.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 23 #include "chrome/utility/importer/bookmark_html_reader.h" | 24 #include "chrome/utility/importer/bookmark_html_reader.h" |
| 24 #include "components/bookmarks/browser/bookmark_model.h" | 25 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/bookmarks/test/bookmark_test_helpers.h" | 26 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "grit/components_strings.h" | 28 #include "grit/components_strings.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "third_party/skia/include/core/SkBitmap.h" | 30 #include "third_party/skia/include/core/SkBitmap.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 BookmarksObserver observer(&run_loop); | 234 BookmarksObserver observer(&run_loop); |
| 234 bookmark_html_writer::WriteBookmarks(&profile, path_, &observer); | 235 bookmark_html_writer::WriteBookmarks(&profile, path_, &observer); |
| 235 run_loop.Run(); | 236 run_loop.Run(); |
| 236 | 237 |
| 237 // Clear favicon so that it would be read from file. | 238 // Clear favicon so that it would be read from file. |
| 238 FaviconServiceFactory::GetForProfile(&profile, Profile::EXPLICIT_ACCESS) | 239 FaviconServiceFactory::GetForProfile(&profile, Profile::EXPLICIT_ACCESS) |
| 239 ->SetFavicons(url1, url1_favicon, favicon_base::FAVICON, gfx::Image()); | 240 ->SetFavicons(url1, url1_favicon, favicon_base::FAVICON, gfx::Image()); |
| 240 | 241 |
| 241 // Read the bookmarks back in. | 242 // Read the bookmarks back in. |
| 242 std::vector<ImportedBookmarkEntry> parsed_bookmarks; | 243 std::vector<ImportedBookmarkEntry> parsed_bookmarks; |
| 244 std::vector<importer::SearchEngineInfo> parsed_search_engines; | |
| 243 std::vector<ImportedFaviconUsage> favicons; | 245 std::vector<ImportedFaviconUsage> favicons; |
| 244 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), | 246 bookmark_html_reader::ImportBookmarksFile(base::Callback<bool(void)>(), |
| 245 base::Callback<bool(const GURL&)>(), | 247 base::Callback<bool(const GURL&)>(), |
| 246 path_, | 248 path_, |
| 247 &parsed_bookmarks, | 249 &parsed_bookmarks, |
| 250 &parsed_search_engines, | |
| 248 &favicons); | 251 &favicons); |
| 249 | 252 |
| 250 // Check loaded favicon (url1 is represented by 4 separate bookmarks). | 253 // Check loaded favicon (url1 is represented by 4 separate bookmarks). |
| 251 EXPECT_EQ(4U, favicons.size()); | 254 EXPECT_EQ(4U, favicons.size()); |
| 252 for (size_t i = 0; i < favicons.size(); i++) { | 255 for (size_t i = 0; i < favicons.size(); i++) { |
| 253 if (url1_favicon == favicons[i].favicon_url) { | 256 if (url1_favicon == favicons[i].favicon_url) { |
| 254 EXPECT_EQ(1U, favicons[i].urls.size()); | 257 EXPECT_EQ(1U, favicons[i].urls.size()); |
| 255 std::set<GURL>::const_iterator iter = favicons[i].urls.find(url1); | 258 std::set<GURL>::const_iterator iter = favicons[i].urls.find(url1); |
| 256 ASSERT_TRUE(iter != favicons[i].urls.end()); | 259 ASSERT_TRUE(iter != favicons[i].urls.end()); |
| 257 ASSERT_TRUE(*iter == url1); | 260 ASSERT_TRUE(*iter == url1); |
| 258 ASSERT_TRUE(favicons[i].png_data == icon_data); | 261 ASSERT_TRUE(favicons[i].png_data == icon_data); |
| 259 } | 262 } |
| 260 } | 263 } |
| 261 | 264 |
| 265 // Since we did not populate the BookmarkModel with any entry which can be | |
| 266 // imported as search engine, verify that we got back no search engine. | |
|
Ilya Sherman
2014/11/07 00:22:34
nit: "no search engine" -> "no search engines"
Tapu Ghose
2014/11/09 14:03:06
Done.
| |
| 267 ASSERT_EQ(0U, parsed_search_engines.size()); | |
| 268 | |
| 262 // Verify we got back what we wrote. | 269 // Verify we got back what we wrote. |
| 263 ASSERT_EQ(9U, parsed_bookmarks.size()); | 270 ASSERT_EQ(9U, parsed_bookmarks.size()); |
| 264 // Windows and ChromeOS builds use Sentence case. | 271 // Windows and ChromeOS builds use Sentence case. |
| 265 base::string16 bookmark_folder_name = | 272 base::string16 bookmark_folder_name = |
| 266 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME); | 273 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME); |
| 267 AssertBookmarkEntryEquals(parsed_bookmarks[0], true, url1, url1_title, t1, | 274 AssertBookmarkEntryEquals(parsed_bookmarks[0], true, url1, url1_title, t1, |
| 268 bookmark_folder_name, f1_title, base::string16()); | 275 bookmark_folder_name, f1_title, base::string16()); |
| 269 AssertBookmarkEntryEquals(parsed_bookmarks[1], true, url2, url2_title, t2, | 276 AssertBookmarkEntryEquals(parsed_bookmarks[1], true, url2, url2_title, t2, |
| 270 bookmark_folder_name, f1_title, f2_title); | 277 bookmark_folder_name, f1_title, f2_title); |
| 271 AssertBookmarkEntryEquals(parsed_bookmarks[2], true, url3, url3_title, t3, | 278 AssertBookmarkEntryEquals(parsed_bookmarks[2], true, url3, url3_title, t3, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 283 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, | 290 AssertBookmarkEntryEquals(parsed_bookmarks[6], false, url1, url1_title, t1, |
| 284 f3_title, f4_title, base::string16()); | 291 f3_title, f4_title, base::string16()); |
| 285 AssertBookmarkEntryEquals(parsed_bookmarks[7], false, url1, url1_title, t1, | 292 AssertBookmarkEntryEquals(parsed_bookmarks[7], false, url1, url1_title, t1, |
| 286 base::string16(), base::string16(), | 293 base::string16(), base::string16(), |
| 287 base::string16()); | 294 base::string16()); |
| 288 AssertBookmarkEntryEquals(parsed_bookmarks[8], false, unnamed_bookmark_url, | 295 AssertBookmarkEntryEquals(parsed_bookmarks[8], false, unnamed_bookmark_url, |
| 289 unnamed_bookmark_title, t2, | 296 unnamed_bookmark_title, t2, |
| 290 base::string16(), base::string16(), | 297 base::string16(), base::string16(), |
| 291 base::string16()); | 298 base::string16()); |
| 292 } | 299 } |
| OLD | NEW |