Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / history_unittest.cc
index b5bf888..5ecef4e 100644 (file)
@@ -28,8 +28,8 @@
 #include "base/callback.h"
 #include "base/command_line.h"
 #include "base/compiler_specific.h"
-#include "base/file_util.h"
 #include "base/files/file_path.h"
+#include "base/files/file_util.h"
 #include "base/files/scoped_temp_dir.h"
 #include "base/logging.h"
 #include "base/memory/scoped_ptr.h"
@@ -39,6 +39,7 @@
 #include "base/strings/string_util.h"
 #include "base/strings/stringprintf.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/task/cancelable_task_tracker.h"
 #include "base/threading/platform_thread.h"
 #include "base/time/time.h"
 #include "chrome/browser/history/download_row.h"
 #include "chrome/browser/history/history_notifications.h"
 #include "chrome/browser/history/history_service.h"
 #include "chrome/browser/history/history_unittest_base.h"
-#include "chrome/browser/history/in_memory_database.h"
 #include "chrome/browser/history/in_memory_history_backend.h"
-#include "chrome/browser/history/page_usage_data.h"
 #include "chrome/common/chrome_constants.h"
 #include "chrome/common/chrome_paths.h"
-#include "chrome/common/thumbnail_score.h"
 #include "chrome/tools/profiles/thumbnail-inl.h"
+#include "components/history/core/browser/in_memory_database.h"
+#include "components/history/core/browser/page_usage_data.h"
+#include "components/history/core/common/thumbnail_score.h"
 #include "content/public/browser/download_item.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/notification_source.h"
 #include "sql/connection.h"
 #include "sql/statement.h"
+#include "sync/api/attachments/attachment_id.h"
+#include "sync/api/fake_sync_change_processor.h"
 #include "sync/api/sync_change.h"
 #include "sync/api/sync_change_processor.h"
+#include "sync/api/sync_change_processor_wrapper_for_test.h"
 #include "sync/api/sync_error.h"
 #include "sync/api/sync_error_factory.h"
 #include "sync/api/sync_merge_result.h"
+#include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
 #include "sync/protocol/history_delete_directive_specifics.pb.h"
 #include "sync/protocol/sync.pb.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -88,15 +93,18 @@ class BackendDelegate : public HistoryBackend::Delegate {
       : history_test_(history_test) {
   }
 
-  virtual void NotifyProfileError(int backend_id,
-                                  sql::InitStatus init_status) OVERRIDE {}
-  virtual void SetInMemoryBackend(int backend_id,
-                                  InMemoryHistoryBackend* backend) OVERRIDE;
-  virtual void BroadcastNotifications(int type,
-                                      HistoryDetails* details) OVERRIDE;
-  virtual void DBLoaded(int backend_id) OVERRIDE {}
-  virtual void NotifyVisitDBObserversOnAddVisit(
-      const BriefVisitInfo& info) OVERRIDE {}
+  void NotifyProfileError(sql::InitStatus init_status) override {}
+  void SetInMemoryBackend(scoped_ptr<InMemoryHistoryBackend> backend) override;
+  void NotifyAddVisit(const BriefVisitInfo& info) override {}
+  void NotifyFaviconChanged(const std::set<GURL>& url) override {}
+  void NotifyURLVisited(ui::PageTransition transition,
+                        const URLRow& row,
+                        const RedirectList& redirects,
+                        base::Time visit_time) override {}
+  void BroadcastNotifications(int type,
+                              scoped_ptr<HistoryDetails> details) override;
+  void DBLoaded() override {}
+
  private:
   HistoryBackendDBTest* history_test_;
 };
@@ -108,8 +116,7 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
   HistoryBackendDBTest() : db_(NULL) {
   }
 
-  virtual ~HistoryBackendDBTest() {
-  }
+  ~HistoryBackendDBTest() override {}
 
  protected:
   friend class BackendDelegate;
@@ -117,8 +124,8 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
   // Creates the HistoryBackend and HistoryDatabase on the current thread,
   // assigning the values to backend_ and db_.
   void CreateBackendAndDatabase() {
-    backend_ = new HistoryBackend(history_dir_, 0, new BackendDelegate(this),
-                                  NULL);
+    backend_ =
+        new HistoryBackend(history_dir_, new BackendDelegate(this), NULL);
     backend_->Init(std::string(), false);
     db_ = backend_->db_.get();
     DCHECK(in_mem_backend_) << "Mem backend should have been set by "
@@ -136,8 +143,18 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
             chrome::kHistoryFilename)));
   }
 
+  void CreateArchivedDB() {
+    base::FilePath data_path;
+    ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
+    data_path = data_path.AppendASCII("History");
+    data_path = data_path.AppendASCII("archived_history.4.sql");
+    ASSERT_NO_FATAL_FAILURE(
+        ExecuteSQLScript(data_path, history_dir_.Append(
+            chrome::kArchivedHistoryFilename)));
+  }
+
   // testing::Test
-  virtual void SetUp() {
+  void SetUp() override {
     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
     history_dir_ = temp_dir_.path().AppendASCII("HistoryBackendDBTest");
     ASSERT_TRUE(base::CreateDirectory(history_dir_));
@@ -150,7 +167,7 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
     }
   }
 
