OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" | 5 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "components/arc/common/intent_helper.mojom.h" | 9 #include "components/arc/common/intent_helper.mojom.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace arc { | 12 namespace arc { |
13 | 13 |
14 namespace { | |
15 | |
16 constexpr char kArcIntentHelperPackageName[] = "org.chromium.arc.intent_helper"; | |
17 | |
18 } // namespace | |
19 | |
20 // Tests if IsIntentHelperPackage works as expected. Probably too trivial | 14 // Tests if IsIntentHelperPackage works as expected. Probably too trivial |
21 // to test but just in case. | 15 // to test but just in case. |
22 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { | 16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { |
23 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); | 17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); |
24 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
25 kArcIntentHelperPackageName + std::string("a"))); | 19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); |
26 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
27 kArcIntentHelperPackageName + std::string("/.ArcIntentHelperActivity"))); | 21 ArcIntentHelperBridge::kArcIntentHelperPackageName + |
| 22 std::string("/.ArcIntentHelperActivity"))); |
28 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( | 23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( |
29 kArcIntentHelperPackageName)); | 24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); |
30 } | 25 } |
31 | 26 |
32 // Tests if FilterOutIntentHelper removes handlers as expected. | 27 // Tests if FilterOutIntentHelper removes handlers as expected. |
33 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { | 28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { |
34 { | 29 { |
35 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 30 mojo::Array<mojom::IntentHandlerInfoPtr> orig; |
36 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 31 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = |
37 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
38 EXPECT_EQ(0U, filtered.size()); | 33 EXPECT_EQ(0U, filtered.size()); |
39 } | 34 } |
(...skipping 10 matching lines...) Expand all Loading... |
50 // FilterOutIntentHelper is no-op in this case. | 45 // FilterOutIntentHelper is no-op in this case. |
51 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 46 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = |
52 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 47 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
53 EXPECT_EQ(2U, filtered.size()); | 48 EXPECT_EQ(2U, filtered.size()); |
54 } | 49 } |
55 | 50 |
56 { | 51 { |
57 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 52 mojo::Array<mojom::IntentHandlerInfoPtr> orig; |
58 orig.push_back(mojom::IntentHandlerInfo::New()); | 53 orig.push_back(mojom::IntentHandlerInfo::New()); |
59 orig[0]->name = "0"; | 54 orig[0]->name = "0"; |
60 orig[0]->package_name = kArcIntentHelperPackageName; | 55 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
61 orig.push_back(mojom::IntentHandlerInfo::New()); | 56 orig.push_back(mojom::IntentHandlerInfo::New()); |
62 orig[1]->name = "1"; | 57 orig[1]->name = "1"; |
63 orig[1]->package_name = "package_name1"; | 58 orig[1]->package_name = "package_name1"; |
64 | 59 |
65 // FilterOutIntentHelper should remove the first element. | 60 // FilterOutIntentHelper should remove the first element. |
66 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 61 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = |
67 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 62 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
68 ASSERT_EQ(1U, filtered.size()); | 63 ASSERT_EQ(1U, filtered.size()); |
69 EXPECT_EQ("1", filtered[0]->name); | 64 EXPECT_EQ("1", filtered[0]->name); |
70 EXPECT_EQ("package_name1", filtered[0]->package_name); | 65 EXPECT_EQ("package_name1", filtered[0]->package_name); |
71 } | 66 } |
72 | 67 |
73 { | 68 { |
74 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 69 mojo::Array<mojom::IntentHandlerInfoPtr> orig; |
75 orig.push_back(mojom::IntentHandlerInfo::New()); | 70 orig.push_back(mojom::IntentHandlerInfo::New()); |
76 orig[0]->name = "0"; | 71 orig[0]->name = "0"; |
77 orig[0]->package_name = kArcIntentHelperPackageName; | 72 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
78 orig.push_back(mojom::IntentHandlerInfo::New()); | 73 orig.push_back(mojom::IntentHandlerInfo::New()); |
79 orig[1]->name = "1"; | 74 orig[1]->name = "1"; |
80 orig[1]->package_name = "package_name1"; | 75 orig[1]->package_name = "package_name1"; |
81 orig.push_back(mojom::IntentHandlerInfo::New()); | 76 orig.push_back(mojom::IntentHandlerInfo::New()); |
82 orig[2]->name = "2"; | 77 orig[2]->name = "2"; |
83 orig[2]->package_name = kArcIntentHelperPackageName; | 78 orig[2]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
84 | 79 |
85 // FilterOutIntentHelper should remove two elements. | 80 // FilterOutIntentHelper should remove two elements. |
86 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 81 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = |
87 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 82 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
88 ASSERT_EQ(1U, filtered.size()); | 83 ASSERT_EQ(1U, filtered.size()); |
89 EXPECT_EQ("1", filtered[0]->name); | 84 EXPECT_EQ("1", filtered[0]->name); |
90 EXPECT_EQ("package_name1", filtered[0]->package_name); | 85 EXPECT_EQ("package_name1", filtered[0]->package_name); |
91 } | 86 } |
92 | 87 |
93 { | 88 { |
94 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 89 mojo::Array<mojom::IntentHandlerInfoPtr> orig; |
95 orig.push_back(mojom::IntentHandlerInfo::New()); | 90 orig.push_back(mojom::IntentHandlerInfo::New()); |
96 orig[0]->name = "0"; | 91 orig[0]->name = "0"; |
97 orig[0]->package_name = kArcIntentHelperPackageName; | 92 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
98 orig.push_back(mojom::IntentHandlerInfo::New()); | 93 orig.push_back(mojom::IntentHandlerInfo::New()); |
99 orig[1]->name = "1"; | 94 orig[1]->name = "1"; |
100 orig[1]->package_name = kArcIntentHelperPackageName; | 95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
101 | 96 |
102 // FilterOutIntentHelper should remove all elements. | 97 // FilterOutIntentHelper should remove all elements. |
103 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 98 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = |
104 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
105 EXPECT_EQ(0U, filtered.size()); | 100 EXPECT_EQ(0U, filtered.size()); |
106 } | 101 } |
107 } | 102 } |
108 | 103 |
109 } // namespace arc | 104 } // namespace arc |
OLD | NEW |