OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/feature_list.h" | 5 #include "base/feature_list.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/persistent_memory_allocator.h" | |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kFeatureOnByDefaultName[] = "OnByDefault"; | 25 const char kFeatureOnByDefaultName[] = "OnByDefault"; |
25 struct Feature kFeatureOnByDefault { | 26 struct Feature kFeatureOnByDefault { |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 ClearFeatureListInstance(); | 462 ClearFeatureListInstance(); |
462 // This test case simulates the calling pattern found in code which does not | 463 // This test case simulates the calling pattern found in code which does not |
463 // explicitly initialize the features list. | 464 // explicitly initialize the features list. |
464 // All IsEnabled() calls should return the default value in this scenario. | 465 // All IsEnabled() calls should return the default value in this scenario. |
465 EXPECT_EQ(nullptr, FeatureList::GetInstance()); | 466 EXPECT_EQ(nullptr, FeatureList::GetInstance()); |
466 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOnByDefault)); | 467 EXPECT_TRUE(FeatureList::IsEnabled(kFeatureOnByDefault)); |
467 EXPECT_EQ(nullptr, FeatureList::GetInstance()); | 468 EXPECT_EQ(nullptr, FeatureList::GetInstance()); |
468 EXPECT_FALSE(FeatureList::IsEnabled(kFeatureOffByDefault)); | 469 EXPECT_FALSE(FeatureList::IsEnabled(kFeatureOffByDefault)); |
469 } | 470 } |
470 | 471 |
472 TEST_F(FeatureListTest, StoreAndRetrieveFeaturesFromSharedMemory) { | |
Alexei Svitkine (slow)
2016/12/01 20:05:52
Can you add testing for OVERRIDE_USE_DEFAULT state
lawrencewu
2016/12/02 19:24:46
Done.
| |
473 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
474 | |
475 // Create some overrides. | |
476 feature_list->RegisterOverride(kFeatureOffByDefaultName, | |
477 FeatureList::OVERRIDE_ENABLE_FEATURE, nullptr); | |
478 feature_list->RegisterOverride( | |
479 kFeatureOnByDefaultName, FeatureList::OVERRIDE_DISABLE_FEATURE, nullptr); | |
480 feature_list->FinalizeInitialization(); | |
481 | |
482 // Create an allocator and store the overrides. | |
483 std::unique_ptr<SharedMemory> shm(new SharedMemory()); | |
484 shm->CreateAndMapAnonymous(4 << 10); | |
485 SharedPersistentMemoryAllocator allocator(std::move(shm), 1, "", false); | |
486 feature_list->AddFeaturesToAllocator(&allocator); | |
487 | |
488 std::unique_ptr<base::FeatureList> feature_list2(new base::FeatureList); | |
489 | |
490 // Check that the new feature list is empty. | |
491 EXPECT_FALSE(feature_list2->IsFeatureOverriddenFromCommandLine( | |
492 kFeatureOffByDefaultName, FeatureList::OVERRIDE_ENABLE_FEATURE)); | |
493 EXPECT_FALSE(feature_list2->IsFeatureOverriddenFromCommandLine( | |
494 kFeatureOnByDefaultName, FeatureList::OVERRIDE_DISABLE_FEATURE)); | |
495 | |
496 feature_list2->InitializeFromSharedMemory(&allocator); | |
497 // Check that the new feature list now has 2 overrides. | |
498 EXPECT_TRUE(feature_list2->IsFeatureOverriddenFromCommandLine( | |
499 kFeatureOffByDefaultName, FeatureList::OVERRIDE_ENABLE_FEATURE)); | |
500 EXPECT_TRUE(feature_list2->IsFeatureOverriddenFromCommandLine( | |
501 kFeatureOnByDefaultName, FeatureList::OVERRIDE_DISABLE_FEATURE)); | |
502 } | |
503 | |
471 } // namespace base | 504 } // namespace base |
OLD | NEW |