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

Side by Side Diff: chrome/browser/bookmarks/bookmark_html_writer_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698