Index: chrome/common/extensions/features/complex_feature_unittest.cc |
diff --git a/chrome/common/extensions/features/complex_feature_unittest.cc b/chrome/common/extensions/features/complex_feature_unittest.cc |
index 38f9735f8b2d2262302f3efdfb65f2de8c864f32..618681afc8cb4ee25b95a97a1e522b701b887924 100644 |
--- a/chrome/common/extensions/features/complex_feature_unittest.cc |
+++ b/chrome/common/extensions/features/complex_feature_unittest.cc |
@@ -4,12 +4,15 @@ |
#include "chrome/common/extensions/features/complex_feature.h" |
+#include "chrome/common/extensions/features/api_feature.h" |
#include "chrome/common/extensions/features/feature_channel.h" |
#include "chrome/common/extensions/features/simple_feature.h" |
+#include "extensions/common/test_util.h" |
#include "extensions/common/value_builder.h" |
#include "testing/gtest/include/gtest/gtest.h" |
using chrome::VersionInfo; |
+using extensions::APIFeature; |
using extensions::ComplexFeature; |
using extensions::DictionaryBuilder; |
using extensions::Feature; |
@@ -17,6 +20,7 @@ using extensions::ListBuilder; |
using extensions::Manifest; |
using extensions::ScopedCurrentChannel; |
using extensions::SimpleFeature; |
+using extensions::test_util::ParseJsonDictionaryWithSingleQuotes; |
namespace { |
@@ -145,4 +149,87 @@ TEST_F(ExtensionComplexFeatureTest, MultipleRulesChannels) { |
} |
} |
+// Tests a complex feature with blocked_in_service_worker returns true for |
+// IsBlockedInServiceWorker(). |
+TEST_F(ExtensionComplexFeatureTest, BlockedInServiceWorker) { |
+ scoped_ptr<ComplexFeature::FeatureList> features( |
+ new ComplexFeature::FeatureList()); |
+ |
+ // Two feature rules, both with blocked_in_service_worker: true. |
+ scoped_ptr<SimpleFeature> api_feature(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'trunk'," |
+ " 'blocked_in_service_worker': true" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ api_feature.reset(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'stable'," |
+ " 'blocked_in_service_worker': true" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); |
not at google - send to devlin
2014/03/28 17:30:49
allocate on stack?
scheib
2014/03/28 18:15:21
Done.
|
+ |
+ EXPECT_TRUE(feature->IsBlockedInServiceWorker()); |
+} |
+ |
+// Tests a complex feature without blocked_in_service_worker returns false for |
+// IsBlockedInServiceWorker(). |
+TEST_F(ExtensionComplexFeatureTest, NotBlockedInServiceWorker) { |
+ scoped_ptr<ComplexFeature::FeatureList> features( |
+ new ComplexFeature::FeatureList()); |
+ |
+ // Two feature rules without blocked_in_service_worker. |
+ scoped_ptr<SimpleFeature> api_feature(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'trunk'" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ api_feature.reset(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'stable'" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())); |
not at google - send to devlin
2014/03/28 17:30:49
ditto
scheib
2014/03/28 18:15:21
Done.
|
+ |
+ EXPECT_FALSE(feature->IsBlockedInServiceWorker()); |
+} |
+ |
+// Tests that a complex feature composing different values for |
+// blocked_in_service_worker will DCHECK. |
not at google - send to devlin
2014/03/28 17:30:49
testing DCHECKs isn't that useful. DCHECK means th
scheib
2014/03/28 18:15:21
Done.
|
+#if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST |
+TEST_F(ExtensionComplexFeatureTest, MixedBlockedInServiceWorker) { |
+ scoped_ptr<ComplexFeature::FeatureList> features( |
+ new ComplexFeature::FeatureList()); |
+ |
+ // mixed blocked_in_service_worker. |
+ scoped_ptr<SimpleFeature> api_feature(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'trunk'," |
+ " 'blocked_in_service_worker': true" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ api_feature.reset(new APIFeature()); |
+ api_feature->Parse(ParseJsonDictionaryWithSingleQuotes( |
+ "{" |
+ " 'channel': 'stable'" |
+ "}").get()); |
+ features->push_back(api_feature.release()); |
+ |
+ ASSERT_DEATH( |
+ scoped_ptr<ComplexFeature> feature(new ComplexFeature(features.Pass())), |
+ ""); |
+} |
+#endif |
+ |
} // namespace |