Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/prerender/prerender_history_unittest.cc

Issue 2893653002: Rename Ownership Transferring Methods for Prerenderer (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/prerender/prerender_history.h" 5 #include "chrome/browser/prerender/prerender_history.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 TEST(PrerenderHistoryTest, GetAsValue) { 54 TEST(PrerenderHistoryTest, GetAsValue) {
55 std::unique_ptr<base::Value> entry_value; 55 std::unique_ptr<base::Value> entry_value;
56 base::ListValue* entry_list = NULL; 56 base::ListValue* entry_list = NULL;
57 57
58 // Create a history with only 2 values. 58 // Create a history with only 2 values.
59 PrerenderHistory history(2); 59 PrerenderHistory history(2);
60 60
61 // Make sure an empty list exists when retrieving as value. 61 // Make sure an empty list exists when retrieving as value.
62 entry_value = history.GetEntriesAsValue(); 62 entry_value = history.CopyEntriesAsValue();
63 ASSERT_TRUE(entry_value.get() != NULL); 63 ASSERT_TRUE(entry_value.get() != NULL);
64 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); 64 ASSERT_TRUE(entry_value->GetAsList(&entry_list));
65 EXPECT_TRUE(entry_list->empty()); 65 EXPECT_TRUE(entry_list->empty());
66 66
67 // Base time used for all events. Each event is given a time 1 millisecond 67 // Base time used for all events. Each event is given a time 1 millisecond
68 // after that of the previous one. 68 // after that of the previous one.
69 base::Time epoch_start = base::Time::UnixEpoch(); 69 base::Time epoch_start = base::Time::UnixEpoch();
70 70
71 // Add a single entry and make sure that it matches up. 71 // Add a single entry and make sure that it matches up.
72 const char* const kFirstUrl = "http://www.alpha.com/"; 72 const char* const kFirstUrl = "http://www.alpha.com/";
73 const FinalStatus kFirstFinalStatus = FINAL_STATUS_USED; 73 const FinalStatus kFirstFinalStatus = FINAL_STATUS_USED;
74 const Origin kFirstOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN; 74 const Origin kFirstOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN;
75 PrerenderHistory::Entry entry_first( 75 PrerenderHistory::Entry entry_first(
76 GURL(kFirstUrl), kFirstFinalStatus, kFirstOrigin, epoch_start); 76 GURL(kFirstUrl), kFirstFinalStatus, kFirstOrigin, epoch_start);
77 history.AddEntry(entry_first); 77 history.AddEntry(entry_first);
78 entry_value = history.GetEntriesAsValue(); 78 entry_value = history.CopyEntriesAsValue();
79 ASSERT_TRUE(entry_value.get() != NULL); 79 ASSERT_TRUE(entry_value.get() != NULL);
80 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); 80 ASSERT_TRUE(entry_value->GetAsList(&entry_list));
81 EXPECT_EQ(1u, entry_list->GetSize()); 81 EXPECT_EQ(1u, entry_list->GetSize());
82 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kFirstUrl, kFirstFinalStatus, 82 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kFirstUrl, kFirstFinalStatus,
83 kFirstOrigin, "0")); 83 kFirstOrigin, "0"));
84 84
85 // Add a second entry and make sure both first and second appear. 85 // Add a second entry and make sure both first and second appear.
86 const char* const kSecondUrl = "http://www.beta.com/"; 86 const char* const kSecondUrl = "http://www.beta.com/";
87 const FinalStatus kSecondFinalStatus = FINAL_STATUS_INVALID_HTTP_METHOD; 87 const FinalStatus kSecondFinalStatus = FINAL_STATUS_INVALID_HTTP_METHOD;
88 const Origin kSecondOrigin = ORIGIN_OMNIBOX; 88 const Origin kSecondOrigin = ORIGIN_OMNIBOX;
89 PrerenderHistory::Entry entry_second( 89 PrerenderHistory::Entry entry_second(
90 GURL(kSecondUrl), kSecondFinalStatus, kSecondOrigin, 90 GURL(kSecondUrl), kSecondFinalStatus, kSecondOrigin,
91 epoch_start + base::TimeDelta::FromMilliseconds(1)); 91 epoch_start + base::TimeDelta::FromMilliseconds(1));
92 history.AddEntry(entry_second); 92 history.AddEntry(entry_second);
93 entry_value = history.GetEntriesAsValue(); 93 entry_value = history.CopyEntriesAsValue();
94 ASSERT_TRUE(entry_value.get() != NULL); 94 ASSERT_TRUE(entry_value.get() != NULL);
95 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); 95 ASSERT_TRUE(entry_value->GetAsList(&entry_list));
96 EXPECT_EQ(2u, entry_list->GetSize()); 96 EXPECT_EQ(2u, entry_list->GetSize());
97 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kSecondUrl, kSecondFinalStatus, 97 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kSecondUrl, kSecondFinalStatus,
98 kSecondOrigin, "1")); 98 kSecondOrigin, "1"));
99 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kFirstUrl, kFirstFinalStatus, 99 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kFirstUrl, kFirstFinalStatus,
100 kFirstOrigin, "0")); 100 kFirstOrigin, "0"));
101 101
102 // Add a third entry and make sure that the first one drops off. 102 // Add a third entry and make sure that the first one drops off.
103 const char* const kThirdUrl = "http://www.gamma.com/"; 103 const char* const kThirdUrl = "http://www.gamma.com/";
104 const FinalStatus kThirdFinalStatus = FINAL_STATUS_AUTH_NEEDED; 104 const FinalStatus kThirdFinalStatus = FINAL_STATUS_AUTH_NEEDED;
105 const Origin kThirdOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN; 105 const Origin kThirdOrigin = ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN;
106 PrerenderHistory::Entry entry_third( 106 PrerenderHistory::Entry entry_third(
107 GURL(kThirdUrl), kThirdFinalStatus, kThirdOrigin, 107 GURL(kThirdUrl), kThirdFinalStatus, kThirdOrigin,
108 epoch_start + base::TimeDelta::FromMilliseconds(2)); 108 epoch_start + base::TimeDelta::FromMilliseconds(2));
109 history.AddEntry(entry_third); 109 history.AddEntry(entry_third);
110 entry_value = history.GetEntriesAsValue(); 110 entry_value = history.CopyEntriesAsValue();
111 ASSERT_TRUE(entry_value.get() != NULL); 111 ASSERT_TRUE(entry_value.get() != NULL);
112 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); 112 ASSERT_TRUE(entry_value->GetAsList(&entry_list));
113 EXPECT_EQ(2u, entry_list->GetSize()); 113 EXPECT_EQ(2u, entry_list->GetSize());
114 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kThirdUrl, kThirdFinalStatus, 114 EXPECT_TRUE(ListEntryMatches(entry_list, 0u, kThirdUrl, kThirdFinalStatus,
115 kThirdOrigin, "2")); 115 kThirdOrigin, "2"));
116 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kSecondUrl, kSecondFinalStatus, 116 EXPECT_TRUE(ListEntryMatches(entry_list, 1u, kSecondUrl, kSecondFinalStatus,
117 kSecondOrigin, "1")); 117 kSecondOrigin, "1"));
118 118
119 // Make sure clearing history acts as expected. 119 // Make sure clearing history acts as expected.
120 history.Clear(); 120 history.Clear();
121 entry_value = history.GetEntriesAsValue(); 121 entry_value = history.CopyEntriesAsValue();
122 ASSERT_TRUE(entry_value.get() != NULL); 122 ASSERT_TRUE(entry_value.get() != NULL);
123 ASSERT_TRUE(entry_value->GetAsList(&entry_list)); 123 ASSERT_TRUE(entry_value->GetAsList(&entry_list));
124 EXPECT_TRUE(entry_list->empty()); 124 EXPECT_TRUE(entry_list->empty());
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 } // namespace prerender 129 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698