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

Unified Diff: extensions/common/manifest_handlers/action_handlers_handler_unittest.cc

Issue 2618493002: Chrome app manifest support for action handlers. (Closed)
Patch Set: Make //components/version_info:version_info dep explicit Created 3 years, 11 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
« no previous file with comments | « extensions/common/manifest_handlers/action_handlers_handler.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/common/manifest_handlers/action_handlers_handler_unittest.cc
diff --git a/extensions/common/manifest_handlers/action_handlers_handler_unittest.cc b/extensions/common/manifest_handlers/action_handlers_handler_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..055013157398944db0e0652a1f0874b6bc4d3801
--- /dev/null
+++ b/extensions/common/manifest_handlers/action_handlers_handler_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/values_test_util.h"
+#include "components/version_info/version_info.h"
+#include "extensions/common/features/feature_channel.h"
+#include "extensions/common/manifest_constants.h"
+#include "extensions/common/manifest_handlers/action_handlers_handler.h"
+#include "extensions/common/manifest_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace app_runtime = api::app_runtime;
+
+namespace {
+
+class ActionHandlersManifestTest : public ManifestTest {
+ protected:
+ ManifestData CreateManifest(const std::string& action_handlers) {
+ std::unique_ptr<base::DictionaryValue> manifest =
+ base::DictionaryValue::From(base::test::ParseJson(R"json({
+ "name": "test",
+ "version": "1",
+ "app": {
+ "background": {
+ "scripts": ["background.js"]
+ }
+ },
+ "manifest_version": 2,
+ "action_handlers": )json" +
+ action_handlers +
+ "}"));
+ EXPECT_TRUE(manifest);
+ return ManifestData(std::move(manifest), "test");
+ }
+
+ // Returns all action handlers associated with |extension|.
+ std::set<app_runtime::ActionType> GetActionHandlers(
+ const Extension* extension) {
+ ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>(
+ extension->GetManifestData(manifest_keys::kActionHandlers));
+ return info ? info->action_handlers : std::set<app_runtime::ActionType>();
+ }
+};
+
+} // namespace
+
+TEST_F(ActionHandlersManifestTest, InvalidType) {
+ extensions::ScopedCurrentChannel channel(version_info::Channel::DEV);
+ LoadAndExpectError(CreateManifest("32"),
+ manifest_errors::kInvalidActionHandlersType);
+ LoadAndExpectError(CreateManifest("[true]"),
+ manifest_errors::kInvalidActionHandlersType);
+ LoadAndExpectError(CreateManifest("[\"invalid_handler\"]"),
+ manifest_errors::kInvalidActionHandlersActionType);
+}
+
+TEST_F(ActionHandlersManifestTest, VerifyParse) {
+ extensions::ScopedCurrentChannel channel(version_info::Channel::DEV);
+ scoped_refptr<Extension> none = LoadAndExpectSuccess(CreateManifest("[]"));
+ EXPECT_EQ(std::set<app_runtime::ActionType>{}, GetActionHandlers(none.get()));
+
+ scoped_refptr<Extension> new_note =
+ LoadAndExpectSuccess(CreateManifest("[\"new_note\"]"));
+ EXPECT_EQ(
+ std::set<app_runtime::ActionType>{app_runtime::ACTION_TYPE_NEW_NOTE},
+ GetActionHandlers(new_note.get()));
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/common/manifest_handlers/action_handlers_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698