Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: base/metrics/field_trial_unittest.cc

Issue 2463223002: Store field trial parameters in shared memory (Closed)
Patch Set: fix tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/field_trial_unittest.cc
diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc
index 0ad13a22be77e00e85cde99aa41b72af63fa79c5..96cb5c0b5c7d022cf7432c1a9ca415cdbe3f4d55 100644
--- a/base/metrics/field_trial_unittest.cc
+++ b/base/metrics/field_trial_unittest.cc
@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
+#include "base/metrics/field_trial_param_associator.h"
#include "base/rand_util.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
@@ -1187,11 +1188,36 @@ TEST(FieldTrialListTest, AddTrialsToAllocator) {
FieldTrialList field_trial_list2(nullptr);
std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
- shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
+ shm.get()->Map(64 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
Alexei Svitkine (slow) 2016/11/22 17:46:38 Nit: Remove this diff.
lawrencewu 2016/11/22 20:25:44 Done.
FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
std::string check_string;
FieldTrialList::AllStatesToString(&check_string);
EXPECT_EQ(save_string, check_string);
}
+TEST(FieldTrialListTest, AssociateFieldTrialParams) {
+ std::string trial_name("Trial1");
+ std::string group_name("Group1");
+
+ // Create a field trial with some params.
+ FieldTrialList field_trial_list(nullptr);
+ FieldTrialList::CreateFieldTrial(trial_name, group_name);
+ std::map<std::string, std::string> params;
+ params["key1"] = "value1";
+ params["key2"] = "value2";
+ FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams(
+ trial_name, group_name, params);
+ FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
+
+ // Clear all cached params from the associator.
+ FieldTrialParamAssociator::GetInstance()->ClearAllCachedParamsForTesting();
+
+ // Check that we fetch the param from shared memory properly.
+ std::map<std::string, std::string> new_params;
+ FieldTrialParamAssociator::GetInstance()->GetFieldTrialParams(trial_name,
+ &new_params);
+ EXPECT_EQ(new_params["key1"], "value1");
Alexei Svitkine (slow) 2016/11/22 17:46:37 The expected value should be on the left.
lawrencewu 2016/11/22 20:25:44 Fixed.
+ EXPECT_EQ(new_params["key2"], "value2");
+}
+
} // namespace base
« base/metrics/field_trial_param_associator.cc ('K') | « base/metrics/field_trial_param_associator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698