OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "components/history/core/browser/visit_tracker.h" | 5 #include "components/history/core/browser/visit_tracker.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 using history::ContextID; | 10 namespace history { |
11 using history::VisitTracker; | |
12 | |
13 namespace { | 11 namespace { |
14 | 12 |
15 struct VisitToTest { | 13 struct VisitToTest { |
16 // Identifies the context. | 14 // Identifies the context. |
17 int context_id_int; | 15 int context_id_int; |
18 int nav_entry_id; | 16 int nav_entry_id; |
19 | 17 |
20 // Used when adding this to the tracker | 18 // Used when adding this to the tracker |
21 const char* url; | 19 const char* url; |
22 const history::VisitID visit_id; | 20 const VisitID visit_id; |
23 | 21 |
24 // Used when finding the referrer | 22 // Used when finding the referrer |
25 const char* referrer; | 23 const char* referrer; |
26 | 24 |
27 // the correct referring visit ID to compare to the computed one | 25 // the correct referring visit ID to compare to the computed one |
28 history::VisitID referring_visit_id; | 26 VisitID referring_visit_id; |
29 }; | 27 }; |
30 | 28 |
31 void RunTest(VisitTracker* tracker, VisitToTest* test, int test_count) { | 29 void RunTest(VisitTracker* tracker, VisitToTest* test, int test_count) { |
32 for (int i = 0; i < test_count; i++) { | 30 for (int i = 0; i < test_count; i++) { |
33 // Our host pointer is actually just an int, convert it (it will not get | 31 // Our host pointer is actually just an int, convert it (it will not get |
34 // dereferenced). | 32 // dereferenced). |
35 ContextID context_id = reinterpret_cast<ContextID>(test[i].context_id_int); | 33 ContextID context_id = reinterpret_cast<ContextID>(test[i].context_id_int); |
36 | 34 |
37 // Check the referrer for this visit. | 35 // Check the referrer for this visit. |
38 history::VisitID ref_visit = tracker->GetLastVisit( | 36 VisitID ref_visit = tracker->GetLastVisit(context_id, test[i].nav_entry_id, |
39 context_id, test[i].nav_entry_id, GURL(test[i].referrer)); | 37 GURL(test[i].referrer)); |
40 EXPECT_EQ(test[i].referring_visit_id, ref_visit); | 38 EXPECT_EQ(test[i].referring_visit_id, ref_visit); |
41 | 39 |
42 // Now add this visit. | 40 // Now add this visit. |
43 tracker->AddVisit( | 41 tracker->AddVisit( |
44 context_id, test[i].nav_entry_id, GURL(test[i].url), test[i].visit_id); | 42 context_id, test[i].nav_entry_id, GURL(test[i].url), test[i].visit_id); |
45 } | 43 } |
46 } | 44 } |
47 | 45 |
48 } // namespace | 46 } // namespace |
49 | 47 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Say that context has been invalidated. | 119 // Say that context has been invalidated. |
122 tracker.ClearCachedDataForContextID(reinterpret_cast<ContextID>(1)); | 120 tracker.ClearCachedDataForContextID(reinterpret_cast<ContextID>(1)); |
123 | 121 |
124 // Simple navigation from a new process with the same ID, it should not find | 122 // Simple navigation from a new process with the same ID, it should not find |
125 // a referrer. | 123 // a referrer. |
126 VisitToTest part2[] = { | 124 VisitToTest part2[] = { |
127 {1, 1, "http://images.google.com/", 2, "http://www.google.com/", 0}, | 125 {1, 1, "http://images.google.com/", 2, "http://www.google.com/", 0}, |
128 }; | 126 }; |
129 RunTest(&tracker, part2, arraysize(part2)); | 127 RunTest(&tracker, part2, arraysize(part2)); |
130 } | 128 } |
| 129 |
| 130 } // namespace history |
OLD | NEW |