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

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 2412113002: Use SharedPersistentMemoryAllocator to share field trial state (Closed)
Patch Set: move field_trial_allocator into anon namespace Created 4 years, 2 months 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 unified diff | Download patch
OLDNEW
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 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 ""); 1136 "");
1137 } 1137 }
1138 1138
1139 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) { 1139 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) {
1140 base::FieldTrialList field_trial_list( 1140 base::FieldTrialList field_trial_list(
1141 base::MakeUnique<base::MockEntropyProvider>()); 1141 base::MakeUnique<base::MockEntropyProvider>());
1142 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1"); 1142 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1");
1143 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program")); 1143 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program"));
1144 base::CommandLine cmd_line = base::CommandLine(test_file_path); 1144 base::CommandLine cmd_line = base::CommandLine(test_file_path);
1145 1145
1146 std::unique_ptr<base::SharedMemory> field_trial_state = 1146 base::FieldTrialList::CopyFieldTrialStateToFlags("field-trial-handle",
1147 base::FieldTrialList::CopyFieldTrialStateToFlags("field-trial-handle", 1147 &cmd_line);
1148 &cmd_line);
1149 1148
1150 EXPECT_TRUE(field_trial_state.get() == nullptr);
1151 EXPECT_TRUE(cmd_line.HasSwitch(switches::kForceFieldTrials)); 1149 EXPECT_TRUE(cmd_line.HasSwitch(switches::kForceFieldTrials));
1152 } 1150 }
1153 1151
1152 TEST(FieldTrialListTest, InstantiateAllocator) {
Alexei Svitkine (slow) 2016/10/20 17:50:29 This test would pass if the function didn't add an
lawrencewu 2016/10/21 16:41:58 Done.
1153 // Test that instantiating the allocator twice doesn't create a new allocator
1154 // or re-add any field trials.
1155 base::FieldTrialList field_trial_list(
1156 base::MakeUnique<base::MockEntropyProvider>());
Alexei Svitkine (slow) 2016/10/20 17:50:29 You can just pass in nullptr.
lawrencewu 2016/10/21 16:41:58 Done.
1157 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1");
1158
1159 EXPECT_TRUE(base::FieldTrialList::GetFieldTrialAllocatorForTesting() ==
1160 nullptr);
Alexei Svitkine (slow) 2016/10/20 17:50:29 EXPECT_EQ or just EXPECT_FALSE
lawrencewu 2016/10/21 16:41:58 Done.
1161 base::FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1162 void* memory =
1163 base::FieldTrialList::GetFieldTrialAllocatorForTesting()->shared_memory();
1164 size_t used =
1165 base::FieldTrialList::GetFieldTrialAllocatorForTesting()->used();
1166
1167 // Ensure that the function is idempotent.
1168 base::FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
Alexei Svitkine (slow) 2016/10/20 17:50:29 After this test runs, it sounds like it will leave
lawrencewu 2016/10/21 16:41:58 Done.
1169 void* new_memory =
1170 base::FieldTrialList::GetFieldTrialAllocatorForTesting()->shared_memory();
1171 size_t new_used =
1172 base::FieldTrialList::GetFieldTrialAllocatorForTesting()->used();
1173 EXPECT_TRUE(memory == new_memory);
Alexei Svitkine (slow) 2016/10/20 17:50:29 EXPECT_EQ
lawrencewu 2016/10/21 16:41:58 Done.
1174 EXPECT_TRUE(used == new_used);
1175 }
1176
1154 } // namespace base 1177 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698