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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « extensions/common/manifest_handlers/action_handlers_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« 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