Chromium Code Reviews| 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..fa1bff0b4187518f5d7ce7d53cb0a296d31fd65b |
| --- /dev/null |
| +++ b/extensions/common/manifest_handlers/action_handlers_handler_unittest.cc |
| @@ -0,0 +1,67 @@ |
| +// 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 "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) { |
| + LoadAndExpectError(CreateManifest("32"), |
| + manifest_errors::kInvalidActionHandlersType); |
| + LoadAndExpectError(CreateManifest("[true]"), |
| + manifest_errors::kInvalidActionHandlersType); |
| + LoadAndExpectError(CreateManifest("[\"invalid_handler\"]"), |
| + manifest_errors::kInvalidActionHandlersActionType); |
| +} |
| + |
| +TEST_F(ActionHandlersManifestTest, VerifyParse) { |
| + auto none = LoadAndExpectSuccess(CreateManifest("[]")); |
|
Devlin
2017/01/17 21:42:01
nit: It's not clear from the callsite what the ret
jdufault
2017/01/20 20:31:47
Done.
|
| + EXPECT_EQ(std::set<app_runtime::ActionType>{}, GetActionHandlers(none.get())); |
| + |
| + auto 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 |