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

Unified Diff: chrome/browser/prerender/prerender_tracker_unittest.cc

Issue 11348357: Add observer interface to PrerenderContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prerender/prerender_tracker_unittest.cc
diff --git a/chrome/browser/prerender/prerender_tracker_unittest.cc b/chrome/browser/prerender/prerender_tracker_unittest.cc
index 0fd4b47e09c21e8d0a4d48545e6d9f60c1294e6b..03169a4fed249ae0f0e05f9406a3ee0103782216 100644
--- a/chrome/browser/prerender/prerender_tracker_unittest.cc
+++ b/chrome/browser/prerender/prerender_tracker_unittest.cc
@@ -3,9 +3,11 @@
// found in the LICENSE file.
#include <set>
+#include <utility>
#include "base/logging.h"
#include "base/message_loop.h"
+#include "chrome/browser/prerender/prerender_contents.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/prerender/prerender_tracker.h"
#include "chrome/test/base/testing_browser_process.h"
@@ -18,6 +20,35 @@ namespace prerender {
namespace {
+class TestPrerenderContents : public PrerenderContents {
+ public:
+ TestPrerenderContents(PrerenderManager* prerender_manager,
+ int child_id, int route_id)
+ : PrerenderContents(prerender_manager, NULL, GURL(), content::Referrer(),
mmenke 2012/12/03 20:02:47 Suggest a comment that the NULL is the profile arg
gavinp 2012/12/04 18:04:48 Done, but I used a static_cast<> as the comment.
+ ORIGIN_NONE, PrerenderManager::kNoExperiment),
+ child_id_(child_id),
+ route_id_(route_id) {
+ }
+
+ ~TestPrerenderContents() {
+ set_final_status(FINAL_STATUS_USED);
+ }
+
+ virtual bool GetChildId(int* child_id) const OVERRIDE {
+ *child_id = child_id_;
+ return true;
+ }
+
+ virtual bool GetRouteId(int* route_id) const OVERRIDE {
+ *route_id = route_id_;
+ return true;
+ }
+
+ private:
+ int child_id_;
+ int route_id_;
+};
+
class TestPrerenderManager : public PrerenderManager {
public:
explicit TestPrerenderManager(PrerenderTracker* prerender_tracker) :
@@ -82,6 +113,7 @@ class PrerenderTrackerTest : public testing::Test {
// Check that a non-existant RenderView is handled correctly.
TEST_F(PrerenderTrackerTest, PrerenderTrackerNull) {
FinalStatus final_status;
mmenke 2012/12/03 20:02:47 While you're here, could you move it to just above
gavinp 2012/12/04 18:04:48 Done.
+ TestPrerenderContents test_contents(prerender_manager(), 0, 0);
EXPECT_FALSE(prerender_tracker()->TryUse(0, 0));
EXPECT_FALSE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
EXPECT_FALSE(prerender_tracker()->TryCancelOnIOThread(
@@ -93,7 +125,9 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerNull) {
// Check that a page that is used is handled correctly.
TEST_F(PrerenderTrackerTest, PrerenderTrackerUsed) {
- prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
+ TestPrerenderContents test_contents(prerender_manager(), 0, 0);
mmenke 2012/12/03 20:02:47 optional: Could just toss this in the test framew
gavinp 2012/12/04 18:04:48 Done. I also got rid of all the magic numbers, at
+
+ prerender_tracker()->OnPrerenderStart(&test_contents);
EXPECT_EQ(FINAL_STATUS_MAX, GetCurrentStatus(0, 0));
// This calls AddPrerenderOnIOThreadTask().
@@ -123,7 +157,7 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerUsed) {
EXPECT_EQ(FINAL_STATUS_USED, GetCurrentStatus(0, 0));
// This calls DestroyPrerenderForChildRouteIdPair().
- prerender_tracker()->OnPrerenderingFinished(0, 0);
+ prerender_tracker()->OnPrerenderStop(&test_contents);
EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0));
// This calls RemovePrerenderOnIOThreadTask().
@@ -138,7 +172,9 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerUsed) {
// Check that a prerendered page cancelled by TryCancel() is handled correctly.
TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelled) {
- prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
+ TestPrerenderContents test_contents(prerender_manager(), 0, 0);
+
+ prerender_tracker()->OnPrerenderStart(&test_contents);
EXPECT_EQ(FINAL_STATUS_MAX, GetCurrentStatus(0, 0));
// This calls AddPrerenderOnIOThreadTask().
@@ -163,7 +199,7 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelled) {
0, 0, FINAL_STATUS_TIMED_OUT));
EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0));
- prerender_tracker()->OnPrerenderingFinished(0, 0);
+ prerender_tracker()->OnPrerenderStop(&test_contents);
EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0));
// This calls RemovePrerenderOnIOThreadTask().
@@ -177,7 +213,9 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelled) {
// Check that a prerendered page cancelled on the IO thread by
// TryCancelOnIOThread() is handled correctly.
TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO) {
- prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
+ TestPrerenderContents test_contents(prerender_manager(), 0, 0);
+
+ prerender_tracker()->OnPrerenderStart(&test_contents);
EXPECT_EQ(FINAL_STATUS_MAX, GetCurrentStatus(0, 0));
// This calls AddPrerenderOnIOThreadTask().
@@ -203,7 +241,7 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO) {
0, 0, FINAL_STATUS_HTTPS));
EXPECT_EQ(FINAL_STATUS_TIMED_OUT, GetCurrentStatus(0, 0));
- prerender_tracker()->OnPrerenderingFinished(0, 0);
+ prerender_tracker()->OnPrerenderStop(&test_contents);
EXPECT_TRUE(prerender_tracker()->IsPrerenderingOnIOThread(0, 0));
// This calls RemovePrerenderOnIOThreadTask().
@@ -217,7 +255,10 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledOnIO) {
// Check that a prerendered page cancelled before it reaches the IO thread is
// handled correctly.
TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledFast) {
- prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
+ TestPrerenderContents test_contents(prerender_manager(), 0, 0);
+
+ prerender_tracker()->OnPrerenderStart(&test_contents);
+
// Cancel the prerender.
EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_HTTPS));
@@ -234,7 +275,7 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledFast) {
EXPECT_TRUE(prerender_tracker()->TryCancel(0, 0, FINAL_STATUS_TIMED_OUT));
EXPECT_EQ(FINAL_STATUS_HTTPS, GetCurrentStatus(0, 0));
- prerender_tracker()->OnPrerenderingFinished(0, 0);
+ prerender_tracker()->OnPrerenderStop(&test_contents);
// This calls RemovePrerenderOnIOThreadTask().
RunEvents();
@@ -246,7 +287,8 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerCancelledFast) {
// Check that handling two pages at once works.
TEST_F(PrerenderTrackerTest, PrerenderTrackerMultiple) {
- prerender_tracker()->OnPrerenderingStarted(0, 0, prerender_manager());
+ TestPrerenderContents first_test_contents(prerender_manager(), 0, 0);
+ prerender_tracker()->OnPrerenderStart(&first_test_contents);
// This calls AddPrerenderOnIOThreadTask().
RunEvents();
@@ -256,7 +298,8 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerMultiple) {
EXPECT_FALSE(prerender_tracker()->TryCancel(1, 2, FINAL_STATUS_HTTPS));
// Start second prerender.
- prerender_tracker()->OnPrerenderingStarted(1, 2, prerender_manager());
+ TestPrerenderContents second_test_contents(prerender_manager(), 1, 2);
+ prerender_tracker()->OnPrerenderStart(&second_test_contents);
// This calls AddPrerenderOnIOThreadTask().
RunEvents();
@@ -281,8 +324,8 @@ TEST_F(PrerenderTrackerTest, PrerenderTrackerMultiple) {
EXPECT_FALSE(prerender_manager()->WasPrerenderCancelled(0, 0));
EXPECT_TRUE(prerender_manager()->WasPrerenderCancelled(1, 2));
- prerender_tracker()->OnPrerenderingFinished(0, 0);
- prerender_tracker()->OnPrerenderingFinished(1, 2);
+ prerender_tracker()->OnPrerenderStop(&first_test_contents);
+ prerender_tracker()->OnPrerenderStop(&second_test_contents);
// This calls RemovePrerenderOnIOThreadTask().
RunEvents();

Powered by Google App Engine
This is Rietveld 408576698