chromium/components/offline_pages/core/model/offline_page_model_taskified_unittest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/offline_pages/core/model/offline_page_model_taskified.h"

#include <stdint.h>
#include <memory>
#include <utility>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/time/clock.h"
#include "build/build_config.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/model/clear_storage_task.h"
#include "components/offline_pages/core/model/offline_page_item_generator.h"
#include "components/offline_pages/core/model/offline_page_model_utils.h"
#include "components/offline_pages/core/model/offline_page_test_utils.h"
#include "components/offline_pages/core/model/persistent_page_consistency_check_task.h"
#include "components/offline_pages/core/offline_page_item.h"
#include "components/offline_pages/core/offline_page_metadata_store.h"
#include "components/offline_pages/core/offline_page_metadata_store_test_util.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "components/offline_pages/core/offline_page_test_archive_publisher.h"
#include "components/offline_pages/core/offline_page_test_archiver.h"
#include "components/offline_pages/core/offline_page_types.h"
#include "components/offline_pages/core/offline_store_utils.h"
#include "components/offline_pages/core/test_scoped_offline_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

_;
A;
An;
ElementsAre;
Eq;
IsEmpty;
Pointee;
SaveArg;
UnorderedElementsAre;

namespace offline_pages {

ArchiverResult;
ClearStorageResult;

namespace {

const ClientId kTestClientId1(kDefaultNamespace, "1234");
const ClientId kTestClientId2(kDefaultNamespace, "5678");
const ClientId kTestUserRequestedClientId(kDownloadNamespace, "714");
const ClientId kTestBrowserActionsClientId(kBrowserActionsNamespace, "999");
const ClientId kTestLastNClientId(kLastNNamespace, "8989");
const int64_t kTestFileSize =;
const std::u16string kTestTitle =;
const char kTestRequestOrigin[] =;
const char kEmptyRequestOrigin[] =;
const char kTestDigest[] =;
const int64_t kDownloadId =;

}  // namespace

class OfflinePageModelTaskifiedTest : public testing::Test,
                                      public OfflinePageModel::Observer,
                                      public OfflinePageTestArchiver::Observer {};

OfflinePageModelTaskifiedTest::OfflinePageModelTaskifiedTest()
    :{}

OfflinePageModelTaskifiedTest::~OfflinePageModelTaskifiedTest() = default;

void OfflinePageModelTaskifiedTest::SetUp() {}

void OfflinePageModelTaskifiedTest::TearDown() {}

void OfflinePageModelTaskifiedTest::BuildStore() {}

void OfflinePageModelTaskifiedTest::BuildModel() {}

void OfflinePageModelTaskifiedTest::ResetModel() {}

void OfflinePageModelTaskifiedTest::ResetResults() {}

void OfflinePageModelTaskifiedTest::OfflinePageModelLoaded(
    OfflinePageModel* model) {}

void OfflinePageModelTaskifiedTest::OfflinePageAdded(
    OfflinePageModel* model,
    const OfflinePageItem& added_page) {}

void OfflinePageModelTaskifiedTest::OfflinePageDeleted(
    const OfflinePageItem& item) {}

void OfflinePageModelTaskifiedTest::SetLastPathCreatedByArchiver(
    const base::FilePath& file_path) {}

void OfflinePageModelTaskifiedTest::SavePageWithCallback(
    const GURL& url,
    const ClientId& client_id,
    const GURL& original_url,
    const std::string& request_origin,
    std::unique_ptr<OfflinePageArchiver> archiver,
    SavePageCallback callback) {}

int64_t OfflinePageModelTaskifiedTest::SavePageWithExpectedResult(
    const GURL& url,
    const ClientId& client_id,
    const GURL& original_url,
    const std::string& request_origin,
    std::unique_ptr<OfflinePageArchiver> archiver,
    SavePageResult expected_result) {}

void OfflinePageModelTaskifiedTest::InsertPageIntoStore(
    const OfflinePageItem& offline_page) {}

std::unique_ptr<OfflinePageTestArchiver>
OfflinePageModelTaskifiedTest::BuildArchiver(const GURL& url,
                                             ArchiverResult result) {}

void OfflinePageModelTaskifiedTest::CheckTaskQueueIdle() {}

// Tests saving successfully a non-user-requested offline page.
TEST_F(OfflinePageModelTaskifiedTest, SavePageSuccessful) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageSuccessfulWithSameOriginalUrl) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageSuccessfulWithRequestOrigin) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineArchiverCancelled) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineArchiverDeviceFull) {}

