| Index: components/precache/core/precache_session_tables_unittest.cc
|
| diff --git a/components/precache/core/precache_session_tables_unittest.cc b/components/precache/core/precache_session_tables_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c6cab011004a4149f52b7b808c0dbf89d1c59228
|
| --- /dev/null
|
| +++ b/components/precache/core/precache_session_tables_unittest.cc
|
| @@ -0,0 +1,185 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/precache/core/precache_session_tables.h"
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include <list>
|
| +#include <map>
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/time/time.h"
|
| +#include "sql/connection.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace precache {
|
| +
|
| +namespace {
|
| +
|
| +class PrecacheSessionTablesTest : public testing::Test {
|
| + public:
|
| + PrecacheSessionTablesTest() {}
|
| + ~PrecacheSessionTablesTest() override {}
|
| +
|
| + protected:
|
| + void SetUp() override {
|
| + precache_session_tables_.reset(new PrecacheSessionTables());
|
| + db_.reset(new sql::Connection());
|
| + ASSERT_TRUE(db_->OpenInMemory());
|
| + precache_session_tables_->Init(db_.get());
|
| + }
|
| +
|
| + std::unique_ptr<PrecacheSessionTables> precache_session_tables_;
|
| + std::unique_ptr<sql::Connection> db_;
|
| +};
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreAndGetURLs) {
|
| + std::list<GURL> manifests, manifests2;
|
| + std::list<GURL> resources, resources2;
|
| + manifests.push_back(GURL("http://www.m1.com/"));
|
| + manifests.push_back(GURL("http://www.m2.com/"));
|
| + resources.push_back(GURL("http://www.r1.com/"));
|
| + resources.push_back(GURL("http://www.r2.com/"));
|
| + precache_session_tables_->StoreURLs(manifests, resources);
|
| + precache_session_tables_->GetURLs(&manifests2, &resources2);
|
| + EXPECT_EQ(manifests, manifests2);
|
| + EXPECT_EQ(resources, resources2);
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreAndGetStatistics) {
|
| + int64_t total_response_bytes = 100;
|
| + int64_t network_response_bytes = 50;
|
| + int64_t num_manifest_urls_to_fetch = 2;
|
| + base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
|
| + int64_t total_response_bytes2;
|
| + int64_t network_response_bytes2;
|
| + int64_t num_manifest_urls_to_fetch2;
|
| + base::TimeTicks start_time2;
|
| + precache_session_tables_->StoreStatistics(
|
| + total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
|
| + start_time);
|
| + precache_session_tables_->GetStatistics(
|
| + &total_response_bytes2, &network_response_bytes2,
|
| + &num_manifest_urls_to_fetch2, &start_time2);
|
| + EXPECT_EQ(total_response_bytes, total_response_bytes2);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes2);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes2);
|
| + EXPECT_EQ(start_time, start_time2);
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, GetEmptyURLs) {
|
| + std::list<GURL> manifests;
|
| + std::list<GURL> resources;
|
| + precache_session_tables_->GetURLs(&manifests, &resources);
|
| + EXPECT_TRUE(manifests.empty());
|
| + EXPECT_TRUE(resources.empty());
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, GetEmptyStatistics) {
|
| + int64_t total_response_bytes;
|
| + int64_t network_response_bytes;
|
| + int64_t num_manifest_urls_to_fetch;
|
| + base::TimeTicks start_time;
|
| + precache_session_tables_->GetStatistics(
|
| + &total_response_bytes, &network_response_bytes,
|
| + &num_manifest_urls_to_fetch, &start_time);
|
| + EXPECT_EQ(0, total_response_bytes);
|
| + EXPECT_EQ(0, network_response_bytes);
|
| + EXPECT_EQ(0, network_response_bytes);
|
| + EXPECT_EQ(0, start_time.ToInternalValue());
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreTwiceAndGetURLs) {
|
| + std::list<GURL> manifests, manifests2, manifests3;
|
| + std::list<GURL> resources, resources2, resources3;
|
| + manifests.push_back(GURL("http://www.m1.com/"));
|
| + manifests.push_back(GURL("http://www.m2.com/"));
|
| + resources.push_back(GURL("http://www.r1.com/"));
|
| + resources.push_back(GURL("http://www.r2.com/"));
|
| + manifests2.push_back(GURL("http://www.m3.com/"));
|
| + resources2.push_back(GURL("http://www.r3.com/"));
|
| + precache_session_tables_->StoreURLs(manifests, resources);
|
| + precache_session_tables_->StoreURLs(manifests2, resources2);
|
| + precache_session_tables_->GetURLs(&manifests3, &resources3);
|
| + EXPECT_EQ(manifests2, manifests2);
|
| + EXPECT_EQ(resources2, resources2);
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreTwiceAndGetStatistics) {
|
| + int64_t total_response_bytes = 100;
|
| + int64_t network_response_bytes = 50;
|
| + int64_t num_manifest_urls_to_fetch = 2;
|
| + base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
|
| + int64_t total_response_bytes2 = 101;
|
| + int64_t network_response_bytes2 = 51;
|
| + int64_t num_manifest_urls_to_fetch2 = 3;
|
| + base::TimeTicks start_time2 = base::TimeTicks::FromInternalValue(51);
|
| + int64_t total_response_bytes3;
|
| + int64_t network_response_bytes3;
|
| + int64_t num_manifest_urls_to_fetch3;
|
| + base::TimeTicks start_time3;
|
| + precache_session_tables_->StoreStatistics(
|
| + total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
|
| + start_time);
|
| + precache_session_tables_->StoreStatistics(
|
| + total_response_bytes2, network_response_bytes2,
|
| + num_manifest_urls_to_fetch2, start_time2);
|
| + precache_session_tables_->GetStatistics(
|
| + &total_response_bytes3, &network_response_bytes3,
|
| + &num_manifest_urls_to_fetch3, &start_time3);
|
| + EXPECT_EQ(total_response_bytes2, total_response_bytes3);
|
| + EXPECT_EQ(network_response_bytes2, network_response_bytes3);
|
| + EXPECT_EQ(network_response_bytes2, network_response_bytes3);
|
| + EXPECT_EQ(start_time2, start_time3);
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreAndGetURLsTwice) {
|
| + std::list<GURL> manifests, manifests2, manifests3;
|
| + std::list<GURL> resources, resources2, resources3;
|
| + manifests.push_back(GURL("http://www.m1.com/"));
|
| + manifests.push_back(GURL("http://www.m2.com/"));
|
| + resources.push_back(GURL("http://www.r1.com/"));
|
| + resources.push_back(GURL("http://www.r2.com/"));
|
| + precache_session_tables_->StoreURLs(manifests, resources);
|
| + precache_session_tables_->GetURLs(&manifests2, &resources2);
|
| + precache_session_tables_->GetURLs(&manifests3, &resources3);
|
| + EXPECT_EQ(manifests, manifests2);
|
| + EXPECT_EQ(resources, resources2);
|
| + EXPECT_EQ(manifests, manifests3);
|
| + EXPECT_EQ(resources, resources3);
|
| +}
|
| +
|
| +TEST_F(PrecacheSessionTablesTest, StoreAndGetStatisticsTwice) {
|
| + int64_t total_response_bytes = 100;
|
| + int64_t network_response_bytes = 50;
|
| + int64_t num_manifest_urls_to_fetch = 2;
|
| + base::TimeTicks start_time = base::TimeTicks::FromInternalValue(50);
|
| + int64_t total_response_bytes2, total_response_bytes3;
|
| + int64_t network_response_bytes2, network_response_bytes3;
|
| + int64_t num_manifest_urls_to_fetch2, num_manifest_urls_to_fetch3;
|
| + base::TimeTicks start_time2, start_time3;
|
| + precache_session_tables_->StoreStatistics(
|
| + total_response_bytes, network_response_bytes, num_manifest_urls_to_fetch,
|
| + start_time);
|
| + precache_session_tables_->GetStatistics(
|
| + &total_response_bytes2, &network_response_bytes2,
|
| + &num_manifest_urls_to_fetch2, &start_time2);
|
| + precache_session_tables_->GetStatistics(
|
| + &total_response_bytes3, &network_response_bytes3,
|
| + &num_manifest_urls_to_fetch3, &start_time3);
|
| + EXPECT_EQ(total_response_bytes, total_response_bytes2);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes2);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes2);
|
| + EXPECT_EQ(start_time, start_time2);
|
| + EXPECT_EQ(total_response_bytes, total_response_bytes3);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes3);
|
| + EXPECT_EQ(network_response_bytes, network_response_bytes3);
|
| + EXPECT_EQ(start_time, start_time3);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +} // namespace precache
|
|
|