| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" | 
| 10 #include "base/build_time.h" | 10 #include "base/build_time.h" | 
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1319   FieldTrialList field_trial_list2(nullptr); | 1319   FieldTrialList field_trial_list2(nullptr); | 
| 1320   std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); | 1320   std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); | 
| 1321   // 4 KiB is enough to hold the trials only created for this test. | 1321   // 4 KiB is enough to hold the trials only created for this test. | 
| 1322   shm.get()->Map(4 << 10); | 1322   shm.get()->Map(4 << 10); | 
| 1323   FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); | 1323   FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); | 
| 1324   std::string check_string; | 1324   std::string check_string; | 
| 1325   FieldTrialList::AllStatesToString(&check_string); | 1325   FieldTrialList::AllStatesToString(&check_string); | 
| 1326   EXPECT_EQ("*Trial1/Group1/", check_string); | 1326   EXPECT_EQ("*Trial1/Group1/", check_string); | 
| 1327 } | 1327 } | 
| 1328 | 1328 | 
|  | 1329 TEST(FieldTrialListTest, DumpAndFetchFromSharedMemory) { | 
|  | 1330   std::string trial_name("Trial1"); | 
|  | 1331   std::string group_name("Group1"); | 
|  | 1332 | 
|  | 1333   // Create a field trial with some params. | 
|  | 1334   FieldTrialList field_trial_list(nullptr); | 
|  | 1335   FieldTrialList::CreateFieldTrial(trial_name, group_name); | 
|  | 1336   std::map<std::string, std::string> params; | 
|  | 1337   params["key1"] = "value1"; | 
|  | 1338   params["key2"] = "value2"; | 
|  | 1339   FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams( | 
|  | 1340       trial_name, group_name, params); | 
|  | 1341 | 
|  | 1342   std::unique_ptr<base::SharedMemory> shm(new SharedMemory()); | 
|  | 1343   // 4 KiB is enough to hold the trials only created for this test. | 
|  | 1344   shm.get()->CreateAndMapAnonymous(4 << 10); | 
|  | 1345   // We _could_ use PersistentMemoryAllocator, this just has less params. | 
|  | 1346   SharedPersistentMemoryAllocator allocator(std::move(shm), 1, "", false); | 
|  | 1347 | 
|  | 1348   // Dump and subsequently retrieve the field trial to |allocator|. | 
|  | 1349   FieldTrialList::DumpAllFieldTrialsToPersistentAllocator(&allocator); | 
|  | 1350   std::vector<const FieldTrial::FieldTrialEntry*> entries = | 
|  | 1351       FieldTrialList::GetAllFieldTrialsFromPersistentAllocator(&allocator); | 
|  | 1352 | 
|  | 1353   // Check that we have the entry we put in. | 
|  | 1354   EXPECT_EQ(1u, entries.size()); | 
|  | 1355   const FieldTrial::FieldTrialEntry* entry = entries[0]; | 
|  | 1356 | 
|  | 1357   // Check that the trial and group names match. | 
|  | 1358   StringPiece shm_trial_name; | 
|  | 1359   StringPiece shm_group_name; | 
|  | 1360   entry->GetTrialAndGroupName(&shm_trial_name, &shm_group_name); | 
|  | 1361   EXPECT_EQ(trial_name, shm_trial_name); | 
|  | 1362   EXPECT_EQ(group_name, shm_group_name); | 
|  | 1363 | 
|  | 1364   // Check that the params match. | 
|  | 1365   std::map<std::string, std::string> shm_params; | 
|  | 1366   entry->GetParams(&shm_params); | 
|  | 1367   EXPECT_EQ(2u, shm_params.size()); | 
|  | 1368   EXPECT_EQ("value1", shm_params["key1"]); | 
|  | 1369   EXPECT_EQ("value2", shm_params["key2"]); | 
|  | 1370 } | 
|  | 1371 | 
| 1329 }  // namespace base | 1372 }  // namespace base | 
| OLD | NEW | 
|---|