TEST_F(OfflinePageModelTaskifiedTest,
       SavePageOfflineArchiverContentUnavailable) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineCreationFailed) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineArchiverReturnedWrongUrl) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageLocalFileFailed) {}

// This test case is for the scenario that there are two save page requests but
// the first one is slower during archive creation (set_delayed in the test
// case) so the second request will finish first.
// offline_id1 will be id of the first completed request.
// offline_id2 will be id of the second completed request.
TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineArchiverTwoPages) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageOnBackground) {}

TEST_F(OfflinePageModelTaskifiedTest, SavePageWithNullArchiver) {}

TEST_F(OfflinePageModelTaskifiedTest, AddPage) {}

TEST_F(OfflinePageModelTaskifiedTest, MarkPageAccessed) {}

TEST_F(OfflinePageModelTaskifiedTest, GetAllPagesWhenStoreEmpty) {}

// These newly added tests are testing the API instead of results, which
// should be covered in DeletePagesTaskTest.

TEST_F(OfflinePageModelTaskifiedTest, DeletePagesWithCriteria) {}

TEST_F(OfflinePageModelTaskifiedTest, DeletePagesByUrlPredicate) {}

TEST_F(OfflinePageModelTaskifiedTest, GetPageByOfflineId) {}

TEST_F(OfflinePageModelTaskifiedTest, GetPagesWithCriteria_FinalUrl) {}

TEST_F(OfflinePageModelTaskifiedTest,
       GetPagesByUrl_FinalUrlWithFragmentStripped) {}

TEST_F(OfflinePageModelTaskifiedTest, GetPagesWithCriteria_AllUrls) {}

TEST_F(OfflinePageModelTaskifiedTest, CanSaveURL) {}

TEST_F(OfflinePageModelTaskifiedTest, GetOfflineIdsForClientId) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_CheckTempPagesSavedInCorrectDir
#else
#define MAYBE_CheckTempPagesSavedInCorrectDir
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_CheckTempPagesSavedInCorrectDir) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_CheckPersistenPagesSavedInCorrectDir
#else
#define MAYBE_CheckPersistenPagesSavedInCorrectDir
#endif
TEST_F(OfflinePageModelTaskifiedTest,
       MAYBE_CheckPersistenPagesSavedInCorrectDir) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_PublishPageFailure
#else
#define MAYBE_PublishPageFailure
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_PublishPageFailure) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_CheckPublishInternalArchive
#else
#define MAYBE_CheckPublishInternalArchive
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_CheckPublishInternalArchive) {}

TEST_F(OfflinePageModelTaskifiedTest, ExtraActionTriggeredWhenSaveSuccess) {}

TEST_F(OfflinePageModelTaskifiedTest, GetArchiveDirectory) {}

TEST_F(OfflinePageModelTaskifiedTest, GetAllPages) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_StartupMaintenanceTaskExecuted
#else
#define MAYBE_StartupMaintenanceTaskExecuted
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_StartupMaintenanceTaskExecuted) {}

TEST_F(OfflinePageModelTaskifiedTest, ClearStorage) {}

// This test is affected by https://crbug.com/725685, which only affects windows
// platform.
#if BUILDFLAG(IS_WIN)
#define MAYBE_PersistentPageConsistencyCheckExecuted
#else
#define MAYBE_PersistentPageConsistencyCheckExecuted
#endif
TEST_F(OfflinePageModelTaskifiedTest,
       MAYBE_PersistentPageConsistencyCheckExecuted) {}

TEST_F(OfflinePageModelTaskifiedTest, MaintenanceTasksAreDisabled) {}

TEST_F(OfflinePageModelTaskifiedTest, StoreAndCheckThumbnail) {}

TEST_F(OfflinePageModelTaskifiedTest, StoreAndCheckFavicon) {}

}  // namespace offline_pages