Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / profile_sync_service_bookmark_unittest.cc
index 1a57075..44a493f 100644 (file)
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
-#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/bookmarks/bookmark_test_helpers.h"
 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
 #include "chrome/browser/sync/glue/bookmark_model_associator.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/test/base/testing_profile.h"
+#include "components/bookmarks/core/browser/base_bookmark_model_observer.h"
+#include "components/bookmarks/core/browser/bookmark_model.h"
+#include "components/bookmarks/core/test/bookmark_test_helpers.h"
 #include "components/sync_driver/data_type_error_handler.h"
 #include "components/sync_driver/data_type_error_handler_mock.h"
 #include "content/public/test/test_browser_thread.h"
@@ -74,7 +74,7 @@ class FakeServerChange {
   }
 
   // Pretend that the server told the syncer to add a bookmark object.
-  int64 AddWithMetaInfo(const std::wstring& title,
+  int64 AddWithMetaInfo(const std::string& title,
                         const std::string& url,
                         const BookmarkNode::MetaInfoMap* meta_info_map,
                         bool is_folder,
@@ -110,7 +110,7 @@ class FakeServerChange {
     return node.GetId();
   }
 
-  int64 Add(const std::wstring& title,
+  int64 Add(const std::string& title,
             const std::string& url,
             bool is_folder,
             int64 parent_id,
@@ -120,12 +120,12 @@ class FakeServerChange {
   }
 
   // Add a bookmark folder.
-  int64 AddFolder(const std::wstring& title,
+  int64 AddFolder(const std::string& title,
                   int64 parent_id,
                   int64 predecessor_id) {
     return Add(title, std::string(), true, parent_id, predecessor_id);
   }
-  int64 AddFolderWithMetaInfo(const std::wstring& title,
+  int64 AddFolderWithMetaInfo(const std::string& title,
                               const BookmarkNode::MetaInfoMap* meta_info_map,
                               int64 parent_id,
                               int64 predecessor_id) {
@@ -134,13 +134,13 @@ class FakeServerChange {
   }
 
   // Add a bookmark.
-  int64 AddURL(const std::wstring& title,
+  int64 AddURL(const std::string& title,
                const std::string& url,
                int64 parent_id,
                int64 predecessor_id) {
     return Add(title, url, false, parent_id, predecessor_id);
   }
-  int64 AddURLWithMetaInfo(const std::wstring& title,
+  int64 AddURLWithMetaInfo(const std::string& title,
                            const std::string& url,
                            const BookmarkNode::MetaInfoMap* meta_info_map,
                            int64 parent_id,
@@ -178,13 +178,13 @@ class FakeServerChange {
   }
 
   // Set a new title value, and return the old value.
-  std::wstring ModifyTitle(int64 id, const std::wstring& new_title) {
+  std::string ModifyTitle(int64 id, const std::string& new_title) {
     syncer::WriteNode node(trans_);
     EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(id));
     std::string old_title = node.GetTitle();
     node.SetTitle(new_title);
     SetModified(id);
-    return base::UTF8ToWide(old_title);
+    return old_title;
   }
 
   // Set a new parent and predecessor value.  Return the old parent id.
@@ -355,7 +355,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
     syncer::WriteNode node(trans);
     EXPECT_TRUE(node.InitBookmarkByCreation(bookmark_bar, NULL));
     node.SetIsFolder(true);
-    node.SetTitle(base::ASCIIToWide(title));
+    node.SetTitle(title);
 
     return node.GetId();
   }
@@ -383,7 +383,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
     syncer::WriteNode node(trans);
     EXPECT_TRUE(node.InitBookmarkByCreation(parent, NULL));
     node.SetIsFolder(false);
-    node.SetTitle(base::ASCIIToWide(title));
+    node.SetTitle(title);
     node.SetBookmarkSpecifics(specifics);
 
     return node.GetId();
@@ -469,7 +469,7 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
         return false;
       node.SetIsFolder(true);
       node.GetMutableEntryForTest()->PutUniqueServerTag(permanent_tags[i]);
-      node.SetTitle(base::UTF8ToWide(permanent_tags[i]));
+      node.SetTitle(permanent_tags[i]);
       node.SetExternalId(0);
       last_child_id = node.GetId();
     }
@@ -528,9 +528,10 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
 
     // Set up change processor.
     change_processor_.reset(
-        new BookmarkChangeProcessor(model_associator_.get(),
+        new BookmarkChangeProcessor(&profile_,
+                                    model_associator_.get(),
                                     &mock_error_handler_));
-    change_processor_->Start(&profile_, test_user_share_.user_share());
+    change_processor_->Start(test_user_share_.user_share());
   }
 
   void StopSync() {
@@ -656,11 +657,11 @@ class ProfileSyncServiceBookmarkTest : public testing::Test {
     EXPECT_EQ(sync_id, syncer::kInvalidId);
   }
 
-  void ExpectBrowserNodeTitle(int64 sync_id, const std::wstring& title) {
+  void ExpectBrowserNodeTitle(int64 sync_id, const std::string& title) {
     const BookmarkNode* bnode =
         model_associator_->GetChromeNodeFromSyncId(sync_id);
     ASSERT_TRUE(bnode);
-    EXPECT_EQ(bnode->GetTitle(), base::WideToUTF16Hack(title));
+    EXPECT_EQ(bnode->GetTitle(), base::UTF8ToUTF16(title));
   }
 
   void ExpectBrowserNodeURL(int64 sync_id, const std::string& url) {
@@ -855,15 +856,15 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
   syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
 
   FakeServerChange adds(&trans);
-  int64 f1 = adds.AddFolder(L"Server Folder B", bookmark_bar_id(), 0);
-  int64 f2 = adds.AddFolder(L"Server Folder A", bookmark_bar_id(), f1);
-  int64 u1 = adds.AddURL(L"Some old site", "ftp://nifty.andrew.cmu.edu/",
+  int64 f1 = adds.AddFolder("Server Folder B", bookmark_bar_id(), 0);
+  int64 f2 = adds.AddFolder("Server Folder A", bookmark_bar_id(), f1);
+  int64 u1 = adds.AddURL("Some old site", "ftp://nifty.andrew.cmu.edu/",
                          bookmark_bar_id(), f2);
-  int64 u2 = adds.AddURL(L"Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
+  int64 u2 = adds.AddURL("Nifty", "ftp://nifty.andrew.cmu.edu/", f1, 0);
   // u3 is a duplicate URL
-  int64 u3 = adds.AddURL(L"Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
+  int64 u3 = adds.AddURL("Nifty2", "ftp://nifty.andrew.cmu.edu/", f1, u2);
   // u4 is a duplicate title, different URL.
-  adds.AddURL(L"Some old site", "http://slog.thestranger.com/",
+  adds.AddURL("Some old site", "http://slog.thestranger.com/",
               bookmark_bar_id(), u1);
   // u5 tests an empty-string title.
   std::string javascript_url(
@@ -871,9 +872,9 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
       "'about:blank','gnotesWin','location=0,menubar=0," \
       "scrollbars=0,status=0,toolbar=0,width=300," \
       "height=300,resizable');});");
-  adds.AddURL(std::wstring(), javascript_url, other_bookmarks_id(), 0);
+  adds.AddURL(std::string(), javascript_url, other_bookmarks_id(), 0);
   int64 u6 = adds.AddURL(
-      L"Sync1", "http://www.syncable.edu/", mobile_bookmarks_id(), 0);
+      "Sync1", "http://www.syncable.edu/", mobile_bookmarks_id(), 0);
 
   syncer::ChangeRecordList::const_iterator it;
   // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
@@ -891,18 +892,18 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
   FakeServerChange mods(&trans);
   // Mess with u2, and move it into empty folder f2
   // TODO(ncarter): Determine if we allow ModifyURL ops or not.
-  /* std::wstring u2_old_url = mods.ModifyURL(u2, L"http://www.google.com"); */
-  std::wstring u2_old_title = mods.ModifyTitle(u2, L"The Google");
+  /* std::string u2_old_url = mods.ModifyURL(u2, "http://www.google.com"); */
+  std::string u2_old_title = mods.ModifyTitle(u2, "The Google");
   int64 u2_old_parent = mods.ModifyPosition(u2, f2, 0);
 
   // Now move f1 after u2.
-  std::wstring f1_old_title = mods.ModifyTitle(f1, L"Server Folder C");
+  std::string f1_old_title = mods.ModifyTitle(f1, "Server Folder C");
   int64 f1_old_parent = mods.ModifyPosition(f1, f2, u2);
 
   // Then add u3 after f1.
   int64 u3_old_parent = mods.ModifyPosition(u3, f2, f1);
 
-  std::wstring u6_old_title = mods.ModifyTitle(u6, L"Mobile Folder A");
+  std::string u6_old_title = mods.ModifyTitle(u6, "Mobile Folder A");
 
   // Test that the property changes have not yet taken effect.
   ExpectBrowserNodeTitle(u2, u2_old_title);
@@ -956,13 +957,13 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeRequiringFosterParent) {
   std::string url("http://dev.chromium.org/");
   FakeServerChange adds(&trans);
   int64 f0 = other_bookmarks_id();                 // + other_node
-  int64 f1 = adds.AddFolder(L"f1",      f0, 0);    //   + f1
-  int64 f2 = adds.AddFolder(L"f2",      f1, 0);    //     + f2
-  int64 u3 = adds.AddURL(   L"u3", url, f2, 0);    //       + u3    NOLINT
-  int64 u4 = adds.AddURL(   L"u4", url, f2, u3);   //       + u4    NOLINT
-  int64 u5 = adds.AddURL(   L"u5", url, f1, f2);   //     + u5      NOLINT
-  int64 f6 = adds.AddFolder(L"f6",      f1, u5);   //     + f6
-  int64 u7 = adds.AddURL(   L"u7", url, f0, f1);   //   + u7        NOLINT
+  int64 f1 = adds.AddFolder("f1",      f0, 0);    //   + f1
+  int64 f2 = adds.AddFolder("f2",      f1, 0);    //     + f2
+  int64 u3 = adds.AddURL(   "u3", url, f2, 0);    //       + u3    NOLINT
+  int64 u4 = adds.AddURL(   "u4", url, f2, u3);   //       + u4    NOLINT
+  int64 u5 = adds.AddURL(   "u5", url, f1, f2);   //     + u5      NOLINT
+  int64 f6 = adds.AddFolder("f6",      f1, u5);   //     + f6
+  int64 u7 = adds.AddURL(   "u7", url, f0, f1);   //   + u7        NOLINT
 
   syncer::ChangeRecordList::const_iterator it;
   // The bookmark model shouldn't yet have seen any of the nodes of |adds|.
@@ -1003,7 +1004,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeWithNonCanonicalURL) {
     FakeServerChange adds(&trans);
     std::string url("http://dev.chromium.org");
     EXPECT_NE(GURL(url).spec(), url);
-    adds.AddURL(L"u1", url, other_bookmarks_id(), 0);
+    adds.AddURL("u1", url, other_bookmarks_id(), 0);
 
     adds.ApplyPendingChanges(change_processor_.get());
 
@@ -1034,7 +1035,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, DISABLED_ServerChangeWithInvalidURL) {
     FakeServerChange adds(&trans);
     std::string url("x");
     EXPECT_FALSE(GURL(url).is_valid());
-    adds.AddURL(L"u1", url, other_bookmarks_id(), 0);
+    adds.AddURL("u1", url, other_bookmarks_id(), 0);
 
     adds.ApplyPendingChanges(change_processor_.get());
 
@@ -1217,11 +1218,11 @@ TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) {
   {
     syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
     FakeServerChange adds(&trans);
-    u0 = adds.AddURL(L"URL 0", "http://plus.google.com/", bookmark_bar_id(), 0);
-    f1 = adds.AddFolder(L"Folder 1", bookmark_bar_id(), u0);
-    u1 = adds.AddURL(L"URL 1", "http://www.google.com/", f1, 0);
-    f2 = adds.AddFolder(L"Folder 2", f1, u1);
-    u2 = adds.AddURL(L"URL 2", "http://mail.google.com/", f2, 0);
+    u0 = adds.AddURL("URL 0", "http://plus.google.com/", bookmark_bar_id(), 0);
+    f1 = adds.AddFolder("Folder 1", bookmark_bar_id(), u0);
+    u1 = adds.AddURL("URL 1", "http://www.google.com/", f1, 0);
+    f2 = adds.AddFolder("Folder 2", f1, u1);
+    u2 = adds.AddURL("URL 2", "http://mail.google.com/", f2, 0);
     adds.ApplyPendingChanges(change_processor_.get());
   }
   StopSync();
@@ -1281,7 +1282,7 @@ TEST_F(ProfileSyncServiceBookmarkTest, ApplySyncDeletesFromJournal) {
 }
 
 struct TestData {
-  const wchar_t* title;
+  const char* title;
   const char* url;
 };
 
@@ -1371,64 +1372,64 @@ namespace {
 //     +-- u5, http://www.u5.com/
 
 static TestData kBookmarkBarChildren[] = {
-  { L"u2", "http://www.u2.com/" },
-  { L"f1", NULL },
-  { L"u1", "http://www.u1.com/" },
-  { L"f2", NULL },
+  { "u2", "http://www.u2.com/" },
+  { "f1", NULL },
+  { "u1", "http://www.u1.com/" },
+  { "f2", NULL },
 };
 static TestData kF1Children[] = {
-  { L"f1u4", "http://www.f1u4.com/" },
-  { L"f1u2", "http://www.f1u2.com/" },
-  { L"f1u3", "http://www.f1u3.com/" },
-  { L"f1u1", "http://www.f1u1.com/" },
+  { "f1u4", "http://www.f1u4.com/" },
+  { "f1u2", "http://www.f1u2.com/" },
+  { "f1u3", "http://www.f1u3.com/" },
+  { "f1u1", "http://www.f1u1.com/" },
 };
 static TestData kF2Children[] = {
-  { L"f2u2", "http://www.f2u2.com/" },
-  { L"f2u4", "http://www.f2u4.com/" },
-  { L"f2u3", "http://www.f2u3.com/" },
-  { L"f2u1", "http://www.f2u1.com/" },
+  { "f2u2", "http://www.f2u2.com/" },
+  { "f2u4", "http://www.f2u4.com/" },
+  { "f2u3", "http://www.f2u3.com/" },
+  { "f2u1", "http://www.f2u1.com/" },
 };
 
 static TestData kOtherBookmarkChildren[] = {
-  { L"f3", NULL },
-  { L"u4", "http://www.u4.com/" },
-  { L"u3", "http://www.u3.com/" },
-  { L"f4", NULL },
-  { L"dup", NULL },
-  { L"dup", NULL },
-  { L"  ls  ", "http://www.ls.com/" }
+  { "f3", NULL },
+  { "u4", "http://www.u4.com/" },
+  { "u3", "http://www.u3.com/" },
+  { "f4", NULL },
+  { "dup", NULL },
+  { "dup", NULL },
+  { "  ls  ", "http://www.ls.com/" }
 };
 static TestData kF3Children[] = {
-  { L"f3u4", "http://www.f3u4.com/" },
-  { L"f3u2", "http://www.f3u2.com/" },
-  { L"f3u3", "http://www.f3u3.com/" },
-  { L"f3u1", "http://www.f3u1.com/" },
+  { "f3u4", "http://www.f3u4.com/" },
+  { "f3u2", "http://www.f3u2.com/" },
+  { "f3u3", "http://www.f3u3.com/" },
+  { "f3u1", "http://www.f3u1.com/" },
 };
 static TestData kF4Children[] = {
-  { L"f4u1", "http://www.f4u1.com/" },
-  { L"f4u2", "http://www.f4u2.com/" },
-  { L"f4u3", "http://www.f4u3.com/" },
-  { L"f4u4", "http://www.f4u4.com/" },
+  { "f4u1", "http://www.f4u1.com/" },
+  { "f4u2", "http://www.f4u2.com/" },
+  { "f4u3", "http://www.f4u3.com/" },
+  { "f4u4", "http://www.f4u4.com/" },
 };
 static TestData kDup1Children[] = {
-  { L"dupu1", "http://www.dupu1.com/" },
+  { "dupu1", "http://www.dupu1.com/" },
 };
 static TestData kDup2Children[] = {
-  { L"dupu2", "http://www.dupu2.com/" },
+  { "dupu2", "http://www.dupu2.com/" },
 };
 
 static TestData kMobileBookmarkChildren[] = {
-  { L"f5", NULL },
-  { L"f6", NULL },
-  { L"u5", "http://www.u5.com/" },
+  { "f5", NULL },
+  { "f6", NULL },
+  { "u5", "http://www.u5.com/" },
 };
 static TestData kF5Children[] = {
-  { L"f5u1", "http://www.f5u1.com/" },
-  { L"f5u2", "http://www.f5u2.com/" },
+  { "f5u1", "http://www.f5u1.com/" },
+  { "f5u2", "http://www.f5u2.com/" },
 };
 static TestData kF6Children[] = {
-  { L"f6u1", "http://www.f6u1.com/" },
-  { L"f6u2", "http://www.f6u2.com/" },
+  { "f6u1", "http://www.f6u1.com/" },
+  { "f6u2", "http://www.f6u2.com/" },
 };
 
 }  // anonymous namespace.
@@ -1451,10 +1452,14 @@ void ProfileSyncServiceBookmarkTestWithData::PopulateFromTestData(
     if (item.url) {
       const base::Time add_time =
           start_time_ + base::TimeDelta::FromMinutes(*running_count);
-      model_->AddURLWithCreationTime(node, i, base::WideToUTF16Hack(item.title),
-                                     GURL(item.url), add_time);
+      model_->AddURLWithCreationTimeAndMetaInfo(node,
+                                                i,
+                                                base::UTF8ToUTF16(item.title),
+                                                GURL(item.url),
+                                                add_time,
+                                                NULL);
     } else {
-      model_->AddFolder(node, i, base::WideToUTF16Hack(item.title));
+      model_->AddFolder(node, i, base::UTF8ToUTF16(item.title));
     }
     (*running_count)++;
   }
@@ -1474,7 +1479,7 @@ void ProfileSyncServiceBookmarkTestWithData::CompareWithTestData(
     const TestData& item = data[i];
     GURL url = GURL(item.url == NULL ? "" : item.url);
     BookmarkNode test_node(url);
-    test_node.SetTitle(base::WideToUTF16Hack(item.title));
+    test_node.SetTitle(base::UTF8ToUTF16(item.title));
     EXPECT_EQ(child_node->GetTitle(), test_node.GetTitle());
     if (item.url) {
       EXPECT_FALSE(child_node->is_folder());
@@ -1903,7 +1908,7 @@ TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateDateAdded) {
   // updates it's creation time.
   syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
   FakeServerChange adds(&trans);
-  const std::wstring kTitle = L"Some site";
+  const std::string kTitle = "Some site";
   const std::string kUrl = "http://www.whatwhat.yeah/";
   const int kCreationTime = 30;
   int64 id = adds.AddURL(kTitle, kUrl,
@@ -1916,7 +1921,7 @@ TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateDateAdded) {
   const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(0);
   ASSERT_TRUE(node);
   EXPECT_TRUE(node->is_url());
-  EXPECT_EQ(base::WideToUTF16Hack(kTitle), node->GetTitle());
+  EXPECT_EQ(base::UTF8ToUTF16(kTitle), node->GetTitle());
   EXPECT_EQ(kUrl, node->url().possibly_invalid_spec());
   EXPECT_EQ(node->date_added(), base::Time::FromInternalValue(30));
 }
@@ -1934,11 +1939,11 @@ TEST_F(ProfileSyncServiceBookmarkTestWithData, UpdateMetaInfoFromSync) {
   BookmarkNode::MetaInfoMap folder_meta_info;
   folder_meta_info["folder"] = "foldervalue";
   int64 folder_id = adds.AddFolderWithMetaInfo(
-      L"folder title", &folder_meta_info, bookmark_bar_id(), 0);
+      "folder title", &folder_meta_info, bookmark_bar_id(), 0);
   BookmarkNode::MetaInfoMap node_meta_info;
   node_meta_info["node"] = "nodevalue";
   node_meta_info["other"] = "othervalue";
-  int64 id = adds.AddURLWithMetaInfo(L"node title", "http://www.foo.com",
+  int64 id = adds.AddURLWithMetaInfo("node title", "http://www.foo.com",
                                      &node_meta_info, folder_id, 0);
   adds.ApplyPendingChanges(change_processor_.get());