Commit c7372072 authored by Ian Wells's avatar Ian Wells Committed by Commit Bot

Add test for OfflinePageRequestHandler validating an empty archive file

This fixes a bug causing OfflinePageRequestHandler to segfault when validating
empty archive files and adds a test to ensure empty archives can be validated.

Bug: 913608
Change-Id: I043cbb0c778f9244763197f294c3839f854c71f2
Reviewed-on: https://chromium-review.googlesource.com/c/1370715Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Reviewed-by: default avatarDan H <harringtond@google.com>
Commit-Queue: Ian Wells <iwells@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615618}
parent 09932bf9
......@@ -797,7 +797,8 @@ void OfflinePageRequestHandler::UpdateDigestOnBackground(
void OfflinePageRequestHandler::FinalizeDigestOnBackground(
base::OnceCallback<void(const std::string&)> digest_finalized_callback) {
DCHECK(archive_validator_.get());
if (!archive_validator_)
archive_validator_ = new ThreadSafeArchiveValidator();
// Delegate to background task runner to finalize the hash to get the digest
// since it is time consuming. Once it is done, |digest_finalized_callback|
......
......@@ -2077,6 +2077,26 @@ TYPED_TEST(OfflinePageRequestHandlerTest, LoadOtherPageOnDigestMismatch) {
this->ExpectOfflinePageAccessCount(offline_id2, 0);
}
TYPED_TEST(OfflinePageRequestHandlerTest, EmptyFile) {
this->SimulateHasNetworkConnectivity(false);
const std::string expected_data("");
base::FilePath temp_file_path = this->CreateFileWithContent(expected_data);
ArchiveValidator archive_validator;
const std::string expected_digest = archive_validator.Finish();
int64_t offline_id =
this->SavePublicPage(kUrl, GURL(), temp_file_path, 0, expected_digest);
this->LoadPage(kUrl);
this->ExpectOfflinePageServed(
offline_id, 0,
OfflinePageRequestHandler::AggregatedRequestResult::
SHOW_OFFLINE_ON_DISCONNECTED_NETWORK);
EXPECT_EQ(expected_data, this->data_received());
}
TYPED_TEST(OfflinePageRequestHandlerTest, TinyFile) {
this->SimulateHasNetworkConnectivity(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment