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

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

Issue 7210020: Added prerendering to omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/prerender/prerender_tracker.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <set> 5 #include <set>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/prerender/prerender_manager.h" 8 #include "chrome/browser/prerender/prerender_manager.h"
9 #include "chrome/browser/prerender/prerender_tracker.h" 9 #include "chrome/browser/prerender/prerender_tracker.h"
10 #include "chrome/test/testing_browser_process.h" 10 #include "chrome/test/testing_browser_process.h"
11 #include "content/browser/browser_thread.h" 11 #include "content/browser/browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace prerender { 14 namespace prerender {
15 15
16 namespace { 16 namespace {
17 17
18 class TestPrerenderManager : public PrerenderManager { 18 class TestPrerenderManager : public PrerenderManager {
19 public: 19 public:
20 explicit TestPrerenderManager(PrerenderTracker* prerender_tracker) : 20 explicit TestPrerenderManager(PrerenderTracker* prerender_tracker) :
21 PrerenderManager(NULL, prerender_tracker) { 21 PrerenderManager(NULL, prerender_tracker) {
22 rate_limit_enabled_ = false; 22 rate_limit_enabled_ = false;
23 } 23 }
24 24
25 virtual void DestroyPreloadForChildRouteIdPair( 25 virtual void DestroyPrerenderForChildRouteIdPair(
26 const std::pair<int, int>& child_route_id_pair, 26 const std::pair<int, int>& child_route_id_pair,
27 FinalStatus final_status) OVERRIDE { 27 FinalStatus final_status) OVERRIDE {
28 cancelled_id_pairs_.insert(child_route_id_pair); 28 cancelled_id_pairs_.insert(child_route_id_pair);
29 } 29 }
30 30
31 bool WasPrerenderCancelled(int child_id, int route_id) { 31 bool WasPrerenderCancelled(int child_id, int route_id) {
32 std::pair<int, int> child_route_id_pair(child_id, route_id); 32 std::pair<int, int> child_route_id_pair(child_id, route_id);
33 return cancelled_id_pairs_.count(child_route_id_pair) != 0; 33 return cancelled_id_pairs_.count(child_route_id_pair) != 0;
34 } 34 }
35 35
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Display the prerendered RenderView. 104 // Display the prerendered RenderView.
105 EXPECT_TRUE(prerender_tracker()->TryUse(0, 0)); 105 EXPECT_TRUE(prerender_tracker()->TryUse(0, 0));
106 106
107 // Make sure the page can't be destroyed or claim it was destroyed after 107 // Make sure the page can't be destroyed or claim it was destroyed after
108 // it's been used. 108 // it's been used.
109 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 109 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
110 EXPECT_FALSE(prerender_tracker()->TryCancelOnIOThread( 110 EXPECT_FALSE(prerender_tracker()->TryCancelOnIOThread(
111 0, 0, FINAL_STATUS_TIMED_OUT)); 111 0, 0, FINAL_STATUS_TIMED_OUT));
112 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0)); 112 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0));
113 113
114 // This would call DestroyPreloadForChildRouteIdPair(), if the prerender were 114 // This would call DestroyPrerenderForChildRouteIdPair(), if the prerender
115 // cancelled. 115 // were cancelled.
116 RunEvents(); 116 RunEvents();
117 117
118 // These functions should all behave as before. 118 // These functions should all behave as before.
119 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 119 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
120 EXPECT_FALSE(prerender_tracker()->TryCancelOnIOThread( 120 EXPECT_FALSE(prerender_tracker()->TryCancelOnIOThread(
121 0, 0, FINAL_STATUS_TIMED_OUT)); 121 0, 0, FINAL_STATUS_TIMED_OUT));
122 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0)); 122 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0));
123 123
124 // This calls DestroyPreloadForChildRouteIdPair(). 124 // This calls DestroyPrerenderForChildRouteIdPair().
125 prerender_tracker()->OnPrerenderingFinished(0, 0); 125 prerender_tracker()->OnPrerenderingFinished(0, 0);
126 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0)); 126 EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0));
127 127
128 // This calls RemovePrerenderOnIOThreadTask(). 128 // This calls RemovePrerenderOnIOThreadTask().
129 RunEvents(); 129 RunEvents();
130 130
131 FinalStatus final_status; 131 FinalStatus final_status;
132 EXPECT_FALSE(prerender_tracker()->GetFinalStatus(0, 0, &final_status)); 132 EXPECT_FALSE(prerender_tracker()->GetFinalStatus(0, 0, &final_status));
133 EXPECT_FALSE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0)); 133 EXPECT_FALSE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0));
134 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 134 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
(...skipping 10 matching lines...) Expand all
145 145
146 // Cancel the prerender. 146 // Cancel the prerender.
147 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 147 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
148 148
149 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0)); 149 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0));
150 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT)); 150 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT));
151 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 151 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
152 0, 0, FINAL_STATUS_TIMED_OUT)); 152 0, 0, FINAL_STATUS_TIMED_OUT));
153 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0)); 153 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0));
154 154
155 // This calls DestroyPreloadForChildRouteIdPair(). 155 // This calls DestroyPrerenderForChildRouteIdPair().
156 RunEvents(); 156 RunEvents();
157 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0)); 157 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0));
158 158
159 // These should all work until the prerendering RenderViewHost is destroyed. 159 // These should all work until the prerendering RenderViewHost is destroyed.
160 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT)); 160 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT));
161 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 161 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
162 0, 0, FINAL_STATUS_TIMED_OUT)); 162 0, 0, FINAL_STATUS_TIMED_OUT));
163 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0)); 163 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0));
164 164
165 prerender_tracker()->OnPrerenderingFinished(0, 0); 165 prerender_tracker()->OnPrerenderingFinished(0, 0);
(...skipping 19 matching lines...) Expand all
185 // Cancel the prerender. 185 // Cancel the prerender.
186 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 186 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
187 0, 0, FINAL_STATUS_TIMED_OUT)); 187 0, 0, FINAL_STATUS_TIMED_OUT));
188 188
189 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0)); 189 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0));
190 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 190 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
191 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 191 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
192 0, 0, FINAL_STATUS_HTTPS)); 192 0, 0, FINAL_STATUS_HTTPS));
193 EXPECT_EQ(FINAL_STATUS_TIMED_OUT, GetCurrentStatus(0, 0)); 193 EXPECT_EQ(FINAL_STATUS_TIMED_OUT, GetCurrentStatus(0, 0));
194 194
195 // This calls DestroyPreloadForChildRouteIdPair(). 195 // This calls DestroyPrerenderForChildRouteIdPair().
196 RunEvents(); 196 RunEvents();
197 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0)); 197 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0));
198 198
199 // These should all work until the prerendering RenderViewHost is destroyed. 199 // These should all work until the prerendering RenderViewHost is destroyed.
200 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 200 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
201 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 201 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
202 0, 0, FINAL_STATUS_HTTPS)); 202 0, 0, FINAL_STATUS_HTTPS));
203 EXPECT_EQ(FINAL_STATUS_TIMED_OUT, GetCurrentStatus(0, 0)); 203 EXPECT_EQ(FINAL_STATUS_TIMED_OUT, GetCurrentStatus(0, 0));
204 204
205 prerender_tracker()->OnPrerenderingFinished(0, 0); 205 prerender_tracker()->OnPrerenderingFinished(0, 0);
(...skipping 11 matching lines...) Expand all
217 // handled correctly. 217 // handled correctly.
218 TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledFast) { 218 TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledFast) {
219 prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager()); 219 prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
220 // Cancel the prerender. 220 // Cancel the prerender.
221 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 221 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
222 222
223 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0)); 223 EXPECT_FALSE(prerender_tracker()->TryUse(0, 0));
224 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT)); 224 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT));
225 225
226 // This calls AddPrerenderOnIOThreadTask() and 226 // This calls AddPrerenderOnIOThreadTask() and
227 // DestroyPreloadForChildRouteIdPair(). 227 // DestroyPrerenderForChildRouteIdPair().
228 RunEvents(); 228 RunEvents();
229 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0)); 229 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(0, 0));
230 230
231 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 231 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
232 0, 0, FINAL_STATUS_TIMED_OUT)); 232 0, 0, FINAL_STATUS_TIMED_OUT));
233 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT)); 233 EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT));
234 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0)); 234 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0));
235 235
236 prerender_tracker()->OnPrerenderingFinished(0, 0); 236 prerender_tracker()->OnPrerenderingFinished(0, 0);
237 237
(...skipping 30 matching lines...) Expand all
268 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread( 268 EXPECT_TRUE(prerender_tracker()->TryCancelOnIOThread(
269 1, 2, FINAL_STATUS_HTTPS)); 269 1, 2, FINAL_STATUS_HTTPS));
270 270
271 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS)); 271 EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
272 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0)); 272 EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0));
273 273
274 EXPECT_FALSE(prerender_tracker()->TryUse(1, 2)); 274 EXPECT_FALSE(prerender_tracker()->TryUse(1, 2));
275 EXPECT_TRUE(prerender_tracker()->TryCancel(1, 2, FINAL_STATUS_HTTPS)); 275 EXPECT_TRUE(prerender_tracker()->TryCancel(1, 2, FINAL_STATUS_HTTPS));
276 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(1, 2)); 276 EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(1, 2));
277 277
278 // This calls DestroyPreloadForChildRouteIdPair(). 278 // This calls DestroyPrerenderForChildRouteIdPair().
279 RunEvents(); 279 RunEvents();
280 EXPECT_FALSE(prerender_manager()->WasPrerenderCancelled(0, 0)); 280 EXPECT_FALSE(prerender_manager()->WasPrerenderCancelled(0, 0));
281 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(1, 2)); 281 EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(1, 2));
282 282
283 prerender_tracker()->OnPrerenderingFinished(0, 0); 283 prerender_tracker()->OnPrerenderingFinished(0, 0);
284 prerender_tracker()->OnPrerenderingFinished(1, 2); 284 prerender_tracker()->OnPrerenderingFinished(1, 2);
285 285
286 // This calls RemovePrerenderOnIOThreadTask(). 286 // This calls RemovePrerenderOnIOThreadTask().
287 RunEvents(); 287 RunEvents();
288 288
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 remove_urls.clear(); 330 remove_urls.clear();
331 remove_urls.push_back(example_url); 331 remove_urls.push_back(example_url);
332 remove_urls.push_back(example_url); 332 remove_urls.push_back(example_url);
333 url_counter.RemoveURLs(remove_urls); 333 url_counter.RemoveURLs(remove_urls);
334 EXPECT_FALSE(url_counter.MatchesURL(example_url)); 334 EXPECT_FALSE(url_counter.MatchesURL(example_url));
335 EXPECT_FALSE(url_counter.MatchesURL(gmail_url)); 335 EXPECT_FALSE(url_counter.MatchesURL(gmail_url));
336 } 336 }
337 337
338 } // namespace prerender 338 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_tracker.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698