1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2020 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/browsing_data/browsing_data_history_observer_service.h"
#include <set>
#include <utility>
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/test/base/testing_profile.h"
#include "components/history/core/browser/history_types.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/commerce/shopping_service_factory.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/feature_utils.h"
#include "components/commerce/core/mock_account_checker.h"
#include "components/commerce/core/mock_shopping_service.h"
#endif
class BrowsingDataHistoryObserverServiceTest : public testing::Test {
public:
BrowsingDataHistoryObserverServiceTest() = default;
protected:
content::BrowserTaskEnvironment task_environment_;
base::test::ScopedFeatureList scoped_feature_list_;
};
#if BUILDFLAG(IS_ANDROID)
TEST_F(BrowsingDataHistoryObserverServiceTest,
TimeRangeHistoryWithRestrictions_ClearCommerceDataCalled) {
base::HistogramTester histogram_tester;
std::unique_ptr<TestingProfile> profile =
TestingProfile::Builder()
.AddTestingFactory(
commerce::ShoppingServiceFactory::GetInstance(),
base::BindRepeating([](content::BrowserContext* context) {
std::unique_ptr<KeyedService> service =
commerce::MockShoppingService::Build();
return service;
}))
.Build();
BrowsingDataHistoryObserverService service(profile.get());
// Make sure the feature is enabled.
scoped_feature_list_.InitAndEnableFeature(commerce::kCommerceMerchantViewer);
commerce::MockAccountChecker account_checker;
auto* mock_shopping_service = static_cast<commerce::MockShoppingService*>(
commerce::ShoppingServiceFactory::GetForBrowserContext(profile.get()));
mock_shopping_service->SetAccountChecker(&account_checker);
ASSERT_TRUE(commerce::IsMerchantViewerEnabled(
mock_shopping_service->GetAccountChecker()));
GURL origin_a = GURL("https://a.test");
std::set<GURL> restrict_urls = {origin_a};
base::Time begin = base::Time::Now();
base::Time end = begin + base::Days(1);
history::DeletionInfo deletion_info(
history::DeletionTimeRange(begin, end), false /* is_from_expiration */,
{} /* deleted_rows */, {} /* favicon_urls */,
restrict_urls /* restrict_urls */);
service.OnHistoryDeletions(nullptr /* history_service */, deletion_info);
task_environment_.RunUntilIdle();
histogram_tester.ExpectUniqueSample(
"MerchantViewer.DataManager.DeleteMerchantViewerDataForTimeRange", 0, 1);
}
TEST_F(BrowsingDataHistoryObserverServiceTest,
OriginBasedCommerceDataCleared_EmptyList) {
base::HistogramTester histogram_tester;
std::unique_ptr<TestingProfile> profile =
TestingProfile::Builder()
.AddTestingFactory(
commerce::ShoppingServiceFactory::GetInstance(),
base::BindRepeating([](content::BrowserContext* context) {
std::unique_ptr<KeyedService> service =
commerce::MockShoppingService::Build();
return service;
}))
.Build();
BrowsingDataHistoryObserverService service(profile.get());
// Make sure the feature is enabled.
scoped_feature_list_.InitAndEnableFeature(commerce::kCommerceMerchantViewer);
commerce::MockAccountChecker account_checker;
auto* mock_shopping_service = static_cast<commerce::MockShoppingService*>(
commerce::ShoppingServiceFactory::GetForBrowserContext(profile.get()));
mock_shopping_service->SetAccountChecker(&account_checker);
ASSERT_TRUE(commerce::IsMerchantViewerEnabled(
mock_shopping_service->GetAccountChecker()));
history::OriginCountAndLastVisitMap origin_map;
history::DeletionInfo deletion_info = history::DeletionInfo::ForUrls(
{} /* deleted_rows */, {} /* favicon_urls */);
deletion_info.set_deleted_urls_origin_map(std::move(origin_map));
service.OnHistoryDeletions(nullptr /* history_service */, deletion_info);
task_environment_.RunUntilIdle();
histogram_tester.ExpectUniqueSample(
"MerchantViewer.DataManager.DeleteMerchantViewerDataForOrigins", 0, 1);
}
#endif
|