| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/values_test_util.h" |
| 6 #include "components/version_info/version_info.h" |
| 7 #include "extensions/common/features/feature_channel.h" |
| 8 #include "extensions/common/manifest_constants.h" |
| 9 #include "extensions/common/manifest_handlers/action_handlers_handler.h" |
| 10 #include "extensions/common/manifest_test.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 namespace app_runtime = api::app_runtime; |
| 16 |
| 17 namespace { |
| 18 |
| 19 class ActionHandlersManifestTest : public ManifestTest { |
| 20 protected: |
| 21 ManifestData CreateManifest(const std::string& action_handlers) { |
| 22 std::unique_ptr<base::DictionaryValue> manifest = |
| 23 base::DictionaryValue::From(base::test::ParseJson(R"json({ |
| 24 "name": "test", |
| 25 "version": "1", |
| 26 "app": { |
| 27 "background": { |
| 28 "scripts": ["background.js"] |
| 29 } |
| 30 }, |
| 31 "manifest_version": 2, |
| 32 "action_handlers": )json" + |
| 33 action_handlers + |
| 34 "}")); |
| 35 EXPECT_TRUE(manifest); |
| 36 return ManifestData(std::move(manifest), "test"); |
| 37 } |
| 38 |
| 39 // Returns all action handlers associated with |extension|. |
| 40 std::set<app_runtime::ActionType> GetActionHandlers( |
| 41 const Extension* extension) { |
| 42 ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>( |
| 43 extension->GetManifestData(manifest_keys::kActionHandlers)); |
| 44 return info ? info->action_handlers : std::set<app_runtime::ActionType>(); |
| 45 } |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
| 50 TEST_F(ActionHandlersManifestTest, InvalidType) { |
| 51 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 52 LoadAndExpectError(CreateManifest("32"), |
| 53 manifest_errors::kInvalidActionHandlersType); |
| 54 LoadAndExpectError(CreateManifest("[true]"), |
| 55 manifest_errors::kInvalidActionHandlersType); |
| 56 LoadAndExpectError(CreateManifest("[\"invalid_handler\"]"), |
| 57 manifest_errors::kInvalidActionHandlersActionType); |
| 58 } |
| 59 |
| 60 TEST_F(ActionHandlersManifestTest, VerifyParse) { |
| 61 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 62 scoped_refptr<Extension> none = LoadAndExpectSuccess(CreateManifest("[]")); |
| 63 EXPECT_EQ(std::set<app_runtime::ActionType>{}, GetActionHandlers(none.get())); |
| 64 |
| 65 scoped_refptr<Extension> new_note = |
| 66 LoadAndExpectSuccess(CreateManifest("[\"new_note\"]")); |
| 67 EXPECT_EQ( |
| 68 std::set<app_runtime::ActionType>{app_runtime::ACTION_TYPE_NEW_NOTE}, |
| 69 GetActionHandlers(new_note.get())); |
| 70 } |
| 71 |
| 72 } // namespace extensions |
| OLD | NEW |