-  virtual void TearDown() {
+  void TearDown() override {
     DeleteBackend();
 
     // Make sure we don't have any event pending that could disrupt the next
@@ -170,6 +187,8 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
                          base::FilePath(FILE_PATH_LITERAL("target-path")),
                          url_chain,
                          GURL("http://referrer.com/"),
+                         "application/vnd.oasis.opendocument.text",
+                         "application/octet-stream",
                          time,
                          time,
                          std::string(),
@@ -199,23 +218,21 @@ class HistoryBackendDBTest : public HistoryUnitTestBase {
   HistoryDatabase* db_;  // Cached reference to the backend's database.
 };
 
-void BackendDelegate::SetInMemoryBackend(int backend_id,
-                                         InMemoryHistoryBackend* backend) {
+void BackendDelegate::SetInMemoryBackend(
+    scoped_ptr<InMemoryHistoryBackend> backend) {
   // Save the in-memory backend to the history test object, this happens
   // synchronously, so we don't have to do anything fancy.
-  history_test_->in_mem_backend_.reset(backend);
+  history_test_->in_mem_backend_.swap(backend);
 }
 
-void BackendDelegate::BroadcastNotifications(int type,
-                                             HistoryDetails* details) {
+void BackendDelegate::BroadcastNotifications(
+    int type,
+    scoped_ptr<HistoryDetails> details) {
   // Currently, just send the notifications directly to the in-memory database.
   // We may want do do something more fancy in the future.
-  content::Details<HistoryDetails> det(details);
+  content::Details<HistoryDetails> det(details.get());
   history_test_->in_mem_backend_->Observe(type,
       content::Source<HistoryBackendDBTest>(NULL), det);
-
-  // The backend passes ownership of the details pointer to us.
-  delete details;
 }
 
 TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
@@ -254,6 +271,8 @@ TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {
   EXPECT_FALSE(downloads[0].opened);
   EXPECT_EQ("by_ext_id", downloads[0].by_ext_id);
   EXPECT_EQ("by_ext_name", downloads[0].by_ext_name);
+  EXPECT_EQ("application/vnd.oasis.opendocument.text", downloads[0].mime_type);
+  EXPECT_EQ("application/octet-stream", downloads[0].original_mime_type);
 
   db_->QueryDownloads(&downloads);
   EXPECT_EQ(1U, downloads.size());
@@ -617,6 +636,90 @@ TEST_F(HistoryBackendDBTest, MigrateDownloadValidators) {
   }
 }
 
+TEST_F(HistoryBackendDBTest, PurgeArchivedDatabase) {
+  ASSERT_NO_FATAL_FAILURE(CreateDBVersion(27));
+  ASSERT_NO_FATAL_FAILURE(CreateArchivedDB());
+
+  ASSERT_TRUE(base::PathExists(
+      history_dir_.Append(chrome::kArchivedHistoryFilename)));
+
+  CreateBackendAndDatabase();
+  DeleteBackend();
+
+  // We do not retain expired history entries in an archived database as of M37.
+  // Verify that any legacy archived database is deleted on start-up.
+  ASSERT_FALSE(base::PathExists(
+      history_dir_.Append(chrome::kArchivedHistoryFilename)));
+}
+
+TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {
+  Time now(base::Time::Now());
+  ASSERT_NO_FATAL_FAILURE(CreateDBVersion(28));
+  {
+    sql::Connection db;
+    ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+    {
+      sql::Statement s(db.GetUniqueStatement(
+          "INSERT INTO downloads (id, current_path, target_path, start_time, "
+          "received_bytes, total_bytes, state, danger_type, interrupt_reason, "
+          "end_time, opened, referrer, by_ext_id, by_ext_name, etag, "
+          "last_modified) VALUES "
+          "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"));
+      s.BindInt64(0, 1);
+      s.BindString(1, "current_path");
+      s.BindString(2, "target_path");
+      s.BindInt64(3, now.ToTimeT());
+      s.BindInt64(4, 100);
+      s.BindInt64(5, 100);
+      s.BindInt(6, 1);
+      s.BindInt(7, 0);
+      s.BindInt(8, 0);
+      s.BindInt64(9, now.ToTimeT());
+      s.BindInt(10, 1);
+      s.BindString(11, "referrer");
+      s.BindString(12, "by extension ID");
+      s.BindString(13, "by extension name");
+      s.BindString(14, "etag");
+      s.BindInt64(15, now.ToTimeT());
+      ASSERT_TRUE(s.Run());
+    }
+    {
+      sql::Statement s(db.GetUniqueStatement(
+          "INSERT INTO downloads_url_chains (id, chain_index, url) VALUES "
+          "(?, ?, ?)"));
+      s.BindInt64(0, 4);
+      s.BindInt64(1, 0);
+      s.BindString(2, "url");
+      ASSERT_TRUE(s.Run());
+    }
+  }
+  // Re-open the db using the HistoryDatabase, which should migrate to the
+  // current version, creating themime_type abd original_mime_type columns.
+  CreateBackendAndDatabase();
+  DeleteBackend();
+  {
+    // Re-open the db for manual manipulation.
+    sql::Connection db;
+    ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
+    // The version should have been updated.
+    int cur_version = HistoryDatabase::GetCurrentVersion();
+    ASSERT_LE(29, cur_version);
+    {
+      sql::Statement s(db.GetUniqueStatement(
+          "SELECT value FROM meta WHERE key = 'version'"));
+      EXPECT_TRUE(s.Step());
+      EXPECT_EQ(cur_version, s.ColumnInt(0));
+    }
+    {
+      sql::Statement s(db.GetUniqueStatement(
+          "SELECT mime_type, original_mime_type from downloads"));
+      EXPECT_TRUE(s.Step());
+      EXPECT_EQ(std::string(), s.ColumnString(0));
+      EXPECT_EQ(std::string(), s.ColumnString(1));
+    }
+  }
+}
+
 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
   // Create the DB.
   CreateBackendAndDatabase();
@@ -673,6 +776,8 @@ TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {
                        base::FilePath(FILE_PATH_LITERAL("foo-path")),
                        url_chain,
                        GURL(std::string()),
+                       "application/octet-stream",
+                       "application/octet-stream",
                        now,
                        now,
                        std::string(),
@@ -815,6 +920,8 @@ const InterruptReasonAssociation historical_reasons[] = {
   {"SERVER_NO_RANGE",  31},
   {"SERVER_PRECONDITION",  32},
   {"SERVER_BAD_CONTENT",  33},
+  {"SERVER_UNAUTHORIZED", 34},
+  {"SERVER_CERT_PROBLEM", 35},
   {"USER_CANCELED",  40},
   {"USER_SHUTDOWN",  41},
   {"CRASH",  50},
@@ -870,39 +977,17 @@ TEST_F(HistoryBackendDBTest,
   }
 }
 
-// The tracker uses RenderProcessHost pointers for scoping but never
-// dereferences them. We use ints because it's easier. This function converts
-// between the two.
-static void* MakeFakeHost(int id) {
-  void* host = 0;
-  memcpy(&host, &id, sizeof(id));
-  return host;
-}
-
 class HistoryTest : public testing::Test {
  public:
   HistoryTest()
       : got_thumbnail_callback_(false),
-        redirect_query_success_(false),
         query_url_success_(false) {
   }
 
-  virtual ~HistoryTest() {
-  }
-
-  void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
-                               std::vector<PageUsageData*>* data) {
-    page_usage_data_.swap(*data);
-    base::MessageLoop::current()->Quit();
-  }
-
-  void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) {
-    base::MessageLoop::current()->Quit();
-  }
+  ~HistoryTest() override {}
 
-  void OnMostVisitedURLsAvailable(CancelableRequestProvider::Handle handle,
-                                  MostVisitedURLList url_list) {
-    most_visited_urls_.swap(url_list);
+  void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) {
+    most_visited_urls_ = *url_list;
     base::MessageLoop::current()->Quit();
   }
 
@@ -910,18 +995,18 @@ class HistoryTest : public testing::Test {
   friend class BackendDelegate;
 
   // testing::Test
-  virtual void SetUp() {
+  void SetUp() override {
     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
     history_dir_ = temp_dir_.path().AppendASCII("HistoryTest");
     ASSERT_TRUE(base::CreateDirectory(history_dir_));
     history_service_.reset(new HistoryService);
-    if (!history_service_->Init(history_dir_, NULL)) {
+    if (!history_service_->Init(history_dir_)) {
       history_service_.reset();
       ADD_FAILURE();
     }
   }
 
-  virtual void TearDown() {
+  void TearDown() override {
     if (history_service_)
       CleanupHistoryService();
 
@@ -935,7 +1020,7 @@ class HistoryTest : public testing::Test {
   void CleanupHistoryService() {
     DCHECK(history_service_);
 
-    history_service_->NotifyRenderProcessHostDestruction(0);
+    history_service_->ClearCachedDataForContextID(0);
     history_service_->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
     history_service_->Cleanup();
     history_service_.reset();
@@ -951,22 +1036,23 @@ class HistoryTest : public testing::Test {
   // information about the given URL and returns true. If the URL was not
   // found, this will return false and those structures will not be changed.
   bool QueryURL(HistoryService* history, const GURL& url) {
-    history_service_->QueryURL(url, true, &consumer_,
-                               base::Bind(&HistoryTest::SaveURLAndQuit,
-                                          base::Unretained(this)));
+    history_service_->QueryURL(
+        url,
+        true,
+        base::Bind(&HistoryTest::SaveURLAndQuit, base::Unretained(this)),
+        &tracker_);
     base::MessageLoop::current()->Run();  // Will be exited in SaveURLAndQuit.
     return query_url_success_;
   }
 
   // Callback for HistoryService::QueryURL.
-  void SaveURLAndQuit(HistoryService::Handle handle,
-                      bool success,
-                      const URLRow* url_row,
-                      VisitVector* visit_vector) {
+  void SaveURLAndQuit(bool success,
+                      const URLRow& url_row,
+                      const VisitVector& visits) {
     query_url_success_ = success;
     if (query_url_success_) {
-      query_url_row_ = *url_row;
-      query_url_visits_.swap(*visit_vector);
+      query_url_row_ = url_row;
+      query_url_visits_ = visits;
     } else {
       query_url_row_ = URLRow();
       query_url_visits_.clear();
@@ -976,25 +1062,22 @@ class HistoryTest : public testing::Test {
 
   // Fills in saved_redirects_ with the redirect information for the given URL,
   // returning true on success. False means the URL was not found.
-  bool QueryRedirectsFrom(HistoryService* history, const GURL& url) {
+  void QueryRedirectsFrom(HistoryService* history, const GURL& url) {
     history_service_->QueryRedirectsFrom(
-        url, &consumer_,
+        url,
         base::Bind(&HistoryTest::OnRedirectQueryComplete,
-                   base::Unretained(this)));
+                   base::Unretained(this)),
+        &tracker_);
     base::MessageLoop::current()->Run();  // Will be exited in *QueryComplete.
-    return redirect_query_success_;
   }
 
   // Callback for QueryRedirects.
-  void OnRedirectQueryComplete(HistoryService::Handle handle,
-                               GURL url,
-                               bool success,
-                               history::RedirectList* redirects) {
-    redirect_query_success_ = success;
-    if (redirect_query_success_)
-      saved_redirects_.swap(*redirects);
-    else
-      saved_redirects_.clear();
+  void OnRedirectQueryComplete(const history::RedirectList* redirects) {
+    saved_redirects_.clear();
+    if (!redirects->empty()) {
+      saved_redirects_.insert(
+          saved_redirects_.end(), redirects->begin(), redirects->end());
+    }
     base::MessageLoop::current()->Quit();
   }
 
@@ -1002,9 +1085,6 @@ class HistoryTest : public testing::Test {
 
   base::MessageLoopForUI message_loop_;
 
-  // PageUsageData vector to test segments.
-  ScopedVector<PageUsageData> page_usage_data_;
-
   MostVisitedURLList most_visited_urls_;
 
   // When non-NULL, this will be deleted on tear down and we will block until
@@ -1023,10 +1103,9 @@ class HistoryTest : public testing::Test {
   // Set by the redirect callback when we get data. You should be sure to
   // clear this before issuing a redirect request.
   history::RedirectList saved_redirects_;
-  bool redirect_query_success_;
 
   // For history requests.
-  CancelableRequestConsumer consumer_;
+  base::CancelableTaskTracker tracker_;
 
   // For saving URL info after a call to QueryURL
   bool query_url_success_;
@@ -1040,7 +1119,7 @@ TEST_F(HistoryTest, AddPage) {
   const GURL test_url("http://www.google.com/");
   history_service_->AddPage(test_url, base::Time::Now(), NULL, 0, GURL(),
                             history::RedirectList(),
-                            content::PAGE_TRANSITION_MANUAL_SUBFRAME,
+                            ui::PAGE_TRANSITION_MANUAL_SUBFRAME,
                             history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
   EXPECT_EQ(1, query_url_row_.visit_count());
@@ -1049,7 +1128,7 @@ TEST_F(HistoryTest, AddPage) {
 
   // Add the page once from the main frame (should unhide it).
   history_service_->AddPage(test_url, base::Time::Now(), NULL, 0, GURL(),
-                   history::RedirectList(), content::PAGE_TRANSITION_LINK,
+                   history::RedirectList(), ui::PAGE_TRANSITION_LINK,
                    history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
   EXPECT_EQ(2, query_url_row_.visit_count());  // Added twice.
@@ -1070,9 +1149,9 @@ TEST_F(HistoryTest, AddRedirect) {
   // Add the sequence of pages as a server with no referrer. Note that we need
   // to have a non-NULL page ID scope.
   history_service_->AddPage(
-      first_redirects.back(), base::Time::Now(), MakeFakeHost(1),
-      0, GURL(), first_redirects, content::PAGE_TRANSITION_LINK,
-      history::SOURCE_BROWSED, true);
+      first_redirects.back(), base::Time::Now(),
+      reinterpret_cast<ContextID>(1), 0, GURL(), first_redirects,
+      ui::PAGE_TRANSITION_LINK, history::SOURCE_BROWSED, true);
 
   // The first page should be added once with a link visit type (because we set
   // LINK when we added the original URL, and a referrer of nowhere (0).
@@ -1080,8 +1159,8 @@ TEST_F(HistoryTest, AddRedirect) {
   EXPECT_EQ(1, query_url_row_.visit_count());
   ASSERT_EQ(1U, query_url_visits_.size());
   int64 first_visit = query_url_visits_[0].visit_id;
-  EXPECT_EQ(content::PAGE_TRANSITION_LINK |
-            content::PAGE_TRANSITION_CHAIN_START,
+  EXPECT_EQ(ui::PAGE_TRANSITION_LINK |
+            ui::PAGE_TRANSITION_CHAIN_START,
             query_url_visits_[0].transition);
   EXPECT_EQ(0, query_url_visits_[0].referring_visit);  // No referrer.
 
@@ -1091,8 +1170,8 @@ TEST_F(HistoryTest, AddRedirect) {
   EXPECT_EQ(1, query_url_row_.visit_count());
   ASSERT_EQ(1U, query_url_visits_.size());
   int64 second_visit = query_url_visits_[0].visit_id;
-  EXPECT_EQ(content::PAGE_TRANSITION_SERVER_REDIRECT |
-            content::PAGE_TRANSITION_CHAIN_END,
+  EXPECT_EQ(ui::PAGE_TRANSITION_SERVER_REDIRECT |
+            ui::PAGE_TRANSITION_CHAIN_END,
             query_url_visits_[0].transition);
   EXPECT_EQ(first_visit, query_url_visits_[0].referring_visit);
 
@@ -1109,10 +1188,11 @@ TEST_F(HistoryTest, AddRedirect) {
   second_redirects.push_back(first_redirects[1]);
   second_redirects.push_back(GURL("http://last.page.com/"));
   history_service_->AddPage(second_redirects[1], base::Time::Now(),
-                   MakeFakeHost(1), 1, second_redirects[0], second_redirects,
-                   static_cast<content::PageTransition>(
-                       content::PAGE_TRANSITION_LINK |
-                       content::PAGE_TRANSITION_CLIENT_REDIRECT),
+                   reinterpret_cast<ContextID>(1), 1,
+                   second_redirects[0], second_redirects,
+                   ui::PageTransitionFromInt(
+                       ui::PAGE_TRANSITION_LINK |
+                       ui::PAGE_TRANSITION_CLIENT_REDIRECT),
                    history::SOURCE_BROWSED, true);
 
   // The last page (source of the client redirect) should NOT have an
@@ -1125,8 +1205,8 @@ TEST_F(HistoryTest, AddRedirect) {
   EXPECT_TRUE(QueryURL(history_service_.get(), second_redirects[1]));
   EXPECT_EQ(1, query_url_row_.visit_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_CLIENT_REDIRECT |
-            content::PAGE_TRANSITION_CHAIN_END,
+  EXPECT_EQ(ui::PAGE_TRANSITION_CLIENT_REDIRECT |
+            ui::PAGE_TRANSITION_CHAIN_END,
             query_url_visits_[0].transition);
   EXPECT_EQ(second_visit, query_url_visits_[0].referring_visit);
 }
@@ -1139,14 +1219,14 @@ TEST_F(HistoryTest, MakeIntranetURLsTyped) {
   const GURL test_url("http://intranet_host/path");
   history_service_->AddPage(
       test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
   EXPECT_EQ(1, query_url_row_.visit_count());
   EXPECT_EQ(1, query_url_row_.typed_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_TYPED,
-      content::PageTransitionStripQualifier(query_url_visits_[0].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_TYPED,
+      ui::PageTransitionStripQualifier(query_url_visits_[0].transition));
 
   // Add more visits on the same host.  None of these should be promoted since
   // there is already a typed visit.
@@ -1155,76 +1235,78 @@ TEST_F(HistoryTest, MakeIntranetURLsTyped) {
   const GURL test_url2("http://intranet_host/different_path");
   history_service_->AddPage(
       test_url2, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url2));
   EXPECT_EQ(1, query_url_row_.visit_count());
   EXPECT_EQ(0, query_url_row_.typed_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_LINK,
-      content::PageTransitionStripQualifier(query_url_visits_[0].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
+      ui::PageTransitionStripQualifier(query_url_visits_[0].transition));
 
   // No path.
   const GURL test_url3("http://intranet_host/");
   history_service_->AddPage(
       test_url3, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url3));
   EXPECT_EQ(1, query_url_row_.visit_count());
   EXPECT_EQ(0, query_url_row_.typed_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_LINK,
-      content::PageTransitionStripQualifier(query_url_visits_[0].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
+      ui::PageTransitionStripQualifier(query_url_visits_[0].transition));
 
   // Different scheme.
   const GURL test_url4("https://intranet_host/");
   history_service_->AddPage(
       test_url4, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url4));
   EXPECT_EQ(1, query_url_row_.visit_count());
   EXPECT_EQ(0, query_url_row_.typed_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_LINK,
-      content::PageTransitionStripQualifier(query_url_visits_[0].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
+      ui::PageTransitionStripQualifier(query_url_visits_[0].transition));
 
   // Different transition.
   const GURL test_url5("http://intranet_host/another_path");
   history_service_->AddPage(
       test_url5, base::Time::Now(), NULL, 0, GURL(),
       history::RedirectList(),
-      content::PAGE_TRANSITION_AUTO_BOOKMARK,
+      ui::PAGE_TRANSITION_AUTO_BOOKMARK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url5));
   EXPECT_EQ(1, query_url_row_.visit_count());
   EXPECT_EQ(0, query_url_row_.typed_count());
   ASSERT_EQ(1U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_AUTO_BOOKMARK,
-      content::PageTransitionStripQualifier(query_url_visits_[0].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_BOOKMARK,
+      ui::PageTransitionStripQualifier(query_url_visits_[0].transition));
 
   // Original URL.
   history_service_->AddPage(
       test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
   EXPECT_EQ(2, query_url_row_.visit_count());
   EXPECT_EQ(1, query_url_row_.typed_count());
   ASSERT_EQ(2U, query_url_visits_.size());
-  EXPECT_EQ(content::PAGE_TRANSITION_LINK,
-      content::PageTransitionStripQualifier(query_url_visits_[1].transition));
+  EXPECT_EQ(ui::PAGE_TRANSITION_LINK,
+      ui::PageTransitionStripQualifier(query_url_visits_[1].transition));
 }
 
 TEST_F(HistoryTest, Typed) {
+  const ContextID context_id = reinterpret_cast<ContextID>(1);
+
   ASSERT_TRUE(history_service_.get());
 
   // Add the page once as typed.
   const GURL test_url("http://www.google.com/");
   history_service_->AddPage(
-      test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      test_url, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
 
@@ -1234,8 +1316,8 @@ TEST_F(HistoryTest, Typed) {
 
   // Add the page again not typed.
   history_service_->AddPage(
-      test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
+      test_url, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_LINK,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
 
@@ -1245,8 +1327,8 @@ TEST_F(HistoryTest, Typed) {
 
   // Add the page again as a generated URL.
   history_service_->AddPage(
-      test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_GENERATED,
+      test_url, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_GENERATED,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
 
@@ -1256,8 +1338,8 @@ TEST_F(HistoryTest, Typed) {
 
   // Add the page again as a reload.
   history_service_->AddPage(
-      test_url, base::Time::Now(), NULL, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_RELOAD,
+      test_url, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_RELOAD,
       history::SOURCE_BROWSED, false);
   EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
 
@@ -1295,76 +1377,6 @@ TEST_F(HistoryTest, SetTitle) {
   // destination page.
 }
 
-// crbug.com/159387: This test fails when daylight savings time ends.
-TEST_F(HistoryTest, DISABLED_Segments) {
-  ASSERT_TRUE(history_service_.get());
-
-  static const void* scope = static_cast<void*>(this);
-
-  // Add a URL.
-  const GURL existing_url("http://www.google.com/");
-  history_service_->AddPage(
-      existing_url, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
-      history::SOURCE_BROWSED, false);
-
-  // Make sure a segment was created.
-  history_service_->QuerySegmentUsageSince(
-      &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
-      base::Bind(&HistoryTest::OnSegmentUsageAvailable,
-                 base::Unretained(this)));
-
-  // Wait for processing.
-  base::MessageLoop::current()->Run();
-
-  ASSERT_EQ(1U, page_usage_data_.size());
-  EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
-  EXPECT_DOUBLE_EQ(3.0, page_usage_data_[0]->GetScore());
-
-  // Add a URL which doesn't create a segment.
-  const GURL link_url("http://yahoo.com/");
-  history_service_->AddPage(
-      link_url, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_LINK,
-      history::SOURCE_BROWSED, false);
-
-  // Query again
-  history_service_->QuerySegmentUsageSince(
-      &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
-      base::Bind(&HistoryTest::OnSegmentUsageAvailable,
-                 base::Unretained(this)));
-
-  // Wait for processing.
-  base::MessageLoop::current()->Run();
-
-  // Make sure we still have one segment.
-  ASSERT_EQ(1U, page_usage_data_.size());
-  EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
-
-  // Add a page linked from existing_url.
-  history_service_->AddPage(
-      GURL("http://www.google.com/foo"), base::Time::Now(),
-      scope, 3, existing_url, history::RedirectList(),
-      content::PAGE_TRANSITION_LINK, history::SOURCE_BROWSED,
-      false);
-
-  // Query again
-  history_service_->QuerySegmentUsageSince(
-      &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
-      base::Bind(&HistoryTest::OnSegmentUsageAvailable,
-                 base::Unretained(this)));
-
-  // Wait for processing.
-  base::MessageLoop::current()->Run();
-
-  // Make sure we still have one segment.
-  ASSERT_EQ(1U, page_usage_data_.size());
-  EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
-
-  // However, the score should have increased.
-  EXPECT_GT(page_usage_data_[0]->GetScore(), 5.0);
-}
-
 TEST_F(HistoryTest, MostVisitedURLs) {
   ASSERT_TRUE(history_service_.get());
 
@@ -1374,22 +1386,23 @@ TEST_F(HistoryTest, MostVisitedURLs) {
   const GURL url3("http://www.google.com/url3/");
   const GURL url4("http://www.google.com/url4/");
 
-  static const void* scope = static_cast<void*>(this);
+  const ContextID context_id = reinterpret_cast<ContextID>(1);
 
   // Add two pages.
   history_service_->AddPage(
-      url0, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      url0, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->AddPage(
-      url1, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      url1, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->QueryMostVisitedURLs(
-      20, 90, &consumer_,
-      base::Bind(
-          &HistoryTest::OnMostVisitedURLsAvailable,
-          base::Unretained(this)));
+      20,
+      90,
+      base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+                 base::Unretained(this)),
+      &tracker_);
   base::MessageLoop::current()->Run();
 
   EXPECT_EQ(2U, most_visited_urls_.size());
@@ -1398,14 +1411,15 @@ TEST_F(HistoryTest, MostVisitedURLs) {
 
   // Add another page.
   history_service_->AddPage(
-      url2, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      url2, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->QueryMostVisitedURLs(
-      20, 90, &consumer_,
-      base::Bind(
-          &HistoryTest::OnMostVisitedURLsAvailable,
-          base::Unretained(this)));
+      20,
+      90,
+      base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+                 base::Unretained(this)),
+      &tracker_);
   base::MessageLoop::current()->Run();
 
   EXPECT_EQ(3U, most_visited_urls_.size());
@@ -1415,14 +1429,15 @@ TEST_F(HistoryTest, MostVisitedURLs) {
 
   // Revisit url2, making it the top URL.
   history_service_->AddPage(
-      url2, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      url2, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->QueryMostVisitedURLs(
-      20, 90, &consumer_,
-      base::Bind(
-          &HistoryTest::OnMostVisitedURLsAvailable,
-          base::Unretained(this)));
+      20,
+      90,
+      base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+                 base::Unretained(this)),
+      &tracker_);
   base::MessageLoop::current()->Run();
 
   EXPECT_EQ(3U, most_visited_urls_.size());
@@ -1432,14 +1447,15 @@ TEST_F(HistoryTest, MostVisitedURLs) {
 
   // Revisit url1, making it the top URL.
   history_service_->AddPage(
-      url1, base::Time::Now(), scope, 0, GURL(),
-      history::RedirectList(), content::PAGE_TRANSITION_TYPED,
+      url1, base::Time::Now(), context_id, 0, GURL(),
+      history::RedirectList(), ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->QueryMostVisitedURLs(
-      20, 90, &consumer_,
-      base::Bind(
-          &HistoryTest::OnMostVisitedURLsAvailable,
-          base::Unretained(this)));
+      20,
+      90,
+      base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+                 base::Unretained(this)),
+      &tracker_);
   base::MessageLoop::current()->Run();
 
   EXPECT_EQ(3U, most_visited_urls_.size());
@@ -1454,14 +1470,15 @@ TEST_F(HistoryTest, MostVisitedURLs) {
 
   // Visit url4 using redirects.
   history_service_->AddPage(
-      url4, base::Time::Now(), scope, 0, GURL(),
-      redirects, content::PAGE_TRANSITION_TYPED,
+      url4, base::Time::Now(), context_id, 0, GURL(),
+      redirects, ui::PAGE_TRANSITION_TYPED,
       history::SOURCE_BROWSED, false);
   history_service_->QueryMostVisitedURLs(
-      20, 90, &consumer_,
-      base::Bind(
-          &HistoryTest::OnMostVisitedURLsAvailable,
-          base::Unretained(this)));
+      20,
+      90,
+      base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+                 base::Unretained(this)),
+      &tracker_);
   base::MessageLoop::current()->Run();
 
   EXPECT_EQ(4U, most_visited_urls_.size());
@@ -1483,23 +1500,23 @@ class HistoryDBTaskImpl : public HistoryDBTask {
  public:
   static const int kWantInvokeCount;
 
-  HistoryDBTaskImpl() : invoke_count(0), done_invoked(false) {}
+  HistoryDBTaskImpl(int* invoke_count, bool* done_invoked)
+      : invoke_count_(invoke_count), done_invoked_(done_invoked) {}
 
-  virtual bool RunOnDBThread(HistoryBackend* backend,
-                             HistoryDatabase* db) OVERRIDE {
-    return (++invoke_count == kWantInvokeCount);
+  bool RunOnDBThread(HistoryBackend* backend, HistoryDatabase* db) override {
+    return (++*invoke_count_ == kWantInvokeCount);
   }
 
-  virtual void DoneRunOnMainThread() OVERRIDE {
-    done_invoked = true;
+  void DoneRunOnMainThread() override {
+    *done_invoked_ = true;
     base::MessageLoop::current()->Quit();
   }
 
-  int invoke_count;
-  bool done_invoked;
+  int* invoke_count_;
+  bool* done_invoked_;
 
  private:
-  virtual ~HistoryDBTaskImpl() {}
+  ~HistoryDBTaskImpl() override {}
 
   DISALLOW_COPY_AND_ASSIGN(HistoryDBTaskImpl);
 };
@@ -1511,9 +1528,13 @@ const int HistoryDBTaskImpl::kWantInvokeCount = 2;
 
 TEST_F(HistoryTest, HistoryDBTask) {
   ASSERT_TRUE(history_service_.get());
-  CancelableRequestConsumerT<int, 0> request_consumer;
-  scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
-  history_service_->ScheduleDBTask(task.get(), &request_consumer);
+  base::CancelableTaskTracker task_tracker;
+  int invoke_count = 0;
+  bool done_invoked = false;
+  history_service_->ScheduleDBTask(
+      scoped_ptr<history::HistoryDBTask>(
+          new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+      &task_tracker);
   // Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs,
   // it will stop the message loop. If the test hangs here, it means
   // DoneRunOnMainThread isn't being invoked correctly.
@@ -1521,87 +1542,26 @@ TEST_F(HistoryTest, HistoryDBTask) {
   CleanupHistoryService();
   // WARNING: history has now been deleted.
   history_service_.reset();
-  ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count);
-  ASSERT_TRUE(task->done_invoked);
+  ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, invoke_count);
+  ASSERT_TRUE(done_invoked);
 }
 
 TEST_F(HistoryTest, HistoryDBTaskCanceled) {
   ASSERT_TRUE(history_service_.get());
-  CancelableRequestConsumerT<int, 0> request_consumer;
-  scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
-  history_service_->ScheduleDBTask(task.get(), &request_consumer);
-  request_consumer.CancelAllRequests();
+  base::CancelableTaskTracker task_tracker;
+  int invoke_count = 0;
+  bool done_invoked = false;
+  history_service_->ScheduleDBTask(
+      scoped_ptr<history::HistoryDBTask>(
+          new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+      &task_tracker);
+  task_tracker.TryCancelAll();
   CleanupHistoryService();
   // WARNING: history has now been deleted.
   history_service_.reset();
-  ASSERT_FALSE(task->done_invoked);
+  ASSERT_FALSE(done_invoked);
 }
 
-// Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
-// back up to Sync.
-//
-// TODO(akalin): Unify all the various test implementations of
-// syncer::SyncChangeProcessor.
-class TestChangeProcessor : public syncer::SyncChangeProcessor {
- public:
-  TestChangeProcessor() {}
-  virtual ~TestChangeProcessor() {}
-
-  virtual syncer::SyncError ProcessSyncChanges(
-      const tracked_objects::Location& from_here,
-      const syncer::SyncChangeList& change_list) OVERRIDE {
-    changes_.insert(changes_.end(), change_list.begin(), change_list.end());
-    return syncer::SyncError();
-  }
-
-  virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
-      OVERRIDE {
-    return syncer::SyncDataList();
-  }
-
-  const syncer::SyncChangeList& GetChanges() const {
-    return changes_;
-  }
-
- private:
-  syncer::SyncChangeList changes_;
-
-  DISALLOW_COPY_AND_ASSIGN(TestChangeProcessor);
-};
-
-// SyncChangeProcessor implementation that delegates to another one.
-// This is necessary since most things expect a
-// scoped_ptr<SyncChangeProcessor>.
-//
-// TODO(akalin): Unify this too.
-class SyncChangeProcessorDelegate : public syncer::SyncChangeProcessor {
- public:
-  explicit SyncChangeProcessorDelegate(syncer::SyncChangeProcessor* recipient)
-      : recipient_(recipient) {
-    DCHECK(recipient_);
-  }
-
-  virtual ~SyncChangeProcessorDelegate() {}
-
-  // syncer::SyncChangeProcessor implementation.
-  virtual syncer::SyncError ProcessSyncChanges(
-      const tracked_objects::Location& from_here,
-      const syncer::SyncChangeList& change_list) OVERRIDE {
-    return recipient_->ProcessSyncChanges(from_here, change_list);
-  }
-
-  virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const
-      OVERRIDE {
-    return recipient_->GetAllSyncData(type);
-  }
-
- private:
-  // The recipient of all sync changes.
-  syncer::SyncChangeProcessor* const recipient_;
-
-  DISALLOW_COPY_AND_ASSIGN(SyncChangeProcessorDelegate);
-};
-
 // Create a local delete directive and process it while sync is
 // online, and then when offline. The delete directive should be sent to sync,
 // no error should be returned for the first time, and an error should be
@@ -1615,7 +1575,7 @@ TEST_F(HistoryTest, ProcessLocalDeleteDirectiveSyncOnline) {
         base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i);
     history_service_->AddPage(test_url, t, NULL, 0, GURL(),
                               history::RedirectList(),
-                              content::PAGE_TRANSITION_LINK,
+                              ui::PAGE_TRANSITION_LINK,
                               history::SOURCE_BROWSED, false);
   }
 
@@ -1626,35 +1586,39 @@ TEST_F(HistoryTest, ProcessLocalDeleteDirectiveSyncOnline) {
       (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(1))
       .ToInternalValue());
 
-  TestChangeProcessor change_processor;
+  syncer::FakeSyncChangeProcessor change_processor;
 
   EXPECT_FALSE(
       history_service_->MergeDataAndStartSyncing(
-          syncer::HISTORY_DELETE_DIRECTIVES,
-          syncer::SyncDataList(),
-          scoped_ptr<syncer::SyncChangeProcessor>(
-              new SyncChangeProcessorDelegate(&change_processor)),
-          scoped_ptr<syncer::SyncErrorFactory>()).error().IsSet());
+                            syncer::HISTORY_DELETE_DIRECTIVES,
+                            syncer::SyncDataList(),
+                            scoped_ptr<syncer::SyncChangeProcessor>(
+                                new syncer::SyncChangeProcessorWrapperForTest(
+                                    &change_processor)),
+                            scoped_ptr<syncer::SyncErrorFactory>())
+          .error()
+          .IsSet());
 
   syncer::SyncError err =
       history_service_->ProcessLocalDeleteDirective(delete_directive);
   EXPECT_FALSE(err.IsSet());
-  EXPECT_EQ(1u, change_processor.GetChanges().size());
+  EXPECT_EQ(1u, change_processor.changes().size());
 
   history_service_->StopSyncing(syncer::HISTORY_DELETE_DIRECTIVES);
   err = history_service_->ProcessLocalDeleteDirective(delete_directive);
   EXPECT_TRUE(err.IsSet());
-  EXPECT_EQ(1u, change_processor.GetChanges().size());
+  EXPECT_EQ(1u, change_processor.changes().size());
 }
 
 // Closure function that runs periodically to check result of delete directive
 // processing. Stop when timeout or processing ends indicated by the creation
 // of sync changes.
 void CheckDirectiveProcessingResult(
-    Time timeout, const TestChangeProcessor* change_processor,
+    Time timeout,
+    const syncer::FakeSyncChangeProcessor* change_processor,
     uint32 num_changes) {
   if (base::Time::Now() > timeout ||
-      change_processor->GetChanges().size() >= num_changes) {
+      change_processor->changes().size() >= num_changes) {
     return;
   }
 
@@ -1676,7 +1640,7 @@ TEST_F(HistoryTest, ProcessGlobalIdDeleteDirective) {
         base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i);
     history_service_->AddPage(test_url, t, NULL, 0, GURL(),
                               history::RedirectList(),
-                              content::PAGE_TRANSITION_LINK,
+                              ui::PAGE_TRANSITION_LINK,
                               history::SOURCE_BROWSED, false);
   }
 
@@ -1694,8 +1658,12 @@ TEST_F(HistoryTest, ProcessGlobalIdDeleteDirective) {
       .ToInternalValue());
   global_id_directive->set_start_time_usec(3);
   global_id_directive->set_end_time_usec(10);
-  directives.push_back(
-      syncer::SyncData::CreateRemoteData(1, entity_specs, base::Time()));
+  directives.push_back(syncer::SyncData::CreateRemoteData(
+      1,
+      entity_specs,
+      base::Time(),
+      syncer::AttachmentIdList(),
+      syncer::AttachmentServiceProxyForTest::Create()));
 
   // 2nd directive.
   global_id_directive->Clear();
@@ -1704,17 +1672,24 @@ TEST_F(HistoryTest, ProcessGlobalIdDeleteDirective) {
       .ToInternalValue());
   global_id_directive->set_start_time_usec(13);
   global_id_directive->set_end_time_usec(19);
-  directives.push_back(
-      syncer::SyncData::CreateRemoteData(2, entity_specs, base::Time()));
-
-  TestChangeProcessor change_processor;
+  directives.push_back(syncer::SyncData::CreateRemoteData(
+      2,
+      entity_specs,
+      base::Time(),
+      syncer::AttachmentIdList(),
+      syncer::AttachmentServiceProxyForTest::Create()));
+
+  syncer::FakeSyncChangeProcessor change_processor;
   EXPECT_FALSE(
       history_service_->MergeDataAndStartSyncing(
-          syncer::HISTORY_DELETE_DIRECTIVES,
-          directives,
-          scoped_ptr<syncer::SyncChangeProcessor>(
-              new SyncChangeProcessorDelegate(&change_processor)),
-          scoped_ptr<syncer::SyncErrorFactory>()).error().IsSet());
+                            syncer::HISTORY_DELETE_DIRECTIVES,
+                            directives,
+                            scoped_ptr<syncer::SyncChangeProcessor>(
+                                new syncer::SyncChangeProcessorWrapperForTest(
+                                    &change_processor)),
+                            scoped_ptr<syncer::SyncErrorFactory>())
+          .error()
+          .IsSet());
 
   // Inject a task to check status and keep message loop filled before directive
   // processing finishes.
@@ -1738,12 +1713,12 @@ TEST_F(HistoryTest, ProcessGlobalIdDeleteDirective) {
             query_url_visits_[4].visit_time);
 
   // Expect two sync changes for deleting processed directives.
-  const syncer::SyncChangeList& sync_changes = change_processor.GetChanges();
+  const syncer::SyncChangeList& sync_changes = change_processor.changes();
   ASSERT_EQ(2u, sync_changes.size());
   EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type());
-  EXPECT_EQ(1, sync_changes[0].sync_data().GetRemoteId());
+  EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId());
   EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type());
-  EXPECT_EQ(2, sync_changes[1].sync_data().GetRemoteId());
+  EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId());
 }
 
 // Create delete directives for time ranges.  The expected entries should be
@@ -1756,7 +1731,7 @@ TEST_F(HistoryTest, ProcessTimeRangeDeleteDirective) {
         base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i);
     history_service_->AddPage(test_url, t, NULL, 0, GURL(),
                               history::RedirectList(),
-                              content::PAGE_TRANSITION_LINK,
+                              ui::PAGE_TRANSITION_LINK,
                               history::SOURCE_BROWSED, false);
   }
 
@@ -1771,26 +1746,35 @@ TEST_F(HistoryTest, ProcessTimeRangeDeleteDirective) {
           ->mutable_time_range_directive();
   time_range_directive->set_start_time_usec(2);
   time_range_directive->set_end_time_usec(5);
-  directives.push_back(syncer::SyncData::CreateRemoteData(1,
-                                                          entity_specs,
-                                                          base::Time()));
+  directives.push_back(syncer::SyncData::CreateRemoteData(
+      1,
+      entity_specs,
+      base::Time(),
+      syncer::AttachmentIdList(),
+      syncer::AttachmentServiceProxyForTest::Create()));
 
   // 2nd directive.
   time_range_directive->Clear();
   time_range_directive->set_start_time_usec(8);
   time_range_directive->set_end_time_usec(10);
-  directives.push_back(syncer::SyncData::CreateRemoteData(2,
-                                                          entity_specs,
-                                                          base::Time()));
-
-  TestChangeProcessor change_processor;
+  directives.push_back(syncer::SyncData::CreateRemoteData(
+      2,
+      entity_specs,
+      base::Time(),
+      syncer::AttachmentIdList(),
+      syncer::AttachmentServiceProxyForTest::Create()));
+
+  syncer::FakeSyncChangeProcessor change_processor;
   EXPECT_FALSE(
       history_service_->MergeDataAndStartSyncing(
-          syncer::HISTORY_DELETE_DIRECTIVES,
-          directives,
-          scoped_ptr<syncer::SyncChangeProcessor>(
-              new SyncChangeProcessorDelegate(&change_processor)),
-          scoped_ptr<syncer::SyncErrorFactory>()).error().IsSet());
+                            syncer::HISTORY_DELETE_DIRECTIVES,
+                            directives,
+                            scoped_ptr<syncer::SyncChangeProcessor>(
+                                new syncer::SyncChangeProcessorWrapperForTest(
+                                    &change_processor)),
+                            scoped_ptr<syncer::SyncErrorFactory>())
+          .error()
+          .IsSet());
 
   // Inject a task to check status and keep message loop filled before
   // directive processing finishes.
@@ -1810,12 +1794,12 @@ TEST_F(HistoryTest, ProcessTimeRangeDeleteDirective) {
             query_url_visits_[2].visit_time);
 
   // Expect two sync changes for deleting processed directives.
-  const syncer::SyncChangeList& sync_changes = change_processor.GetChanges();
+  const syncer::SyncChangeList& sync_changes = change_processor.changes();
   ASSERT_EQ(2u, sync_changes.size());
   EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type());
-  EXPECT_EQ(1, sync_changes[0].sync_data().GetRemoteId());
+  EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId());
   EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type());
-  EXPECT_EQ(2, sync_changes[1].sync_data().GetRemoteId());
+  EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId());
 }
 
 TEST_F(HistoryBackendDBTest, MigratePresentations) {