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 "base/values.h" | 5 #include "base/values.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "chrome/browser/prerender/prerender_history.h" | 7 #include "chrome/browser/prerender/prerender_history.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace prerender { | 10 namespace prerender { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); | 60 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); |
61 EXPECT_TRUE(entry_list->empty()); | 61 EXPECT_TRUE(entry_list->empty()); |
62 | 62 |
63 // Base time used for all events. Each event is given a time 1 millisecond | 63 // Base time used for all events. Each event is given a time 1 millisecond |
64 // after that of the previous one. | 64 // after that of the previous one. |
65 base::Time epoch_start = base::Time::UnixEpoch(); | 65 base::Time epoch_start = base::Time::UnixEpoch(); |
66 | 66 |
67 // Add a single entry and make sure that it matches up. | 67 // Add a single entry and make sure that it matches up. |
68 const char* const kFirstUrl = "http://www.alpha.com/"; | 68 const char* const kFirstUrl = "http://www.alpha.com/"; |
69 const FinalStatus kFirstFinalStatus = FINAL_STATUS_USED; | 69 const FinalStatus kFirstFinalStatus = FINAL_STATUS_USED; |
70 const Origin kFirstOrigin = ORIGIN_LINK_REL_PRERENDER; | 70 const Origin kFirstOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN; |
71 PrerenderHistory::Entry entry_first( | 71 PrerenderHistory::Entry entry_first( |
72 GURL(kFirstUrl), kFirstFinalStatus, kFirstOrigin, epoch_start); | 72 GURL(kFirstUrl), kFirstFinalStatus, kFirstOrigin, epoch_start); |
73 history.AddEntry(entry_first); | 73 history.AddEntry(entry_first); |
74 entry_value.reset(history.GetEntriesAsValue()); | 74 entry_value.reset(history.GetEntriesAsValue()); |
75 ASSERT_TRUE(entry_value.get() != NULL); | 75 ASSERT_TRUE(entry_value.get() != NULL); |
76 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); | 76 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); |
77 EXPECT_EQ(1u, entry_list->GetSize()); | 77 EXPECT_EQ(1u, entry_list->GetSize()); |
78 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kFirstUrl, kFirstFinalStatus, | 78 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kFirstUrl, kFirstFinalStatus, |
79 kFirstOrigin, "0")); | 79 kFirstOrigin, "0")); |
80 | 80 |
(...skipping 10 matching lines...) Expand all Loading... |
91 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); | 91 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); |
92 EXPECT_EQ(2u, entry_list->GetSize()); | 92 EXPECT_EQ(2u, entry_list->GetSize()); |
93 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kSecondUrl, kSecondFinalStatus, | 93 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kSecondUrl, kSecondFinalStatus, |
94 kSecondOrigin, "1")); | 94 kSecondOrigin, "1")); |
95 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kFirstUrl, kFirstFinalStatus, | 95 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kFirstUrl, kFirstFinalStatus, |
96 kFirstOrigin, "0")); | 96 kFirstOrigin, "0")); |
97 | 97 |
98 // Add a third entry and make sure that the first one drops off. | 98 // Add a third entry and make sure that the first one drops off. |
99 const char* const kThirdUrl = "http://www.gamma.com/"; | 99 const char* const kThirdUrl = "http://www.gamma.com/"; |
100 const FinalStatus kThirdFinalStatus = FINAL_STATUS_AUTH_NEEDED; | 100 const FinalStatus kThirdFinalStatus = FINAL_STATUS_AUTH_NEEDED; |
101 const Origin kThirdOrigin = ORIGIN_LINK_REL_PRERENDER; | 101 const Origin kThirdOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN; |
102 PrerenderHistory::Entry entry_third( | 102 PrerenderHistory::Entry entry_third( |
103 GURL(kThirdUrl), kThirdFinalStatus, kThirdOrigin, | 103 GURL(kThirdUrl), kThirdFinalStatus, kThirdOrigin, |
104 epoch_start + base::TimeDelta::FromMilliseconds(2)); | 104 epoch_start + base::TimeDelta::FromMilliseconds(2)); |
105 history.AddEntry(entry_third); | 105 history.AddEntry(entry_third); |
106 entry_value.reset(history.GetEntriesAsValue()); | 106 entry_value.reset(history.GetEntriesAsValue()); |
107 ASSERT_TRUE(entry_value.get() != NULL); | 107 ASSERT_TRUE(entry_value.get() != NULL); |
108 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); | 108 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); |
109 EXPECT_EQ(2u, entry_list->GetSize()); | 109 EXPECT_EQ(2u, entry_list->GetSize()); |
110 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kThirdUrl, kThirdFinalStatus, | 110 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kThirdUrl, kThirdFinalStatus, |
111 kThirdOrigin, "2")); | 111 kThirdOrigin, "2")); |
112 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kSecondUrl, kSecondFinalStatus, | 112 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kSecondUrl, kSecondFinalStatus, |
113 kSecondOrigin, "1")); | 113 kSecondOrigin, "1")); |
114 | 114 |
115 // Make sure clearing history acts as expected. | 115 // Make sure clearing history acts as expected. |
116 history.Clear(); | 116 history.Clear(); |
117 entry_value.reset(history.GetEntriesAsValue()); | 117 entry_value.reset(history.GetEntriesAsValue()); |
118 ASSERT_TRUE(entry_value.get() != NULL); | 118 ASSERT_TRUE(entry_value.get() != NULL); |
119 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); | 119 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); |
120 EXPECT_TRUE(entry_list->empty()); | 120 EXPECT_TRUE(entry_list->empty()); |
121 } | 121 } |
122 | 122 |
123 } // namespace | 123 } // namespace |
124 | 124 |
125 } // namespace prerender | 125 } // namespace prerender |
OLD | NEW |