Commit f44c69ed authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

[unity] URL consent helper for personalized URL-keyed data collection.

This CL adds the consent API that allows the various browser services to
check whether the user has consented for personalized URL-keyed data
collection (data collection that is keyed by URL and by Google account id).
As defined in the PRD, this decision is based on the sync state:
* If the Unified consent feature is disabled, then we consider that the
user has granted consent for personalized URL-keyed data collection iff sync
history is enabled.
* If the Unified consent feature is enabled, then we consider that the
user has granted consent for personalized URL-keyed data collection iff sync
user events is enabled (aka event logger is enabled).

BUG: 823809
Change-Id: Idf619b96010064020f36efbd90d54b720b45deec
Reviewed-on: https://chromium-review.googlesource.com/1123827
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572564}
parent 73c19013
...@@ -9,8 +9,8 @@ static_library("unified_consent") { ...@@ -9,8 +9,8 @@ static_library("unified_consent") {
"unified_consent_service.cc", "unified_consent_service.cc",
"unified_consent_service.h", "unified_consent_service.h",
"unified_consent_service_client.h", "unified_consent_service_client.h",
"url_keyed_anonymized_data_collection_consent_helper.cc", "url_keyed_data_collection_consent_helper.cc",
"url_keyed_anonymized_data_collection_consent_helper.h", "url_keyed_data_collection_consent_helper.h",
] ]
deps = [ deps = [
"//base", "//base",
...@@ -27,7 +27,7 @@ source_set("unit_tests") { ...@@ -27,7 +27,7 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"unified_consent_service_unittest.cc", "unified_consent_service_unittest.cc",
"url_keyed_anonymized_data_collection_consent_helper_unittest.cc", "url_keyed_data_collection_consent_helper_unittest.cc",
] ]
deps = [ deps = [
":unified_consent", ":unified_consent",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/unified_consent/url_keyed_anonymized_data_collection_consent_helper.h"
#include <vector>
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/unified_consent/pref_names.h"
#include "components/unified_consent/unified_consent_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace unified_consent {
namespace {
class UrlKeyedDataCollectionConsentHelperTest
: public testing::Test,
public UrlKeyedAnonymizedDataCollectionConsentHelper::Observer {
public:
// testing::Test:
void SetUp() override {
UnifiedConsentService::RegisterPrefs(pref_service_.registry());
}
void OnUrlKeyedDataCollectionConsentStateChanged(bool enabled) override {
state_changed_notifications.push_back(enabled);
}
protected:
sync_preferences::TestingPrefServiceSyncable pref_service_;
std::vector<bool> state_changed_notifications;
syncer::FakeSyncService sync_service_;
};
TEST_F(UrlKeyedDataCollectionConsentHelperTest, UnifiedConsentEnabled) {
std::unique_ptr<UrlKeyedAnonymizedDataCollectionConsentHelper> helper =
UrlKeyedAnonymizedDataCollectionConsentHelper::NewInstance(
true, &pref_service_, &sync_service_);
helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications.empty());
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
true);
EXPECT_TRUE(helper->IsEnabled());
EXPECT_EQ(1U, state_changed_notifications.size());
EXPECT_TRUE(state_changed_notifications[0]);
state_changed_notifications.clear();
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_EQ(1U, state_changed_notifications.size());
EXPECT_FALSE(state_changed_notifications[0]);
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest, UnifiedConsentDisabled) {
std::unique_ptr<UrlKeyedAnonymizedDataCollectionConsentHelper> helper =
UrlKeyedAnonymizedDataCollectionConsentHelper::NewInstance(
false, &pref_service_, &sync_service_);
EXPECT_FALSE(helper->IsEnabled());
}
} // namespace
} // namespace unified_consent
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/unified_consent/url_keyed_anonymized_data_collection_consent_helper.h" #include "components/unified_consent/url_keyed_data_collection_consent_helper.h"
#include "base/bind.h" #include "base/bind.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
...@@ -18,13 +18,13 @@ namespace unified_consent { ...@@ -18,13 +18,13 @@ namespace unified_consent {
namespace { namespace {
class PrefBasedUrlKeyedDataCollectionConsentHelper class PrefBasedUrlKeyedDataCollectionConsentHelper
: public UrlKeyedAnonymizedDataCollectionConsentHelper { : public UrlKeyedDataCollectionConsentHelper {
public: public:
explicit PrefBasedUrlKeyedDataCollectionConsentHelper( explicit PrefBasedUrlKeyedDataCollectionConsentHelper(
PrefService* pref_service); PrefService* pref_service);
~PrefBasedUrlKeyedDataCollectionConsentHelper() override = default; ~PrefBasedUrlKeyedDataCollectionConsentHelper() override = default;
// UrlKeyedAnonymizedDataCollectionConsentHelper: // UrlKeyedDataCollectionConsentHelper:
bool IsEnabled() override; bool IsEnabled() override;
private: private:
...@@ -36,14 +36,15 @@ class PrefBasedUrlKeyedDataCollectionConsentHelper ...@@ -36,14 +36,15 @@ class PrefBasedUrlKeyedDataCollectionConsentHelper
}; };
class SyncBasedUrlKeyedDataCollectionConsentHelper class SyncBasedUrlKeyedDataCollectionConsentHelper
: public UrlKeyedAnonymizedDataCollectionConsentHelper, : public UrlKeyedDataCollectionConsentHelper,
syncer::SyncServiceObserver { syncer::SyncServiceObserver {
public: public:
explicit SyncBasedUrlKeyedDataCollectionConsentHelper( SyncBasedUrlKeyedDataCollectionConsentHelper(
syncer::SyncService* sync_service); syncer::SyncService* sync_service,
syncer::ModelType sync_data_type);
~SyncBasedUrlKeyedDataCollectionConsentHelper() override; ~SyncBasedUrlKeyedDataCollectionConsentHelper() override;
// UrlKeyedAnonymizedDataCollectionConsentHelper: // UrlKeyedDataCollectionConsentHelper:
bool IsEnabled() override; bool IsEnabled() override;
// syncer::SyncServiceObserver: // syncer::SyncServiceObserver:
...@@ -52,7 +53,8 @@ class SyncBasedUrlKeyedDataCollectionConsentHelper ...@@ -52,7 +53,8 @@ class SyncBasedUrlKeyedDataCollectionConsentHelper
private: private:
syncer::SyncService* sync_service_; syncer::SyncService* sync_service_;
syncer::UploadState sync_history_upload_state_; syncer::ModelType sync_data_type_;
syncer::UploadState sync_data_type_upload_state_;
DISALLOW_COPY_AND_ASSIGN(SyncBasedUrlKeyedDataCollectionConsentHelper); DISALLOW_COPY_AND_ASSIGN(SyncBasedUrlKeyedDataCollectionConsentHelper);
}; };
...@@ -79,11 +81,12 @@ void PrefBasedUrlKeyedDataCollectionConsentHelper::OnPrefChanged() { ...@@ -79,11 +81,12 @@ void PrefBasedUrlKeyedDataCollectionConsentHelper::OnPrefChanged() {
SyncBasedUrlKeyedDataCollectionConsentHelper:: SyncBasedUrlKeyedDataCollectionConsentHelper::
SyncBasedUrlKeyedDataCollectionConsentHelper( SyncBasedUrlKeyedDataCollectionConsentHelper(
syncer::SyncService* sync_service) syncer::SyncService* sync_service,
syncer::ModelType sync_data_type)
: sync_service_(sync_service), : sync_service_(sync_service),
sync_history_upload_state_(syncer::GetUploadToGoogleState( sync_data_type_(sync_data_type),
sync_service_, sync_data_type_upload_state_(
syncer::ModelType::HISTORY_DELETE_DIRECTIVES)) { syncer::GetUploadToGoogleState(sync_service_, sync_data_type_)) {
DCHECK(sync_service_); DCHECK(sync_service_);
sync_service_->AddObserver(this); sync_service_->AddObserver(this);
} }
...@@ -95,15 +98,15 @@ SyncBasedUrlKeyedDataCollectionConsentHelper:: ...@@ -95,15 +98,15 @@ SyncBasedUrlKeyedDataCollectionConsentHelper::
} }
bool SyncBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() { bool SyncBasedUrlKeyedDataCollectionConsentHelper::IsEnabled() {
return sync_history_upload_state_ == syncer::UploadState::ACTIVE; return sync_data_type_upload_state_ == syncer::UploadState::ACTIVE;
} }
void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged( void SyncBasedUrlKeyedDataCollectionConsentHelper::OnStateChanged(
syncer::SyncService* sync_service) { syncer::SyncService* sync_service) {
DCHECK_EQ(sync_service_, sync_service); DCHECK_EQ(sync_service_, sync_service);
bool enabled_before_state_updated = IsEnabled(); bool enabled_before_state_updated = IsEnabled();
sync_history_upload_state_ = syncer::GetUploadToGoogleState( sync_data_type_upload_state_ =
sync_service_, syncer::ModelType::HISTORY_DELETE_DIRECTIVES); syncer::GetUploadToGoogleState(sync_service_, sync_data_type_);
if (enabled_before_state_updated != IsEnabled()) if (enabled_before_state_updated != IsEnabled())
FireOnStateChanged(); FireOnStateChanged();
...@@ -118,13 +121,14 @@ void SyncBasedUrlKeyedDataCollectionConsentHelper::OnSyncShutdown( ...@@ -118,13 +121,14 @@ void SyncBasedUrlKeyedDataCollectionConsentHelper::OnSyncShutdown(
} // namespace } // namespace
UrlKeyedAnonymizedDataCollectionConsentHelper:: UrlKeyedDataCollectionConsentHelper::UrlKeyedDataCollectionConsentHelper() =
UrlKeyedAnonymizedDataCollectionConsentHelper() = default; default;
UrlKeyedAnonymizedDataCollectionConsentHelper:: UrlKeyedDataCollectionConsentHelper::~UrlKeyedDataCollectionConsentHelper() =
~UrlKeyedAnonymizedDataCollectionConsentHelper() = default; default;
std::unique_ptr<UrlKeyedAnonymizedDataCollectionConsentHelper> // static
UrlKeyedAnonymizedDataCollectionConsentHelper::NewInstance( std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
UrlKeyedDataCollectionConsentHelper::NewAnonymizedDataCollectionConsentHelper(
bool is_unified_consent_enabled, bool is_unified_consent_enabled,
PrefService* pref_service, PrefService* pref_service,
syncer::SyncService* sync_service) { syncer::SyncService* sync_service) {
...@@ -134,22 +138,31 @@ UrlKeyedAnonymizedDataCollectionConsentHelper::NewInstance( ...@@ -134,22 +138,31 @@ UrlKeyedAnonymizedDataCollectionConsentHelper::NewInstance(
} }
return std::make_unique<SyncBasedUrlKeyedDataCollectionConsentHelper>( return std::make_unique<SyncBasedUrlKeyedDataCollectionConsentHelper>(
sync_service); sync_service, syncer::ModelType::HISTORY_DELETE_DIRECTIVES);
} }
void UrlKeyedAnonymizedDataCollectionConsentHelper::AddObserver( // static
Observer* observer) { std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
UrlKeyedDataCollectionConsentHelper::NewPersonalizedDataCollectionConsentHelper(
bool is_unified_consent_enabled,
syncer::SyncService* sync_service) {
syncer::ModelType sync_type =
is_unified_consent_enabled ? syncer::ModelType::USER_EVENTS
: syncer::ModelType::HISTORY_DELETE_DIRECTIVES;
return std::make_unique<SyncBasedUrlKeyedDataCollectionConsentHelper>(
sync_service, sync_type);
}
void UrlKeyedDataCollectionConsentHelper::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer); observer_list_.AddObserver(observer);
} }
void UrlKeyedAnonymizedDataCollectionConsentHelper::RemoveObserver( void UrlKeyedDataCollectionConsentHelper::RemoveObserver(Observer* observer) {
Observer* observer) {
observer_list_.RemoveObserver(observer); observer_list_.RemoveObserver(observer);
} }
void UrlKeyedAnonymizedDataCollectionConsentHelper::FireOnStateChanged() { void UrlKeyedDataCollectionConsentHelper::FireOnStateChanged() {
bool is_enabled = IsEnabled();
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnUrlKeyedDataCollectionConsentStateChanged(is_enabled); observer.OnUrlKeyedDataCollectionConsentStateChanged(this);
} }
} // namespace unified_consent } // namespace unified_consent
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_UNIFIED_CONSENT_URL_KEYED_ANONYMIZED_DATA_COLLECTION_CONSENT_HELPER_H_ #ifndef COMPONENTS_UNIFIED_CONSENT_URL_KEYED_DATA_COLLECTION_CONSENT_HELPER_H_
#define COMPONENTS_UNIFIED_CONSENT_URL_KEYED_ANONYMIZED_DATA_COLLECTION_CONSENT_HELPER_H_ #define COMPONENTS_UNIFIED_CONSENT_URL_KEYED_DATA_COLLECTION_CONSENT_HELPER_H_
#include <memory> #include <memory>
...@@ -17,18 +17,22 @@ class SyncService; ...@@ -17,18 +17,22 @@ class SyncService;
namespace unified_consent { namespace unified_consent {
// Helper class that allows clients to check whether the user has consented // Helper class that allows clients to check whether the user has consented
// for URL-keyed anonymized data collection. // for URL-keyed data collection.
class UrlKeyedAnonymizedDataCollectionConsentHelper { class UrlKeyedDataCollectionConsentHelper {
public: public:
class Observer { class Observer {
public: public:
// Called when the state of the URL-keyed anonymized data collection // Called when the state of the URL-keyed data collection changes.
// changes. virtual void OnUrlKeyedDataCollectionConsentStateChanged(
virtual void OnUrlKeyedDataCollectionConsentStateChanged(bool enabled) = 0; UrlKeyedDataCollectionConsentHelper* consent_helper) = 0;
}; };
// Creates a new |UrlKeyedAnonymizedDataCollectionConsentHelper| instance. We // Creates a new |UrlKeyedDataCollectionConsentHelper| instance that checks
// distinguish the following cases: // whether *anonymized* data collection is enabled. This should be used when
// the client needs to check whether the user has granted consent for
// *anonymized* URL-keyed data collection.
//
// Implementation-wise we distinguish the following cases:
// 1. If |is_unified_consent_enabled| true, then the instance is backed by // 1. If |is_unified_consent_enabled| true, then the instance is backed by
// |pref_service|. Url-keyed data collection is enabled if the preference // |pref_service|. Url-keyed data collection is enabled if the preference
// |prefs::kUrlKeyedAnonymizedDataCollectionEnabled| is set to true. // |prefs::kUrlKeyedAnonymizedDataCollectionEnabled| is set to true.
...@@ -38,12 +42,26 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper { ...@@ -38,12 +42,26 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper {
// and if sync history is enabled. // and if sync history is enabled.
// //
// Note: |pref_service| must outlive the retuned instance. // Note: |pref_service| must outlive the retuned instance.
static std::unique_ptr<UrlKeyedAnonymizedDataCollectionConsentHelper> static std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
NewInstance(bool is_unified_consent_enabled, NewAnonymizedDataCollectionConsentHelper(bool is_unified_consent_enabled,
PrefService* pref_service, PrefService* pref_service,
syncer::SyncService* sync_service); syncer::SyncService* sync_service);
// Creates a new |UrlKeyedDataCollectionConsentHelper| instance that checks
// whether *personalized* data collection is enabled. This should be used when
// the client needs to check whether the user has granted consent for
// URL-keyed data collection keyed by their Google account.
//
// Implementation-wise we distinguish the following cases:
// 1. If |is_unified_consent_enabled| is true then URL-keyed data collection
// is enabled if sync is active and if sync event logger is enabled.
// 2. If |is_unified_consent_enabled| is false then URL-keyed data collection
// is enabled if sync is active and if sync history is enabled.
static std::unique_ptr<UrlKeyedDataCollectionConsentHelper>
NewPersonalizedDataCollectionConsentHelper(bool is_unified_consent_enabled,
syncer::SyncService* sync_service);
virtual ~UrlKeyedAnonymizedDataCollectionConsentHelper(); virtual ~UrlKeyedDataCollectionConsentHelper();
// Returns true if the user has consented for URL keyed anonymized data // Returns true if the user has consented for URL keyed anonymized data
// collection. // collection.
...@@ -54,7 +72,7 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper { ...@@ -54,7 +72,7 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper {
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
protected: protected:
UrlKeyedAnonymizedDataCollectionConsentHelper(); UrlKeyedDataCollectionConsentHelper();
// Fires |OnUrlKeyedDataCollectionConsentStateChanged| on all the observers. // Fires |OnUrlKeyedDataCollectionConsentStateChanged| on all the observers.
void FireOnStateChanged(); void FireOnStateChanged();
...@@ -62,9 +80,9 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper { ...@@ -62,9 +80,9 @@ class UrlKeyedAnonymizedDataCollectionConsentHelper {
private: private:
base::ObserverList<Observer, true> observer_list_; base::ObserverList<Observer, true> observer_list_;
DISALLOW_COPY_AND_ASSIGN(UrlKeyedAnonymizedDataCollectionConsentHelper); DISALLOW_COPY_AND_ASSIGN(UrlKeyedDataCollectionConsentHelper);
}; };
} // namespace unified_consent } // namespace unified_consent
#endif // COMPONENTS_UNIFIED_CONSENT_URL_KEYED_ANONYMIZED_DATA_COLLECTION_CONSENT_HELPER_H_ #endif // COMPONENTS_UNIFIED_CONSENT_URL_KEYED_DATA_COLLECTION_CONSENT_HELPER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/unified_consent/url_keyed_data_collection_consent_helper.h"
#include <vector>
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/engine/cycle/sync_cycle_snapshot.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/unified_consent/pref_names.h"
#include "components/unified_consent/unified_consent_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace unified_consent {
namespace {
class TestSyncService : public syncer::FakeSyncService {
public:
void set_sync_initialized(bool sync_initialized) {
sync_initialized_ = sync_initialized;
}
void set_sync_active_data_type(syncer::ModelType type) {
sync_active_data_type_ = type;
}
void FireOnStateChangeOnAllObservers() {
for (auto& observer : observers_)
observer.OnStateChanged(this);
}
// syncer::FakeSyncService:
bool IsSyncAllowed() const override { return true; }
bool CanSyncStart() const override { return true; }
syncer::ModelTypeSet GetPreferredDataTypes() const override {
return syncer::ModelTypeSet(syncer::ModelType::HISTORY_DELETE_DIRECTIVES,
syncer::ModelType::USER_EVENTS);
}
bool IsSyncActive() const override { return true; }
bool ConfigurationDone() const override { return true; }
syncer::SyncCycleSnapshot GetLastCycleSnapshot() const override {
if (!sync_initialized_)
return syncer::SyncCycleSnapshot();
return syncer::SyncCycleSnapshot(
syncer::ModelNeutralState(), syncer::ProgressMarkerMap(), false, 5, 2,
7, false, 0, base::Time::Now(), base::Time::Now(),
std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
std::vector<int>(syncer::MODEL_TYPE_COUNT, 0),
sync_pb::SyncEnums::UNKNOWN_ORIGIN,
/*short_poll_interval=*/base::TimeDelta::FromMinutes(30),
/*long_poll_interval=*/base::TimeDelta::FromMinutes(180),
/*has_remaining_local_changes=*/false);
}
syncer::ModelTypeSet GetActiveDataTypes() const override {
if (sync_active_data_type_ != syncer::ModelType::UNSPECIFIED) {
return syncer::ModelTypeSet(sync_active_data_type_);
}
return syncer::ModelTypeSet();
}
void AddObserver(syncer::SyncServiceObserver* observer) override {
observers_.AddObserver(observer);
}
void RemoveObserver(syncer::SyncServiceObserver* observer) override {
observers_.RemoveObserver(observer);
}
private:
bool sync_initialized_ = false;
syncer::ModelType sync_active_data_type_ = syncer::ModelType::UNSPECIFIED;
base::ObserverList<syncer::SyncServiceObserver> observers_;
};
class UrlKeyedDataCollectionConsentHelperTest
: public testing::Test,
public UrlKeyedDataCollectionConsentHelper::Observer {
public:
// testing::Test:
void SetUp() override {
UnifiedConsentService::RegisterPrefs(pref_service_.registry());
}
void OnUrlKeyedDataCollectionConsentStateChanged(
UrlKeyedDataCollectionConsentHelper* consent_helper) override {
state_changed_notifications.push_back(consent_helper->IsEnabled());
}
protected:
sync_preferences::TestingPrefServiceSyncable pref_service_;
std::vector<bool> state_changed_notifications;
TestSyncService sync_service_;
};
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
AnonymizedDataCollection_UnifiedConsentEnabled) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewAnonymizedDataCollectionConsentHelper(true, &pref_service_,
&sync_service_);
helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications.empty());
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
true);
EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications.size());
EXPECT_TRUE(state_changed_notifications[0]);
state_changed_notifications.clear();
pref_service_.SetBoolean(prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
false);
EXPECT_FALSE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications.size());
EXPECT_FALSE(state_changed_notifications[0]);
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
AnonymizedDataCollection_UnifiedConsentDisabled) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewAnonymizedDataCollectionConsentHelper(false, &pref_service_,
&sync_service_);
helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type(
syncer::ModelType::HISTORY_DELETE_DIRECTIVES);
sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizeddDataCollection_UnifiedConsentEnabled) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper(true, &sync_service_);
helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type(syncer::ModelType::USER_EVENTS);
sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this);
}
TEST_F(UrlKeyedDataCollectionConsentHelperTest,
PersonalizedDataCollection_UnifiedConsentDisabled) {
std::unique_ptr<UrlKeyedDataCollectionConsentHelper> helper =
UrlKeyedDataCollectionConsentHelper::
NewPersonalizedDataCollectionConsentHelper(false, &sync_service_);
helper->AddObserver(this);
EXPECT_FALSE(helper->IsEnabled());
EXPECT_TRUE(state_changed_notifications.empty());
sync_service_.set_sync_initialized(true);
sync_service_.set_sync_active_data_type(
syncer::ModelType::HISTORY_DELETE_DIRECTIVES);
sync_service_.FireOnStateChangeOnAllObservers();
EXPECT_TRUE(helper->IsEnabled());
ASSERT_EQ(1U, state_changed_notifications.size());
helper->RemoveObserver(this);
}
} // namespace
} // namespace unified_consent
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment