Commit 38ac6d5e authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

Associate VariationIDs with the two new IDCollectionKeys.

The keys are GOOGLE_WEB_PROPERTIES_FIRST_PARTY and
GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY.

The new keys will be used to limit the set of experiment IDs included in
X-Client-Data headers sent in third-party contexts when the
RestrictGoogleWebVisibility feature is enabled. Note that the feature is
disabled by default.

Also, update relevant code to consider IDs associated with the new
FIRST_PARTY groups. To do this, GetVariationsVector() and
GetVariationsString() were changed to accept collections of
IDCollectionKeys.

Bug: 1094303
Change-Id: If931d8281f5a687548427101e07f3b3075cd349b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367989Reviewed-by: default avatarDan H <harringtond@chromium.org>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Cr-Commit-Position: refs/heads/master@{#806803}
parent e1affefa
...@@ -50,8 +50,10 @@ std::set<variations::VariationID> GetSnippetsExperiments() { ...@@ -50,8 +50,10 @@ std::set<variations::VariationID> GetSnippetsExperiments() {
for (variations::IDCollectionKey key : for (variations::IDCollectionKey key :
{variations::GOOGLE_WEB_PROPERTIES_ANY_CONTEXT, {variations::GOOGLE_WEB_PROPERTIES_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_FIRST_PARTY,
variations::GOOGLE_WEB_PROPERTIES_SIGNED_IN, variations::GOOGLE_WEB_PROPERTIES_SIGNED_IN,
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT}) { variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY}) {
const variations::VariationID id = variations::GetGoogleVariationID( const variations::VariationID id = variations::GetGoogleVariationID(
key, trial->trial_name(), trial->group_name()); key, trial->trial_name(), trial->group_name());
if (id != variations::EMPTY_ID) { if (id != variations::EMPTY_ID) {
......
...@@ -1062,7 +1062,8 @@ void AutofillDownloadManager::InitActiveExperiments() { ...@@ -1062,7 +1062,8 @@ void AutofillDownloadManager::InitActiveExperiments() {
delete active_experiments_; delete active_experiments_;
active_experiments_ = new std::vector<variations::VariationID>( active_experiments_ = new std::vector<variations::VariationID>(
variations_ids_provider->GetVariationsVector( variations_ids_provider->GetVariationsVector(
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT)); {variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY}));
base::EraseIf(*active_experiments_, [](variations::VariationID id) { base::EraseIf(*active_experiments_, [](variations::VariationID id) {
return !IsAutofillExperimentId(id); return !IsAutofillExperimentId(id);
}); });
......
...@@ -64,9 +64,10 @@ enum IDCollectionKey { ...@@ -64,9 +64,10 @@ enum IDCollectionKey {
// transmitted via the X-Client-Data header. These IDs are transmitted in // transmitted via the X-Client-Data header. These IDs are transmitted in
// first- and third-party contexts. // first- and third-party contexts.
GOOGLE_WEB_PROPERTIES_ANY_CONTEXT, GOOGLE_WEB_PROPERTIES_ANY_CONTEXT,
// Used when kRestrictGoogleWebVisibility is enabled. The IDs in this // The IDs in this collection are used by Google web properties and are
// collection are used by Google web properties and are transmitted via the // transmitted via the X-Client-Data header. When kRestrictGoogleWebVisibility
// X-Client-Data header. These IDs are transmitted in first-party contexts. // is enabled, these IDs are transmitted in only first-party contexts;
// otherwise, these IDs are transmitted in first- and third-party contexts.
GOOGLE_WEB_PROPERTIES_FIRST_PARTY, GOOGLE_WEB_PROPERTIES_FIRST_PARTY,
// This collection is used by Google web properties for signed in users only, // This collection is used by Google web properties for signed in users only,
// transmitted through the X-Client-Data header. // transmitted through the X-Client-Data header.
...@@ -75,10 +76,11 @@ enum IDCollectionKey { ...@@ -75,10 +76,11 @@ enum IDCollectionKey {
// server-side experimental behavior and are transmitted via the X-Client-Data // server-side experimental behavior and are transmitted via the X-Client-Data
// header. These IDs are transmitted in first- and third-party contexts. // header. These IDs are transmitted in first- and third-party contexts.
GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT, GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT,
// Used when kRestrictGoogleWebVisibility is enabled. The IDs in this // The IDs in this collection are used by Google web properties to trigger
// collection are used by Google web properties to trigger server-side // server-side experimental behavior and are transmitted via the X-Client-Data
// experimental behavior and are transmitted via the X-Client-Data header. // header. When kRestrictGoogleWebVisibility is enabled, these IDs are
// These IDs are transmitted in first-party contexts. // transmitted in only first-party contexts; otherwise, these IDs are
// transmitted in first- and third-party contexts.
GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY, GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY,
// This collection is used by the Google App and is passed at the time // This collection is used by the Google App and is passed at the time
// the cross-app communication is triggered. // the cross-app communication is triggered.
......
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm> #include <algorithm>
#include <set>
#include <string>
#include <vector>
#include "base/base64.h" #include "base/base64.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
...@@ -55,44 +52,44 @@ std::string VariationsIdsProvider::GetClientDataHeader(bool is_signed_in) { ...@@ -55,44 +52,44 @@ std::string VariationsIdsProvider::GetClientDataHeader(bool is_signed_in) {
return variation_ids_header_copy; return variation_ids_header_copy;
} }
std::string VariationsIdsProvider::GetVariationsString(IDCollectionKey key) { std::string VariationsIdsProvider::GetVariationsString(
InitVariationIDsCacheIfNeeded(); const std::set<IDCollectionKey>& keys) {
// Construct a space-separated string with leading and trailing spaces from // Construct a space-separated string with leading and trailing spaces from
// the variations set. Note: The ids in it will be in sorted order per the // the VariationIDs set. The IDs in the string are in sorted order as per the
// std::set contract. // std::set contract.
std::string ids_string = " "; std::string ids_string = " ";
{
base::AutoLock scoped_lock(lock_); for (const VariationID& id : GetVariationsVector(keys)) {
for (const VariationIDEntry& entry : GetAllVariationIds()) { ids_string.append(base::NumberToString(id));
if (entry.second == key) { ids_string.push_back(' ');
ids_string.append(base::NumberToString(entry.first));
ids_string.push_back(' ');
}
}
} }
return ids_string; return ids_string;
} }
std::string VariationsIdsProvider::GetGoogleAppVariationsString() { std::string VariationsIdsProvider::GetGoogleAppVariationsString() {
return GetVariationsString(GOOGLE_APP); return GetVariationsString({GOOGLE_APP});
} }
std::string VariationsIdsProvider::GetVariationsString() { std::string VariationsIdsProvider::GetVariationsString() {
return GetVariationsString(GOOGLE_WEB_PROPERTIES_ANY_CONTEXT); return GetVariationsString(
{GOOGLE_WEB_PROPERTIES_ANY_CONTEXT, GOOGLE_WEB_PROPERTIES_FIRST_PARTY});
} }
std::vector<VariationID> VariationsIdsProvider::GetVariationsVector( std::vector<VariationID> VariationsIdsProvider::GetVariationsVector(
IDCollectionKey key) { const std::set<IDCollectionKey>& keys) {
return GetVariationsVectorImpl(std::set<IDCollectionKey>{key}); return GetVariationsVectorImpl(keys);
} }
std::vector<VariationID> std::vector<VariationID>
VariationsIdsProvider::GetVariationsVectorForWebPropertiesKeys() { VariationsIdsProvider::GetVariationsVectorForWebPropertiesKeys() {
const std::set<IDCollectionKey> web_properties_keys{ const std::set<IDCollectionKey> web_properties_keys{
variations::GOOGLE_WEB_PROPERTIES_ANY_CONTEXT, GOOGLE_WEB_PROPERTIES_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_SIGNED_IN, GOOGLE_WEB_PROPERTIES_FIRST_PARTY,
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT}; GOOGLE_WEB_PROPERTIES_SIGNED_IN,
GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT,
GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY,
};
return GetVariationsVectorImpl(web_properties_keys); return GetVariationsVectorImpl(web_properties_keys);
} }
...@@ -168,11 +165,7 @@ void VariationsIdsProvider::OnFieldTrialGroupFinalized( ...@@ -168,11 +165,7 @@ void VariationsIdsProvider::OnFieldTrialGroupFinalized(
const std::string& group_name) { const std::string& group_name) {
base::AutoLock scoped_lock(lock_); base::AutoLock scoped_lock(lock_);
const size_t old_size = variation_ids_set_.size(); const size_t old_size = variation_ids_set_.size();
CacheVariationsId(trial_name, group_name, GOOGLE_WEB_PROPERTIES_ANY_CONTEXT); CacheVariationsId(trial_name, group_name);
CacheVariationsId(trial_name, group_name, GOOGLE_WEB_PROPERTIES_SIGNED_IN);
CacheVariationsId(trial_name, group_name,
GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT);
CacheVariationsId(trial_name, group_name, GOOGLE_APP);
if (variation_ids_set_.size() != old_size) if (variation_ids_set_.size() != old_size)
UpdateVariationIDsHeaderValue(); UpdateVariationIDsHeaderValue();
} }
...@@ -215,13 +208,7 @@ void VariationsIdsProvider::InitVariationIDsCacheIfNeeded() { ...@@ -215,13 +208,7 @@ void VariationsIdsProvider::InitVariationIDsCacheIfNeeded() {
base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups); base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups);
for (const auto& entry : initial_groups) { for (const auto& entry : initial_groups) {
CacheVariationsId(entry.trial_name, entry.group_name, CacheVariationsId(entry.trial_name, entry.group_name);
GOOGLE_WEB_PROPERTIES_ANY_CONTEXT);
CacheVariationsId(entry.trial_name, entry.group_name,
GOOGLE_WEB_PROPERTIES_SIGNED_IN);
CacheVariationsId(entry.trial_name, entry.group_name,
GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT);
CacheVariationsId(entry.trial_name, entry.group_name, GOOGLE_APP);
} }
UpdateVariationIDsHeaderValue(); UpdateVariationIDsHeaderValue();
...@@ -229,11 +216,13 @@ void VariationsIdsProvider::InitVariationIDsCacheIfNeeded() { ...@@ -229,11 +216,13 @@ void VariationsIdsProvider::InitVariationIDsCacheIfNeeded() {
} }
void VariationsIdsProvider::CacheVariationsId(const std::string& trial_name, void VariationsIdsProvider::CacheVariationsId(const std::string& trial_name,
const std::string& group_name, const std::string& group_name) {
IDCollectionKey key) { for (int i = 0; i < ID_COLLECTION_COUNT; ++i) {
const VariationID id = GetGoogleVariationID(key, trial_name, group_name); IDCollectionKey key = static_cast<IDCollectionKey>(i);
if (id != EMPTY_ID) const VariationID id = GetGoogleVariationID(key, trial_name, group_name);
variation_ids_set_.insert(VariationIDEntry(id, key)); if (id != EMPTY_ID)
variation_ids_set_.insert(VariationIDEntry(id, key));
}
} }
void VariationsIdsProvider::UpdateVariationIDsHeaderValue() { void VariationsIdsProvider::UpdateVariationIDsHeaderValue() {
...@@ -270,16 +259,38 @@ std::string VariationsIdsProvider::GenerateBase64EncodedProto( ...@@ -270,16 +259,38 @@ std::string VariationsIdsProvider::GenerateBase64EncodedProto(
case GOOGLE_WEB_PROPERTIES_ANY_CONTEXT: case GOOGLE_WEB_PROPERTIES_ANY_CONTEXT:
proto.add_variation_id(entry.first); proto.add_variation_id(entry.first);
break; break;
case GOOGLE_WEB_PROPERTIES_FIRST_PARTY:
if (base::FeatureList::IsEnabled(
internal::kRestrictGoogleWebVisibility)) {
// TODO(crbug/1094303): Send fewer VariationIDs in third-party
// contexts by excluding IDs associated with
// GOOGLE_WEB_PROPERTIES_FIRST_PARTY.
break;
}
// When the feature is not enabled, treat VariationIDs associated with
// GOOGLE_WEB_PROPERTIES_FIRST_PARTY in the same way as those
// associated with GOOGLE_WEB_PROPERTIES_ANY_CONTEXT.
proto.add_variation_id(entry.first);
break;
case GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT: case GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT:
proto.add_trigger_variation_id(entry.first); proto.add_trigger_variation_id(entry.first);
break; break;
case GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY:
if (base::FeatureList::IsEnabled(
internal::kRestrictGoogleWebVisibility)) {
// TODO(crbug/1094303): Send fewer VariationIDs in third-party
// contexts by excluding IDs associated with
// GOOGLE_WEB_PROPERTIES_FIRST_PARTY.
break;
}
// When the feature is not enabled, treat VariationIDs associated with
// GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY in the same way as those
// associated with GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT.
proto.add_trigger_variation_id(entry.first);
break;
case GOOGLE_APP: case GOOGLE_APP:
// These IDs should not be added into Google Web headers. // These IDs should not be added into Google Web headers.
break; break;
case GOOGLE_WEB_PROPERTIES_FIRST_PARTY:
case GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY:
// TODO(crbug/1094303): Add support for the above IDCollectionKeys.
break;
case ID_COLLECTION_COUNT: case ID_COLLECTION_COUNT:
// This case included to get full enum coverage for switch, so that // This case included to get full enum coverage for switch, so that
// new enums introduce compiler warnings. Nothing to do for this. // new enums introduce compiler warnings. Nothing to do for this.
...@@ -385,7 +396,7 @@ std::vector<VariationID> VariationsIdsProvider::GetVariationsVectorImpl( ...@@ -385,7 +396,7 @@ std::vector<VariationID> VariationsIdsProvider::GetVariationsVectorImpl(
result.push_back(entry.first); result.push_back(entry.first);
} }
// Make sure each enry is unique. As a side-effect, the output will be sorted. // Make sure each entry is unique. As a side effect, the output is sorted.
std::sort(result.begin(), result.end()); std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end()); result.erase(std::unique(result.begin(), result.end()), result.end());
return result; return result;
......
...@@ -64,9 +64,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer, ...@@ -64,9 +64,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer,
// apps. // apps.
std::string GetGoogleAppVariationsString(); std::string GetGoogleAppVariationsString();
// Returns the collection of variation ids matching the given |key|. Each // Returns the collection of VariationIDs associated with |keys|. Each entry
// entry in the returned vector will be unique. // in the returned vector is unique.
std::vector<VariationID> GetVariationsVector(IDCollectionKey key); std::vector<VariationID> GetVariationsVector(
const std::set<IDCollectionKey>& keys);
// Returns the collection of variations ids for all Google Web Properties // Returns the collection of variations ids for all Google Web Properties
// related keys. // related keys.
...@@ -132,7 +133,7 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer, ...@@ -132,7 +133,7 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer,
// Returns a space-separated string containing the list of current active // Returns a space-separated string containing the list of current active
// variations (as would be reported in the |variation_id| repeated field of // variations (as would be reported in the |variation_id| repeated field of
// the ClientVariations proto) for a given ID collection. // the ClientVariations proto) for a given ID collection.
std::string GetVariationsString(IDCollectionKey key); std::string GetVariationsString(const std::set<IDCollectionKey>& keys);
// base::FieldTrialList::Observer: // base::FieldTrialList::Observer:
// This will add the variation ID associated with |trial_name| and // This will add the variation ID associated with |trial_name| and
...@@ -149,11 +150,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer, ...@@ -149,11 +150,10 @@ class VariationsIdsProvider : public base::FieldTrialList::Observer,
// new variation IDs. // new variation IDs.
void InitVariationIDsCacheIfNeeded(); void InitVariationIDsCacheIfNeeded();
// Looks up the associated id for the given trial/group and adds an entry for // Looks up the VariationID associated with |trial_name| and |group_name|, and
// it to |variation_ids_set_| if found. // if found, adds an entry for it to |variation_ids_set_|.
void CacheVariationsId(const std::string& trial_name, void CacheVariationsId(const std::string& trial_name,
const std::string& group_name, const std::string& group_name);
IDCollectionKey key);
// Takes whatever is currently in |variation_ids_set_| and recreates // Takes whatever is currently in |variation_ids_set_| and recreates
// |variation_ids_header_| with it. Assumes the the |lock_| is currently // |variation_ids_header_| with it. Assumes the the |lock_| is currently
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/variations/client_filterable_state.h" #include "components/variations/client_filterable_state.h"
#include "components/variations/processed_study.h" #include "components/variations/processed_study.h"
...@@ -35,31 +36,60 @@ void RegisterExperimentParams(const Study& study, ...@@ -35,31 +36,60 @@ void RegisterExperimentParams(const Study& study,
AssociateVariationParams(study.name(), experiment.name(), params); AssociateVariationParams(study.name(), experiment.name(), params);
} }
// If there are variation ids associated with |experiment|, register the // Returns the IDCollectionKey with which |experiment| should be associated.
// variation ids. // Returns nullopt when |experiment| doesn't have a Google web or Google web
void RegisterVariationIds(const Study_Experiment& experiment, // trigger experiment ID.
const std::string& trial_name) { base::Optional<IDCollectionKey> GetKeyForWebExperiment(
if (experiment.has_google_web_experiment_id()) { const Study_Experiment& experiment) {
const VariationID variation_id = bool has_web_experiment_id = experiment.has_google_web_experiment_id();
static_cast<VariationID>(experiment.google_web_experiment_id()); bool has_web_trigger_experiment_id =
AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES_ANY_CONTEXT, experiment.has_google_web_trigger_experiment_id();
trial_name, experiment.name(),
variation_id); if (!has_web_experiment_id && !has_web_trigger_experiment_id)
} return base::nullopt;
if (experiment.has_google_web_trigger_experiment_id()) {
const VariationID variation_id = // An experiment cannot have both |google_web_experiment_id| and
static_cast<VariationID>(experiment.google_web_trigger_experiment_id()); // |google_trigger_web_experiment_id|. This is enforced by the variations
AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT, // server before generating a variations seed.
trial_name, experiment.name(), DCHECK(!(has_web_experiment_id && has_web_trigger_experiment_id));
variation_id);
Study_GoogleWebVisibility visibility = experiment.google_web_visibility();
if (visibility == Study_GoogleWebVisibility_FIRST_PARTY) {
return has_web_trigger_experiment_id
? GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY
: GOOGLE_WEB_PROPERTIES_FIRST_PARTY;
} }
return has_web_trigger_experiment_id
? GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT
: GOOGLE_WEB_PROPERTIES_ANY_CONTEXT;
}
// If there are VariationIDs associated with |experiment|, register the
// VariationIDs.
void RegisterVariationIds(const Study_Experiment& experiment,
const std::string& trial_name) {
if (experiment.has_google_app_experiment_id()) { if (experiment.has_google_app_experiment_id()) {
const VariationID variation_id = const VariationID variation_id =
static_cast<VariationID>(experiment.google_app_experiment_id()); static_cast<VariationID>(experiment.google_app_experiment_id());
AssociateGoogleVariationIDForce(GOOGLE_APP, trial_name, experiment.name(), AssociateGoogleVariationIDForce(GOOGLE_APP, trial_name, experiment.name(),
variation_id); variation_id);
} }
base::Optional<IDCollectionKey> key = GetKeyForWebExperiment(experiment);
if (!key.has_value())
return;
// An experiment cannot have both |google_web_experiment_id| and
// |google_trigger_web_experiment_id|. See GetKeyForWebExperiment() for more
// details.
const VariationID variation_id =
experiment.has_google_web_trigger_experiment_id()
? static_cast<VariationID>(
experiment.google_web_trigger_experiment_id())
: static_cast<VariationID>(experiment.google_web_experiment_id());
AssociateGoogleVariationIDForce(key.value(), trial_name, experiment.name(),
variation_id);
} }
// Executes |callback| on every override defined by |experiment|. // Executes |callback| on every override defined by |experiment|.
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "base/test/scoped_field_trial_list_resetter.h" #include "base/test/scoped_field_trial_list_resetter.h"
#include "components/variations/client_filterable_state.h" #include "components/variations/client_filterable_state.h"
#include "components/variations/processed_study.h" #include "components/variations/processed_study.h"
#include "components/variations/proto/study.pb.h"
#include "components/variations/study_filtering.h" #include "components/variations/study_filtering.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -182,6 +183,23 @@ TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) { ...@@ -182,6 +183,23 @@ TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId) {
EXPECT_EQ(kExperimentId, id); EXPECT_EQ(kExperimentId, id);
} }
TEST_F(VariationsSeedProcessorTest, AllowForceGroupAndVariationId_FirstParty) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
Study study = CreateStudyWithFlagGroups(100, 0, 0);
Study_Experiment* experiment1 = study.mutable_experiment(1);
experiment1->set_google_web_experiment_id(kExperimentId);
experiment1->set_google_web_visibility(Study_GoogleWebVisibility_FIRST_PARTY);
EXPECT_TRUE(CreateTrialFromStudy(study));
EXPECT_EQ(kFlagGroup1Name,
base::FieldTrialList::FindFullName(kFlagStudyName));
VariationID id = GetGoogleVariationID(GOOGLE_WEB_PROPERTIES_FIRST_PARTY,
kFlagStudyName, kFlagGroup1Name);
EXPECT_EQ(kExperimentId, id);
}
// Test that the group for kForcingFlag1 is forced. // Test that the group for kForcingFlag1 is forced.
TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) { TEST_F(VariationsSeedProcessorTest, ForceGroupWithFlag1) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1); base::CommandLine::ForCurrentProcess()->AppendSwitch(kForcingFlag1);
......
...@@ -702,7 +702,8 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -702,7 +702,8 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
variations::VariationsIdsProvider* provider = variations::VariationsIdsProvider* provider =
variations::VariationsIdsProvider::GetInstance(); variations::VariationsIdsProvider::GetInstance();
std::vector<variations::VariationID> ids = provider->GetVariationsVector( std::vector<variations::VariationID> ids = provider->GetVariationsVector(
variations::GOOGLE_WEB_PROPERTIES_ANY_CONTEXT); {variations::GOOGLE_WEB_PROPERTIES_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_FIRST_PARTY});
return std::find(ids.begin(), ids.end(), variationID) != ids.end(); return std::find(ids.begin(), ids.end(), variationID) != ids.end();
} }
...@@ -710,7 +711,8 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -710,7 +711,8 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
variations::VariationsIdsProvider* provider = variations::VariationsIdsProvider* provider =
variations::VariationsIdsProvider::GetInstance(); variations::VariationsIdsProvider::GetInstance();
std::vector<variations::VariationID> ids = provider->GetVariationsVector( std::vector<variations::VariationID> ids = provider->GetVariationsVector(
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT); {variations::GOOGLE_WEB_PROPERTIES_TRIGGER_ANY_CONTEXT,
variations::GOOGLE_WEB_PROPERTIES_TRIGGER_FIRST_PARTY});
return std::find(ids.begin(), ids.end(), variationID) != ids.end(); return std::find(ids.begin(), ids.end(), variationID) != ids.end();
} }
......
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