Chromium Code Reviews| 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 "extensions/common/manifest_constants.h" | |
| 7 #include "extensions/common/manifest_handlers/action_handlers_handler.h" | |
| 8 #include "extensions/common/manifest_test.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 namespace app_runtime = api::app_runtime; | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class ActionHandlersManifestTest : public ManifestTest { | |
| 18 protected: | |
| 19 ManifestData CreateManifest(const std::string& action_handlers) { | |
| 20 std::unique_ptr<base::DictionaryValue> manifest = | |
| 21 base::DictionaryValue::From(base::test::ParseJson(R"json({ | |
| 22 "name": "test", | |
| 23 "version": "1", | |
| 24 "app": { | |
| 25 "background": { | |
| 26 "scripts": ["background.js"] | |
| 27 } | |
| 28 }, | |
| 29 "manifest_version": 2, | |
| 30 "action_handlers": )json" + | |
| 31 action_handlers + | |
| 32 "}")); | |
| 33 EXPECT_TRUE(manifest); | |
| 34 return ManifestData(std::move(manifest), "test"); | |
| 35 } | |
| 36 | |
| 37 // Returns all action handlers associated with |extension|. | |
| 38 std::set<app_runtime::ActionType> GetActionHandlers( | |
| 39 const Extension* extension) { | |
| 40 ActionHandlersInfo* info = static_cast<ActionHandlersInfo*>( | |
| 41 extension->GetManifestData(manifest_keys::kActionHandlers)); | |
| 42 return info ? info->action_handlers : std::set<app_runtime::ActionType>(); | |
| 43 } | |
| 44 }; | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 TEST_F(ActionHandlersManifestTest, InvalidType) { | |
| 49 LoadAndExpectError(CreateManifest("32"), | |
| 50 manifest_errors::kInvalidActionHandlersType); | |
| 51 LoadAndExpectError(CreateManifest("[true]"), | |
| 52 manifest_errors::kInvalidActionHandlersType); | |
| 53 LoadAndExpectError(CreateManifest("[\"invalid_handler\"]"), | |
| 54 manifest_errors::kInvalidActionHandlersActionType); | |
| 55 } | |
| 56 | |
| 57 TEST_F(ActionHandlersManifestTest, VerifyParse) { | |
| 58 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.
| |
| 59 EXPECT_EQ(std::set<app_runtime::ActionType>{}, GetActionHandlers(none.get())); | |
| 60 | |
| 61 auto new_note = LoadAndExpectSuccess(CreateManifest("[\"new_note\"]")); | |
| 62 EXPECT_EQ( | |
| 63 std::set<app_runtime::ActionType>{app_runtime::ACTION_TYPE_NEW_NOTE}, | |
| 64 GetActionHandlers(new_note.get())); | |
| 65 } | |
| 66 | |
| 67 } // namespace extensions | |
| OLD | NEW |