#include "chrome/browser/safe_browsing/incident_reporting/last_download_finder.h"
#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/mock_entropy_provider.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/chrome_history_client.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/history/content/browser/content_visit_delegate.h"
#include "components/history/content/browser/download_conversions.h"
#include "components/history/content/browser/history_database_helper.h"
#include "components/history/core/browser/download_constants.h"
#include "components/history/core/browser/download_row.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/download_manager.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
std::unique_ptr<KeyedService> BuildHistoryService(
content::BrowserContext* context) { … }
#if BUILDFLAG(IS_WIN)
static const base::FilePath::CharType kBinaryFileName[] =
FILE_PATH_LITERAL("spam.exe");
static const base::FilePath::CharType kBinaryFileNameForOtherOS[] =
FILE_PATH_LITERAL("spam.dmg");
#elif BUILDFLAG(IS_MAC)
static const base::FilePath::CharType kBinaryFileName[] =
FILE_PATH_LITERAL("spam.dmg");
static const base::FilePath::CharType kBinaryFileNameForOtherOS[] =
FILE_PATH_LITERAL("spam.apk");
#elif BUILDFLAG(IS_ANDROID)
static const base::FilePath::CharType kBinaryFileName[] =
FILE_PATH_LITERAL("spam.apk");
static const base::FilePath::CharType kBinaryFileNameForOtherOS[] =
FILE_PATH_LITERAL("spam.dmg");
#else
static const base::FilePath::CharType kBinaryFileName[] = …);
#endif
static const base::FilePath::CharType kTxtFileName[] = …);
}
namespace safe_browsing {
class LastDownloadFinderTest : public testing::Test { … };
TEST_F(LastDownloadFinderTest, NoProfiles) { … }
TEST_F(LastDownloadFinderTest, NoSafeBrowsingProfile) { … }
TEST_F(LastDownloadFinderTest, NoExtendedReportingProfile) { … }
TEST_F(LastDownloadFinderTest, SimpleEndToEnd) { … }
TEST_F(LastDownloadFinderTest, NonBinaryOnly) { … }
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID)
TEST_F(LastDownloadFinderTest, DownloadForDifferentOs) {
TestingProfile* profile = CreateProfile(SAFE_BROWSING_AND_EXTENDED_REPORTING);
AddDownload(profile,
CreateTestDownloadRow(kBinaryFileNameForOtherOS, profile));
std::unique_ptr<ClientIncidentReport_DownloadDetails> last_binary_download;
std::unique_ptr<ClientIncidentReport_NonBinaryDownloadDetails>
last_non_binary_download;
RunLastDownloadFinder(&last_binary_download, &last_non_binary_download);
EXPECT_FALSE(last_binary_download);
EXPECT_FALSE(last_non_binary_download);
}
#endif
TEST_F(LastDownloadFinderTest, DeleteBeforeResults) { … }
TEST_F(LastDownloadFinderTest, AddProfileAfterStarting) { … }
}