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 #include <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 int page_id, | 163 int page_id, |
164 content::PageTransition transition, | 164 content::PageTransition transition, |
165 base::Time time) { | 165 base::Time time) { |
166 history::RedirectList redirects; | 166 history::RedirectList redirects; |
167 for (int i = 0; sequence[i] != NULL; ++i) | 167 for (int i = 0; sequence[i] != NULL; ++i) |
168 redirects.push_back(GURL(sequence[i])); | 168 redirects.push_back(GURL(sequence[i])); |
169 | 169 |
170 int int_scope = 1; | 170 int int_scope = 1; |
171 void* scope = 0; | 171 void* scope = 0; |
172 memcpy(&scope, &int_scope, sizeof(int_scope)); | 172 memcpy(&scope, &int_scope, sizeof(int_scope)); |
173 scoped_refptr<history::HistoryAddPageArgs> request( | 173 history::HistoryAddPageArgs request( |
174 new history::HistoryAddPageArgs( | 174 redirects.back(), time, scope, page_id, GURL(), |
175 redirects.back(), time, scope, page_id, GURL(), | 175 redirects, transition, history::SOURCE_BROWSED, |
176 redirects, transition, history::SOURCE_BROWSED, | 176 true); |
177 true)); | |
178 backend_->AddPage(request); | 177 backend_->AddPage(request); |
179 } | 178 } |
180 | 179 |
181 // Adds CLIENT_REDIRECT page transition. | 180 // Adds CLIENT_REDIRECT page transition. |
182 // |url1| is the source URL and |url2| is the destination. | 181 // |url1| is the source URL and |url2| is the destination. |
183 // |did_replace| is true if the transition is non-user initiated and the | 182 // |did_replace| is true if the transition is non-user initiated and the |
184 // navigation entry for |url2| has replaced that for |url1|. The possibly | 183 // navigation entry for |url2| has replaced that for |url1|. The possibly |
185 // updated transition code of the visit records for |url1| and |url2| is | 184 // updated transition code of the visit records for |url1| and |url2| is |
186 // returned by filling in |*transition1| and |*transition2|, respectively. | 185 // returned by filling in |*transition1| and |*transition2|, respectively. |
187 // |time| is a time of the redirect. | 186 // |time| is a time of the redirect. |
188 void AddClientRedirect(const GURL& url1, const GURL& url2, bool did_replace, | 187 void AddClientRedirect(const GURL& url1, const GURL& url2, bool did_replace, |
189 base::Time time, | 188 base::Time time, |
190 int* transition1, int* transition2) { | 189 int* transition1, int* transition2) { |
191 void* const dummy_scope = reinterpret_cast<void*>(0x87654321); | 190 void* const dummy_scope = reinterpret_cast<void*>(0x87654321); |
192 history::RedirectList redirects; | 191 history::RedirectList redirects; |
193 if (url1.is_valid()) | 192 if (url1.is_valid()) |
194 redirects.push_back(url1); | 193 redirects.push_back(url1); |
195 if (url2.is_valid()) | 194 if (url2.is_valid()) |
196 redirects.push_back(url2); | 195 redirects.push_back(url2); |
197 scoped_refptr<HistoryAddPageArgs> request( | 196 HistoryAddPageArgs request( |
198 new HistoryAddPageArgs(url2, time, dummy_scope, 0, url1, | 197 url2, time, dummy_scope, 0, url1, |
199 redirects, content::PAGE_TRANSITION_CLIENT_REDIRECT, | 198 redirects, content::PAGE_TRANSITION_CLIENT_REDIRECT, |
200 history::SOURCE_BROWSED, did_replace)); | 199 history::SOURCE_BROWSED, did_replace); |
201 backend_->AddPage(request); | 200 backend_->AddPage(request); |
202 | 201 |
203 *transition1 = getTransition(url1); | 202 *transition1 = getTransition(url1); |
204 *transition2 = getTransition(url2); | 203 *transition2 = getTransition(url2); |
205 } | 204 } |
206 | 205 |
207 int getTransition(const GURL& url) { | 206 int getTransition(const GURL& url) { |
208 if (!url.is_valid()) | 207 if (!url.is_valid()) |
209 return 0; | 208 return 0; |
210 URLRow row; | 209 URLRow row; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 } | 617 } |
619 | 618 |
620 // Checks that adding a visit, then calling DeleteAll, and then trying to add | 619 // Checks that adding a visit, then calling DeleteAll, and then trying to add |
621 // data for the visited page works. This can happen when clearing the history | 620 // data for the visited page works. This can happen when clearing the history |
622 // immediately after visiting a page. | 621 // immediately after visiting a page. |
623 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { | 622 TEST_F(HistoryBackendTest, DeleteAllThenAddData) { |
624 ASSERT_TRUE(backend_.get()); | 623 ASSERT_TRUE(backend_.get()); |
625 | 624 |
626 Time visit_time = Time::Now(); | 625 Time visit_time = Time::Now(); |
627 GURL url("http://www.google.com/"); | 626 GURL url("http://www.google.com/"); |
628 scoped_refptr<HistoryAddPageArgs> request( | 627 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), |
629 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(), | |
630 history::RedirectList(), | 628 history::RedirectList(), |
631 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 629 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
632 history::SOURCE_BROWSED, false)); | 630 history::SOURCE_BROWSED, false); |
633 backend_->AddPage(request); | 631 backend_->AddPage(request); |
634 | 632 |
635 // Check that a row was added. | 633 // Check that a row was added. |
636 URLRow outrow; | 634 URLRow outrow; |
637 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow)); | 635 EXPECT_TRUE(backend_->db_->GetRowForURL(url, &outrow)); |
638 | 636 |
639 // Check that the visit was added. | 637 // Check that the visit was added. |
640 VisitVector all_visits; | 638 VisitVector all_visits; |
641 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); | 639 backend_->db_->GetAllVisitsInRange(Time(), Time(), 0, &all_visits); |
642 ASSERT_EQ(1U, all_visits.size()); | 640 ASSERT_EQ(1U, all_visits.size()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 } | 774 } |
777 | 775 |
778 // Tests a handful of assertions for a navigation with a type of | 776 // Tests a handful of assertions for a navigation with a type of |
779 // KEYWORD_GENERATED. | 777 // KEYWORD_GENERATED. |
780 TEST_F(HistoryBackendTest, KeywordGenerated) { | 778 TEST_F(HistoryBackendTest, KeywordGenerated) { |
781 ASSERT_TRUE(backend_.get()); | 779 ASSERT_TRUE(backend_.get()); |
782 | 780 |
783 GURL url("http://google.com"); | 781 GURL url("http://google.com"); |
784 | 782 |
785 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); | 783 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); |
786 scoped_refptr<HistoryAddPageArgs> request( | 784 HistoryAddPageArgs request(url, visit_time, NULL, 0, GURL(), |
787 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(), | |
788 history::RedirectList(), | 785 history::RedirectList(), |
789 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 786 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
790 history::SOURCE_BROWSED, false)); | 787 history::SOURCE_BROWSED, false); |
791 backend_->AddPage(request); | 788 backend_->AddPage(request); |
792 | 789 |
793 // A row should have been added for the url. | 790 // A row should have been added for the url. |
794 URLRow row; | 791 URLRow row; |
795 URLID url_id = backend_->db()->GetRowForURL(url, &row); | 792 URLID url_id = backend_->db()->GetRowForURL(url, &row); |
796 ASSERT_NE(0, url_id); | 793 ASSERT_NE(0, url_id); |
797 | 794 |
798 // The typed count should be 1. | 795 // The typed count should be 1. |
799 ASSERT_EQ(1, row.typed_count()); | 796 ASSERT_EQ(1, row.typed_count()); |
800 | 797 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 } | 1001 } |
1005 EXPECT_EQ(0x7, sources); | 1002 EXPECT_EQ(0x7, sources); |
1006 } | 1003 } |
1007 | 1004 |
1008 TEST_F(HistoryBackendTest, AddPageArgsSource) { | 1005 TEST_F(HistoryBackendTest, AddPageArgsSource) { |
1009 ASSERT_TRUE(backend_.get()); | 1006 ASSERT_TRUE(backend_.get()); |
1010 | 1007 |
1011 GURL url("http://testpageargs.com"); | 1008 GURL url("http://testpageargs.com"); |
1012 | 1009 |
1013 // Assume this page is browsed by user. | 1010 // Assume this page is browsed by user. |
1014 scoped_refptr<HistoryAddPageArgs> request1( | 1011 HistoryAddPageArgs request1(url, base::Time::Now(), NULL, 0, GURL(), |
1015 new HistoryAddPageArgs(url, base::Time::Now(), NULL, 0, GURL(), | |
1016 history::RedirectList(), | 1012 history::RedirectList(), |
1017 content::PAGE_TRANSITION_KEYWORD_GENERATED, | 1013 content::PAGE_TRANSITION_KEYWORD_GENERATED, |
1018 history::SOURCE_BROWSED, false)); | 1014 history::SOURCE_BROWSED, false); |
1019 backend_->AddPage(request1); | 1015 backend_->AddPage(request1); |
1020 // Assume this page is synced. | 1016 // Assume this page is synced. |
1021 scoped_refptr<HistoryAddPageArgs> request2( | 1017 HistoryAddPageArgs request2(url, base::Time::Now(), NULL, 0, GURL(), |
1022 new HistoryAddPageArgs(url, base::Time::Now(), NULL, 0, GURL(), | |
1023 history::RedirectList(), | 1018 history::RedirectList(), |
1024 content::PAGE_TRANSITION_LINK, | 1019 content::PAGE_TRANSITION_LINK, |
1025 history::SOURCE_SYNCED, false)); | 1020 history::SOURCE_SYNCED, false); |
1026 backend_->AddPage(request2); | 1021 backend_->AddPage(request2); |
1027 // Assume this page is browsed again. | 1022 // Assume this page is browsed again. |
1028 scoped_refptr<HistoryAddPageArgs> request3( | 1023 HistoryAddPageArgs request3(url, base::Time::Now(), NULL, 0, GURL(), |
1029 new HistoryAddPageArgs(url, base::Time::Now(), NULL, 0, GURL(), | |
1030 history::RedirectList(), | 1024 history::RedirectList(), |
1031 content::PAGE_TRANSITION_TYPED, | 1025 content::PAGE_TRANSITION_TYPED, |
1032 history::SOURCE_BROWSED, false)); | 1026 history::SOURCE_BROWSED, false); |
1033 backend_->AddPage(request3); | 1027 backend_->AddPage(request3); |
1034 | 1028 |
1035 // Three visits should be added with proper sources. | 1029 // Three visits should be added with proper sources. |
1036 VisitVector visits; | 1030 VisitVector visits; |
1037 URLRow row; | 1031 URLRow row; |
1038 URLID id = backend_->db()->GetRowForURL(url, &row); | 1032 URLID id = backend_->db()->GetRowForURL(url, &row); |
1039 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); | 1033 ASSERT_TRUE(backend_->db()->GetVisitsForURL(id, &visits)); |
1040 ASSERT_EQ(3U, visits.size()); | 1034 ASSERT_EQ(3U, visits.size()); |
1041 VisitSourceMap visit_sources; | 1035 VisitSourceMap visit_sources; |
1042 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources)); | 1036 ASSERT_TRUE(backend_->GetVisitsSource(visits, &visit_sources)); |
(...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 | 2623 |
2630 backend_->DeleteURL(url); | 2624 backend_->DeleteURL(url); |
2631 backend_->AddPageNoVisitForBookmark(url, string16()); | 2625 backend_->AddPageNoVisitForBookmark(url, string16()); |
2632 backend_->GetURL(url, &row); | 2626 backend_->GetURL(url, &row); |
2633 EXPECT_EQ(url, row.url()); | 2627 EXPECT_EQ(url, row.url()); |
2634 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); | 2628 EXPECT_EQ(UTF8ToUTF16(url.spec()), row.title()); |
2635 EXPECT_EQ(0, row.visit_count()); | 2629 EXPECT_EQ(0, row.visit_count()); |
2636 } | 2630 } |
2637 | 2631 |
2638 } // namespace history | 2632 } // namespace history |
OLD | NEW |