chromium/chrome/browser/download/download_history_unittest.cc

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

#include "chrome/browser/download/download_history.h"

#include <stddef.h>
#include <stdint.h>

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/uuid.h"
#include "chrome/test/base/testing_profile.h"
#include "components/download/public/common/download_features.h"
#include "components/download/public/common/download_utils.h"
#include "components/download/public/common/mock_download_item.h"
#include "components/history/content/browser/download_conversions.h"
#include "components/history/core/browser/download_constants.h"
#include "components/history/core/browser/download_row.h"
#include "components/history/core/browser/history_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_utils.h"
#include "extensions/buildflags/buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#endif

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/download/download_item_web_app_data.h"
#endif

_;
DoAll;
Invoke;
NiceMock;
Return;
ReturnRefOfCopy;
SetArgPointee;
WithArg;

namespace {

IdSet;
StrictMockDownloadItem;

enum class LoadDownloadRowResult {};

struct CreateDownloadHistoryEntry {};

class FakeHistoryAdapter : public DownloadHistory::HistoryAdapter {};

class TestDownloadHistoryObserver : public DownloadHistory::Observer {};

class DownloadHistoryTest : public testing::Test {};

// Test loading an item from the database, changing it and removing it.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_LoadWithDownloadDB) {}

// Test that the OnHistoryQueryComplete() observer method is invoked for an
// observer that was added before the initial history query completing.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_OnHistoryQueryComplete_Pre) {}

// Test that the OnHistoryQueryComplete() observer method is invoked for an
// observer that was added after the initial history query completing.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_OnHistoryQueryComplete_Post) {}

// Test creating an completed item, saving it to the database, changing it,
// saving it back, removing it.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_Create) {}

// Test creating a new item, saving it, removing it by setting it Temporary,
// changing it without saving it back because it's Temporary, clearing
// IsTemporary, saving it back, changing it, saving it back because it isn't
// Temporary anymore.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_Temporary) {}

// Test removing downloads while they're still being added.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_RemoveWhileAdding) {}

// Test loading multiple items from the database and removing them all.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_Multiple) {}

// Test what happens when HistoryService/CreateDownload::CreateDownload() fails.
TEST_F(DownloadHistoryTest, DownloadHistoryTest_CreateFailed) {}

TEST_F(DownloadHistoryTest, DownloadHistoryTest_UpdateWhileAdding) {}

// Test creating and updating an completed item.
TEST_F(DownloadHistoryTest, CreateCompletedItem) {}

// Test creating history download item that exists in DownloadDB.
TEST_F(DownloadHistoryTest, CreateHistoryItemInDownloadDB) {}

// Test that new in-progress download will not be added to history.
TEST_F(DownloadHistoryTest, CreateInProgressDownload) {}

// Test that in-progress download already in history will be updated once it
// becomes non-resumable.
TEST_F(DownloadHistoryTest, InProgressHistoryItemBecomesNonResumable) {}

// Test loading history download item that will be cleared by |manager_|
TEST_F(DownloadHistoryTest, RemoveClearedItemFromHistory) {}

// Test that large data URL will be truncated before being inserted into
// history.
TEST_F(DownloadHistoryTest, CreateLargeDataURLCompletedItem) {}

// Tests that overwritten download is removed from history DB after the
// expiration time.
TEST_F(DownloadHistoryTest,
       DownloadHistoryTest_OverwrittenDownloadRemovedAfterExpiration) {}

// Tests that overwritten download is not removed from history DB before the
// expiration time.
TEST_F(DownloadHistoryTest,
       DownloadHistoryTest_OverwrittenDownloadNotRemovedPriorToExpiration) {}

#if !BUILDFLAG(IS_ANDROID)
// Test that web app id is inserted into history.
TEST_F(DownloadHistoryTest, ByWebAppId) {}
#endif

}  // anonymous namespace