// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "testing/gtest/include/gtest/gtest.h" #include #include #include "chrome/browser/importer/importer.h" #include "chrome/browser/importer/toolbar_importer.h" #include "chrome/common/libxml_utils.h" #include "googleurl/src/gurl.h" // See http://crbug.com/11838 TEST(Toolbar5ImporterTest, DISABLED_BookmarkParse) { #if 0 // Compile breaks if you remove this and leave the test disabled static const wchar_t* kTitle = L"MyTitle"; static const char* kUrl = "http://www.google.com/"; static const wchar_t* kFolder = L"Google"; static const wchar_t* kFolder2 = L"Homepage"; static const wchar_t* kFolderArray[3] = {L"Google", L"Search", L"Page"}; static const wchar_t* kOtherTitle = L"MyOtherTitle"; static const char* kOtherUrl = "http://www.google.com/mail"; static const wchar_t* kOtherFolder = L"Mail"; // Since the following is very dense to read I enumerate the test cases here. // 1. Correct bookmark structure with one label. // 2. Correct bookmark structure with no labels. // 3. Correct bookmark structure with two labels. // 4. Correct bookmark structure with a folder->label translation by toolbar. // 5. Correct bookmark structure with no favicon. // 6. Two correct bookmarks. // The following are error cases by removing sections from the xml: // 7. Empty string passed as xml. // 8. No section in the xml. // 9. No section below the section. // 10. No in a <bookmark> section. // 11. No <url> in a <bookmark> section. // 12. No <timestamp> in a <bookmark> section. // 13. No <labels> in a <bookmark> section. static const char* kGoodBookmark = "<?xml version=\"1.0\" ?> <xml_api_reply version=\"1\"> <bookmarks>" " <bookmark> " "<title>MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kGoodBookmarkNoLabel = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kGoodBookmarkTwoLabels = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kGoodBookmarkFolderLabel = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kGoodBookmarkNoFavicon = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kGoodBookmark2Items = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " "" " " "MyOtherTitle " "http://www.google.com/mail " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url" "http://www.google.com/mail/favicon.ico " " " " " "favicon_timestamp 1253328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " "" ""; static const char* kEmptyString = ""; static const char* kBadBookmarkNoBookmarks = " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kBadBookmarkNoBookmark = " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kBadBookmarkNoTitle = " " " " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kBadBookmarkNoUrl = " " " " "MyTitle " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kBadBookmarkNoTimestamp = " " " " "MyTitle " "http://www.google.com/ " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; static const char* kBadBookmarkNoLabels = " " " " "MyTitle " "http://www.google.com/ " "1153328691085181 " "N123nasdf239 Bxxxxxxx " "Sxxxxxx 0" " " " " "favicon_url http://www.google.com/favicon.ico " " " " " "favicon_timestamp 1153328653 " " " " notebook_name My notebook 0 " " " " section_name My section 0 " " " " "; XmlReader reader; std::string bookmark_xml; std::vector bookmarks; const GURL url(toolbar_importer_unittest::kUrl); const GURL other_url(toolbar_importer_unittest::kOtherUrl); // Test case 1 is parsing a basic bookmark with a single label. bookmark_xml = toolbar_importer_unittest::kGoodBookmark; bookmarks.clear(); XmlReader reader1; EXPECT_TRUE(reader1.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader1, &bookmarks)); ASSERT_EQ(1U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(url, bookmarks[0].url); ASSERT_EQ(2U, bookmarks[0].path.size()); EXPECT_EQ(toolbar_importer_unittest::kFolder, bookmarks[0].path[1]); // Test case 2 is parsing a single bookmark with no label. bookmark_xml = toolbar_importer_unittest::kGoodBookmarkNoLabel; bookmarks.clear(); XmlReader reader2; EXPECT_TRUE(reader2.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader2, &bookmarks)); ASSERT_EQ(1U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(url, bookmarks[0].url); EXPECT_EQ(1U, bookmarks[0].path.size()); // Test case 3 is parsing a single bookmark with two labels. bookmark_xml = toolbar_importer_unittest::kGoodBookmarkTwoLabels; bookmarks.clear(); XmlReader reader3; EXPECT_TRUE(reader3.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader3, &bookmarks)); ASSERT_EQ(2U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_FALSE(bookmarks[1].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[1].title); EXPECT_EQ(url, bookmarks[0].url); EXPECT_EQ(url, bookmarks[1].url); ASSERT_EQ(2U, bookmarks[0].path.size()); EXPECT_EQ(toolbar_importer_unittest::kFolder, bookmarks[0].path[1]); ASSERT_EQ(2U, bookmarks[1].path.size()); EXPECT_EQ(toolbar_importer_unittest::kFolder2, bookmarks[1].path[1]); // Test case 4 is parsing a single bookmark which has a label with a colon, // this test file name translation between Toolbar and Chrome. bookmark_xml = toolbar_importer_unittest::kGoodBookmarkFolderLabel; bookmarks.clear(); XmlReader reader4; EXPECT_TRUE(reader4.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader4, &bookmarks)); ASSERT_EQ(1U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(url, bookmarks[0].url); ASSERT_EQ(4U, bookmarks[0].path.size()); EXPECT_EQ(std::wstring(toolbar_importer_unittest::kFolderArray[0]), bookmarks[0].path[1]); EXPECT_EQ(std::wstring(toolbar_importer_unittest::kFolderArray[1]), bookmarks[0].path[2]); EXPECT_EQ(std::wstring(toolbar_importer_unittest::kFolderArray[2]), bookmarks[0].path[3]); // Test case 5 is parsing a single bookmark without a favicon URL. bookmark_xml = toolbar_importer_unittest::kGoodBookmarkNoFavicon; bookmarks.clear(); XmlReader reader5; EXPECT_TRUE(reader5.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader5, &bookmarks)); ASSERT_EQ(1U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(url, bookmarks[0].url); ASSERT_EQ(2U, bookmarks[0].path.size()); EXPECT_EQ(toolbar_importer_unittest::kFolder, bookmarks[0].path[1]); // Test case 6 is parsing two bookmarks. bookmark_xml = toolbar_importer_unittest::kGoodBookmark2Items; bookmarks.clear(); XmlReader reader6; EXPECT_TRUE(reader6.Load(bookmark_xml)); EXPECT_TRUE(Toolbar5Importer::ParseBookmarksFromReader(&reader6, &bookmarks)); ASSERT_EQ(2U, bookmarks.size()); EXPECT_FALSE(bookmarks[0].in_toolbar); EXPECT_FALSE(bookmarks[1].in_toolbar); EXPECT_EQ(toolbar_importer_unittest::kTitle, bookmarks[0].title); EXPECT_EQ(toolbar_importer_unittest::kOtherTitle, bookmarks[1].title); EXPECT_EQ(url, bookmarks[0].url); EXPECT_EQ(other_url, bookmarks[1].url); ASSERT_EQ(2U, bookmarks[0].path.size()); EXPECT_EQ(toolbar_importer_unittest::kFolder, bookmarks[0].path[1]); ASSERT_EQ(2U, bookmarks[1].path.size()); EXPECT_EQ(toolbar_importer_unittest::kOtherFolder, bookmarks[1].path[1]); // Test case 7 is parsing an empty string for bookmarks. bookmark_xml = toolbar_importer_unittest::kEmptyString; bookmarks.clear(); XmlReader reader7; EXPECT_FALSE(reader7.Load(bookmark_xml)); // Test case 8 is testing the error when no section is present. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoBookmarks; bookmarks.clear(); XmlReader reader8; EXPECT_TRUE(reader8.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader8, &bookmarks)); // Test case 9 tests when no section is present. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoBookmark; bookmarks.clear(); XmlReader reader9; EXPECT_TRUE(reader9.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader9, &bookmarks)); // Test case 10 tests when a bookmark has no section. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoTitle; bookmarks.clear(); XmlReader reader10; EXPECT_TRUE(reader10.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader10, &bookmarks)); // Test case 11 tests when a bookmark has no <url> section. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoUrl; bookmarks.clear(); XmlReader reader11; EXPECT_TRUE(reader11.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader11, &bookmarks)); // Test case 12 tests when a bookmark has no <timestamp> section. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoTimestamp; bookmarks.clear(); XmlReader reader12; EXPECT_TRUE(reader12.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader12, &bookmarks)); // Test case 13 tests when a bookmark has no <labels> section. bookmark_xml = toolbar_importer_unittest::kBadBookmarkNoLabels; bookmarks.clear(); XmlReader reader13; EXPECT_TRUE(reader13.Load(bookmark_xml)); EXPECT_FALSE(Toolbar5Importer::ParseBookmarksFromReader(&reader13, &bookmarks)); #endif }