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