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

Unified Diff: components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc

Issue 2928243002: Return operation name in prefetch request callback and add internal page hookup (Closed)
Patch Set: Fix comment indent in JS Created 3 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 side-by-side diff with in-line comments
Download patch
Index: components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc
diff --git a/components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc b/components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc
index cd5994571938b41fe32c3703eda771551a69b840..3df538cf09a5f3cf2c86386eb70241072e12085a 100644
--- a/components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc
+++ b/components/offline_pages/core/prefetch/prefetch_request_operation_response_unittest.cc
@@ -24,6 +24,7 @@ namespace offline_pages {
namespace {
const version_info::Channel kTestChannel = version_info::Channel::UNKNOWN;
+const char kTestOperationName[] = "operation/test123";
const char kTestURL[] = "http://example.com";
const char kTestURL2[] = "http://example.com/2";
const char kTestURL3[] = "http://example.com/3";
@@ -101,6 +102,7 @@ class OperationBuilder {
const std::string& any_type_url,
const std::string& any_value) {
proto::Operation operation;
+ operation.set_name(kTestOperationName);
operation.set_done(is_done);
if (error_code != proto::OK) {
operation.mutable_error()->set_code(error_code);
@@ -234,6 +236,7 @@ class PrefetchRequestOperationResponseTest : public PrefetchRequestTestBase {
builder_.BuildFromAny(kPageBundleTypeURL, bundle_data));
}
+ const std::string& operation_name() const { return operation_name_; }
const std::vector<RenderPageInfo>& pages() const { return pages_; }
private:
@@ -242,14 +245,17 @@ class PrefetchRequestOperationResponseTest : public PrefetchRequestTestBase {
builder_.CreateRequest(request_context(), callback.Get());
PrefetchRequestStatus status;
+ operation_name_.clear();
pages_.clear();
- EXPECT_CALL(callback, Run(_, _))
- .WillOnce(DoAll(SaveArg<0>(&status), SaveArg<1>(&pages_)));
+ EXPECT_CALL(callback, Run(_, _, _))
+ .WillOnce(DoAll(SaveArg<0>(&status), SaveArg<1>(&operation_name_),
+ SaveArg<2>(&pages_)));
RespondWithData(response_data);
return status;
}
T builder_;
+ std::string operation_name_;
std::vector<RenderPageInfo> pages_;
};
@@ -266,24 +272,28 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, EmptyOperation) {
// No error is set for OK. Thus this will cause the operation
// being filled with only done flag.
this->SendWithErrorResponse(proto::OK, ""));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
TYPED_TEST(PrefetchRequestOperationResponseTest, ErrorValue) {
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithErrorResponse(proto::UNKNOWN, kErrorMessage));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
TYPED_TEST(PrefetchRequestOperationResponseTest, InvalidTypeUrl) {
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithAnyResponse("foo", ""));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
TYPED_TEST(PrefetchRequestOperationResponseTest, InvalidValue) {
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithAnyResponse(kPageBundleTypeURL, "foo"));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
@@ -291,6 +301,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, EmptyPageBundle) {
proto::PageBundle bundle;
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
@@ -299,6 +310,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, EmptyArchive) {
bundle.add_archives();
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
@@ -309,6 +321,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, NoPageInfo) {
archive->set_body_length(kTestBodyLength);
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
@@ -319,6 +332,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, MissingPageInfoUrl) {
page_info->set_redirect_url(kTestURL);
EXPECT_EQ(PrefetchRequestStatus::SHOULD_RETRY_WITH_BACKOFF,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_TRUE(this->operation_name().empty());
EXPECT_TRUE(this->pages().empty());
}
@@ -338,6 +352,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, SinglePage) {
1000000);
EXPECT_EQ(PrefetchRequestStatus::SUCCESS,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_EQ(kTestOperationName, this->operation_name());
ASSERT_EQ(1u, this->pages().size());
EXPECT_EQ(kTestURL, this->pages().back().url);
EXPECT_EQ(kTestURL2, this->pages().back().redirect_url);
@@ -383,6 +398,7 @@ TYPED_TEST(PrefetchRequestOperationResponseTest, MultiplePages) {
EXPECT_EQ(PrefetchRequestStatus::SUCCESS,
this->SendWithPageBundleResponse(bundle));
+ EXPECT_EQ(kTestOperationName, this->operation_name());
ASSERT_EQ(4u, this->pages().size());
EXPECT_EQ(kTestURL, this->pages().at(0).url);
EXPECT_EQ(RenderStatus::PENDING, this->pages().at(0).status);

Powered by Google App Engine
This is Rietveld 408576698