Commit 9d597d7e authored by Markus Heintz's avatar Markus Heintz Committed by Commit Bot

[User Consent] Migrate to consent protos.

Bug: 865902
Change-Id: Iaa2d643eb4cf679511573a6816849db925d346f5
Reviewed-on: https://chromium-review.googlesource.com/1206811
Commit-Queue: Markus Heintz <markusheintz@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589173}
parent 461cbc77
...@@ -44,7 +44,7 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker { ...@@ -44,7 +44,7 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker {
: SingleClientStatusChangeChecker(service), fake_server_(fake_server) { : SingleClientStatusChangeChecker(service), fake_server_(fake_server) {
for (const UserConsentSpecifics& specifics : expected_specifics) { for (const UserConsentSpecifics& specifics : expected_specifics) {
expected_specifics_.insert(std::pair<int64_t, UserConsentSpecifics>( expected_specifics_.insert(std::pair<int64_t, UserConsentSpecifics>(
specifics.confirmation_grd_id(), specifics)); specifics.consent_case(), specifics));
} }
} }
...@@ -65,8 +65,7 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker { ...@@ -65,8 +65,7 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker {
// modify |expected_specifics_|. // modify |expected_specifics_|.
for (const SyncEntity& entity : entities) { for (const SyncEntity& entity : entities) {
UserConsentSpecifics server_specifics = entity.specifics().user_consent(); UserConsentSpecifics server_specifics = entity.specifics().user_consent();
auto iter = auto iter = expected_specifics_.find(server_specifics.consent_case());
expected_specifics_.find(server_specifics.confirmation_grd_id());
EXPECT_TRUE(expected_specifics_.end() != iter); EXPECT_TRUE(expected_specifics_.end() != iter);
if (expected_specifics_.end() == iter) { if (expected_specifics_.end() == iter) {
return false; return false;
...@@ -84,6 +83,9 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker { ...@@ -84,6 +83,9 @@ class UserConsentEqualityChecker : public SingleClientStatusChangeChecker {
private: private:
FakeServer* fake_server_; FakeServer* fake_server_;
// TODO(markusheintz): User a string with the serialized proto instead of an
// int. The requires creating better expectations with a proper creation
// time.
std::multimap<int64_t, UserConsentSpecifics> expected_specifics_; std::multimap<int64_t, UserConsentSpecifics> expected_specifics_;
DISALLOW_COPY_AND_ASSIGN(UserConsentEqualityChecker); DISALLOW_COPY_AND_ASSIGN(UserConsentEqualityChecker);
...@@ -122,7 +124,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientUserConsentsSyncTest, ...@@ -122,7 +124,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientUserConsentsSyncTest,
consent_auditor::ConsentAuditor* consent_service = consent_auditor::ConsentAuditor* consent_service =
ConsentAuditorFactory::GetForProfile(GetProfile(0)); ConsentAuditorFactory::GetForProfile(GetProfile(0));
UserConsentSpecifics specifics; UserConsentSpecifics specifics;
specifics.set_confirmation_grd_id(1); specifics.mutable_sync_consent()->set_confirmation_grd_id(1);
specifics.set_account_id(GetAccountId()); specifics.set_account_id(GetAccountId());
SyncConsent sync_consent; SyncConsent sync_consent;
...@@ -139,7 +141,7 @@ IN_PROC_BROWSER_TEST_F( ...@@ -139,7 +141,7 @@ IN_PROC_BROWSER_TEST_F(
SetSyncUserConsentSeparateTypeFeature(true); SetSyncUserConsentSeparateTypeFeature(true);
UserConsentSpecifics specifics; UserConsentSpecifics specifics;
specifics.set_confirmation_grd_id(1); specifics.mutable_sync_consent()->set_confirmation_grd_id(1);
// Account id may be compared to the synced account, thus, we need them to // Account id may be compared to the synced account, thus, we need them to
// match. // match.
specifics.set_account_id(GetAccountId()); specifics.set_account_id(GetAccountId());
...@@ -193,7 +195,9 @@ IN_PROC_BROWSER_TEST_F(SingleClientUserConsentsSyncTest, ...@@ -193,7 +195,9 @@ IN_PROC_BROWSER_TEST_F(SingleClientUserConsentsSyncTest,
->RecordSyncConsent(GetAccountId(), sync_consent); ->RecordSyncConsent(GetAccountId(), sync_consent);
UserConsentSpecifics specifics; UserConsentSpecifics specifics;
specifics.set_confirmation_grd_id(1); SyncConsent* expected_sync_consent = specifics.mutable_sync_consent();
expected_sync_consent->set_confirmation_grd_id(1);
expected_sync_consent->set_status(UserConsentTypes::GIVEN);
// Account id may be compared to the synced account, thus, we need them to // Account id may be compared to the synced account, thus, we need them to
// match. // match.
specifics.set_account_id(GetAccountId()); specifics.set_account_id(GetAccountId());
......
...@@ -360,13 +360,18 @@ TEST_F(ConsentAuditorImplTest, RecordGaiaConsentAsUserConsent) { ...@@ -360,13 +360,18 @@ TEST_F(ConsentAuditorImplTest, RecordGaiaConsentAsUserConsent) {
EXPECT_EQ(now.since_origin().InMicroseconds(), EXPECT_EQ(now.since_origin().InMicroseconds(),
consent.client_consent_time_usec()); consent.client_consent_time_usec());
EXPECT_EQ(kAccountId, consent.account_id()); EXPECT_EQ(kAccountId, consent.account_id());
EXPECT_EQ(UserConsentSpecifics::CHROME_SYNC, consent.feature());
EXPECT_EQ(3, consent.description_grd_ids_size());
EXPECT_EQ(kDescriptionMessageIds[0], consent.description_grd_ids(0));
EXPECT_EQ(kDescriptionMessageIds[1], consent.description_grd_ids(1));
EXPECT_EQ(kDescriptionMessageIds[2], consent.description_grd_ids(2));
EXPECT_EQ(kConfirmationMessageId, consent.confirmation_grd_id());
EXPECT_EQ(kCurrentAppLocale, consent.locale()); EXPECT_EQ(kCurrentAppLocale, consent.locale());
EXPECT_TRUE(consent.has_sync_consent());
const SyncConsent& actual_sync_consent = consent.sync_consent();
EXPECT_EQ(3, actual_sync_consent.description_grd_ids_size());
EXPECT_EQ(kDescriptionMessageIds[0],
actual_sync_consent.description_grd_ids(0));
EXPECT_EQ(kDescriptionMessageIds[1],
actual_sync_consent.description_grd_ids(1));
EXPECT_EQ(kDescriptionMessageIds[2],
actual_sync_consent.description_grd_ids(2));
EXPECT_EQ(kConfirmationMessageId, actual_sync_consent.confirmation_grd_id());
} }
TEST_F(ConsentAuditorImplTest, RecordArcPlayConsentRevocation) { TEST_F(ConsentAuditorImplTest, RecordArcPlayConsentRevocation) {
...@@ -405,14 +410,22 @@ TEST_F(ConsentAuditorImplTest, RecordArcPlayConsentRevocation) { ...@@ -405,14 +410,22 @@ TEST_F(ConsentAuditorImplTest, RecordArcPlayConsentRevocation) {
UserConsentSpecifics consent = consents[0]; UserConsentSpecifics consent = consents[0];
EXPECT_EQ(kAccountId, consent.account_id()); EXPECT_EQ(kAccountId, consent.account_id());
EXPECT_EQ(UserConsentTypes::NOT_GIVEN, consent.status());
EXPECT_EQ(UserConsentSpecifics::PLAY_STORE, consent.feature());
EXPECT_EQ(3, consent.description_grd_ids_size());
EXPECT_EQ(kDescriptionMessageIds[0], consent.description_grd_ids(0));
EXPECT_EQ(kDescriptionMessageIds[1], consent.description_grd_ids(1));
EXPECT_EQ(kDescriptionMessageIds[2], consent.description_grd_ids(2));
EXPECT_EQ(kConfirmationMessageId, consent.confirmation_grd_id());
EXPECT_EQ(kCurrentAppLocale, consent.locale()); EXPECT_EQ(kCurrentAppLocale, consent.locale());
EXPECT_TRUE(consent.has_arc_play_terms_of_service_consent());
const ArcPlayTermsOfServiceConsent& actual_play_consent =
consent.arc_play_terms_of_service_consent();
EXPECT_EQ(UserConsentTypes::NOT_GIVEN, actual_play_consent.status());
EXPECT_EQ(ArcPlayTermsOfServiceConsent::SETTING_CHANGE,
actual_play_consent.consent_flow());
EXPECT_EQ(3, actual_play_consent.description_grd_ids_size());
EXPECT_EQ(kDescriptionMessageIds[0],
actual_play_consent.description_grd_ids(0));
EXPECT_EQ(kDescriptionMessageIds[1],
actual_play_consent.description_grd_ids(1));
EXPECT_EQ(kDescriptionMessageIds[2],
actual_play_consent.description_grd_ids(2));
EXPECT_EQ(kConfirmationMessageId, actual_play_consent.confirmation_grd_id());
} }
TEST_F(ConsentAuditorImplTest, RecordArcPlayConsent) { TEST_F(ConsentAuditorImplTest, RecordArcPlayConsent) {
...@@ -456,18 +469,20 @@ TEST_F(ConsentAuditorImplTest, RecordArcPlayConsent) { ...@@ -456,18 +469,20 @@ TEST_F(ConsentAuditorImplTest, RecordArcPlayConsent) {
UserConsentSpecifics consent = consents[0]; UserConsentSpecifics consent = consents[0];
EXPECT_EQ(kAccountId, consent.account_id()); EXPECT_EQ(kAccountId, consent.account_id());
EXPECT_EQ(UserConsentSpecifics::PLAY_STORE, consent.feature()); EXPECT_EQ(kCurrentAppLocale, consent.locale());
EXPECT_EQ(6, consent.description_grd_ids_size()); EXPECT_TRUE(consent.has_arc_play_terms_of_service_consent());
EXPECT_EQ(7, consent.description_grd_ids(0)); const ArcPlayTermsOfServiceConsent& actual_play_consent =
EXPECT_EQ(static_cast<int>(0x2fd4e1c6), consent.description_grd_ids(1)); consent.arc_play_terms_of_service_consent();
EXPECT_EQ(static_cast<int>(0x7a2d28fc), consent.description_grd_ids(2));
EXPECT_EQ(static_cast<int>(0xed849ee1), consent.description_grd_ids(3));
EXPECT_EQ(static_cast<int>(0xbb76e739), consent.description_grd_ids(4));
EXPECT_EQ(static_cast<int>(0x1b93eb12), consent.description_grd_ids(5));
EXPECT_EQ(kConfirmationMessageId, consent.confirmation_grd_id()); EXPECT_EQ(7, actual_play_consent.play_terms_of_service_text_length());
EXPECT_EQ(kCurrentAppLocale, consent.locale()); EXPECT_EQ(std::string(play_tos_hash, base::kSHA1Length),
actual_play_consent.play_terms_of_service_hash());
EXPECT_EQ(kConfirmationMessageId, actual_play_consent.confirmation_grd_id());
EXPECT_EQ(ArcPlayTermsOfServiceConsent::SETUP,
actual_play_consent.consent_flow());
EXPECT_EQ(UserConsentTypes::GIVEN, actual_play_consent.status());
} }
TEST_F(ConsentAuditorImplTest, ShouldReturnNoSyncDelegateWhenNoBridge) { TEST_F(ConsentAuditorImplTest, ShouldReturnNoSyncDelegateWhenNoBridge) {
......
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