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

Unified Diff: chrome/common/extensions/features/complex_feature_unittest.cc

Issue 217163003: Enable _api_features.json to block APIs from service worker contexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
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..616c3cc512058610dcd93c47fb3763bf4cfb7cd4 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,54 @@ 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());
+
+ EXPECT_TRUE(ComplexFeature(features.Pass()).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());
+
+ EXPECT_FALSE(ComplexFeature(features.Pass()).IsBlockedInServiceWorker());
+}
+
} // namespace
« no previous file with comments | « chrome/common/extensions/features/complex_feature.cc ('k') | chrome/common/extensions/features/simple_feature.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698