OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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(2)) | |
Nicolas Zea
2012/11/29 22:29:43
add a 0 case as well?
akalin
2012/11/29 23:44:58
Done.
| |
992 .ToInternalValue()); | |
993 global_id_directive->add_global_id( | |
994 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(5)) | |
995 .ToInternalValue()); | |
996 global_id_directive->add_global_id( | |
997 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(10)) | |
998 .ToInternalValue()); | |
999 global_id_directive->add_global_id( | |
1000 (base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(20)) | |
1001 .ToInternalValue()); | |
1002 | |
1003 history_service_->ProcessDeleteDirectiveForTest(delete_directive); | |
1004 | |
1005 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); | |
1006 EXPECT_EQ(7, query_url_row_.visit_count()); | |
1007 } | |
1008 | |
1009 TEST_F(HistoryTest, ProcessTimeRangeDeleteDirective) { | |
1010 ASSERT_TRUE(history_service_.get()); | |
1011 // Add the page once from a child frame. | |
1012 const GURL test_url("http://www.google.com/"); | |
1013 for (int64 i = 1; i <= 10; ++i) { | |
1014 base::Time t = | |
1015 base::Time::UnixEpoch() + base::TimeDelta::FromMicroseconds(i); | |
1016 history_service_->AddPage(test_url, t, NULL, 0, GURL(), | |
1017 history::RedirectList(), | |
1018 content::PAGE_TRANSITION_LINK, | |
1019 history::SOURCE_BROWSED, false); | |
1020 } | |
1021 | |
1022 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); | |
1023 EXPECT_EQ(10, query_url_row_.visit_count()); | |
1024 | |
1025 sync_pb::HistoryDeleteDirectiveSpecifics delete_directive; | |
1026 sync_pb::TimeRangeDirective* time_range_directive = | |
1027 delete_directive.mutable_time_range_directive(); | |
1028 time_range_directive->set_start_time_usec(2); | |
1029 time_range_directive->set_end_time_usec(9); | |
1030 | |
1031 history_service_->ProcessDeleteDirectiveForTest(delete_directive); | |
1032 | |
1033 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); | |
1034 EXPECT_EQ(2, query_url_row_.visit_count()); | |
1035 } | |
1036 | |
970 } // namespace | 1037 } // namespace |
971 | 1038 |
972 } // namespace history | 1039 } // namespace history |
OLD | NEW |