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