#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 = …;
}
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() { … }
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) { … }
TEST_F(OfflinePageModelTaskifiedTest, SavePageOfflineArchiverTwoPages) { … }
TEST_F(OfflinePageModelTaskifiedTest, SavePageOnBackground) { … }
TEST_F(OfflinePageModelTaskifiedTest, SavePageWithNullArchiver) { … }
TEST_F(OfflinePageModelTaskifiedTest, AddPage) { … }
TEST_F(OfflinePageModelTaskifiedTest, MarkPageAccessed) { … }
TEST_F(OfflinePageModelTaskifiedTest, GetAllPagesWhenStoreEmpty) { … }
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) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_CheckTempPagesSavedInCorrectDir …
#else
#define MAYBE_CheckTempPagesSavedInCorrectDir …
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_CheckTempPagesSavedInCorrectDir) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_CheckPersistenPagesSavedInCorrectDir …
#else
#define MAYBE_CheckPersistenPagesSavedInCorrectDir …
#endif
TEST_F(OfflinePageModelTaskifiedTest,
MAYBE_CheckPersistenPagesSavedInCorrectDir) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_PublishPageFailure …
#else
#define MAYBE_PublishPageFailure …
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_PublishPageFailure) { … }
#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) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_StartupMaintenanceTaskExecuted …
#else
#define MAYBE_StartupMaintenanceTaskExecuted …
#endif
TEST_F(OfflinePageModelTaskifiedTest, MAYBE_StartupMaintenanceTaskExecuted) { … }
TEST_F(OfflinePageModelTaskifiedTest, ClearStorage) { … }
#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) { … }
}