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

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 11299218: [Sync] Implement processing of history delete directives (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/history.cc ('k') | no next file » | 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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/history/page_usage_data.h" 46 #include "chrome/browser/history/page_usage_data.h"
47 #include "chrome/common/chrome_constants.h" 47 #include "chrome/common/chrome_constants.h"
48 #include "chrome/common/chrome_paths.h" 48 #include "chrome/common/chrome_paths.h"
49 #include "chrome/common/thumbnail_score.h" 49 #include "chrome/common/thumbnail_score.h"
50 #include "chrome/tools/profiles/thumbnail-inl.h" 50 #include "chrome/tools/profiles/thumbnail-inl.h"
51 #include "content/public/browser/download_item.h" 51 #include "content/public/browser/download_item.h"
52 #include "content/public/browser/notification_details.h" 52 #include "content/public/browser/notification_details.h"
53 #include "content/public/browser/notification_source.h" 53 #include "content/public/browser/notification_source.h"
54 #include "sql/connection.h" 54 #include "sql/connection.h"
55 #include "sql/statement.h" 55 #include "sql/statement.h"
56 #include "sync/protocol/history_delete_directive_specifics.pb.h"
56 #include "testing/gtest/include/gtest/gtest.h" 57 #include "testing/gtest/include/gtest/gtest.h"
57 #include "third_party/skia/include/core/SkBitmap.h" 58 #include "third_party/skia/include/core/SkBitmap.h"
58 #include "ui/gfx/codec/jpeg_codec.h" 59 #include "ui/gfx/codec/jpeg_codec.h"
59 60
60 using base::Time; 61 using base::Time;
61 using base::TimeDelta; 62 using base::TimeDelta;
62 using content::DownloadItem; 63 using content::DownloadItem;
63 64
64 namespace history { 65 namespace history {
65 class HistoryBackendDBTest; 66 class HistoryBackendDBTest;
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 CancelableRequestConsumerT<int, 0> request_consumer; 961 CancelableRequestConsumerT<int, 0> request_consumer;
961 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl()); 962 scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
962 history_service_->ScheduleDBTask(task.get(), &request_consumer); 963 history_service_->ScheduleDBTask(task.get(), &request_consumer);
963 request_consumer.CancelAllRequests(); 964 request_consumer.CancelAllRequests();
964 CleanupHistoryService(); 965 CleanupHistoryService();
965 // WARNING: history has now been deleted. 966 // WARNING: history has now been deleted.
966 history_service_.reset(); 967 history_service_.reset();
967 ASSERT_FALSE(task->done_invoked); 968 ASSERT_FALSE(task->done_invoked);
968 } 969 }
969 970
971 TEST_F(HistoryTest, ProcessGlobalIdDeleteDirective) {
972 ASSERT_TRUE(history_service_.get());
973 // Add the page once from a child frame.
974 const GURL test_url("http://www.google.com/");
975 for (int64 i = 1; i <= 10; ++i) {
976 base::Time t =
977 base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i);
978 history_service_->AddPage(test_url, t, NULL, 0, GURL(),
979 history::RedirectList(),
980 content::PAGE_TRANSITION_LINK,
981 history::SOURCE_BROWSED, false);
982 }
983
984 EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
985 EXPECT_EQ(10, query_url_row_.visit_count());
986
987 sync_pb::HistoryDeleteDirectiveSpecifics delete_directive;
988 sync_pb::GlobalIdDirective* global_id_directive =
989 delete_directive.mutable_global_id_directive();
990 global_id_directive->add_global_id(
991 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(0))
992 .ToInternalValue());
993 global_id_directive->add_global_id(
994 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(2))
995 .ToInternalValue());
996 global_id_directive->add_global_id(
997 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(5))
998 .ToInternalValue());
999 global_id_directive->add_global_id(
1000 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(10))
1001 .ToInternalValue());
1002 global_id_directive->add_global_id(
1003 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(20))
1004 .ToInternalValue());
1005
1006 history_service_->ProcessDeleteDirectiveForTest(delete_directive);
1007
1008 EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
1009 EXPECT_EQ(7, query_url_row_.visit_count());
1010 }
1011
1012 TEST_F(HistoryTest, ProcessTimeRangeDeleteDirective) {
1013 ASSERT_TRUE(history_service_.get());
1014 // Add the page once from a child frame.
1015 const GURL test_url("http://www.google.com/");
1016 for (int64 i = 1; i <= 10; ++i) {
1017 base::Time t =
1018 base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i);
1019 history_service_->AddPage(test_url, t, NULL, 0, GURL(),
1020 history::RedirectList(),
1021 content::PAGE_TRANSITION_LINK,
1022 history::SOURCE_BROWSED, false);
1023 }
1024
1025 EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
1026 EXPECT_EQ(10, query_url_row_.visit_count());
1027
1028 sync_pb::HistoryDeleteDirectiveSpecifics delete_directive;
1029 sync_pb::TimeRangeDirective* time_range_directive =
1030 delete_directive.mutable_time_range_directive();
1031 time_range_directive->set_start_time_usec(2);
1032 time_range_directive->set_end_time_usec(9);
1033
1034 history_service_->ProcessDeleteDirectiveForTest(delete_directive);
1035
1036 EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
1037 EXPECT_EQ(2, query_url_row_.visit_count());
1038 }
1039
970 } // namespace 1040 } // namespace
971 1041
972 } // namespace history 1042 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698