| 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 // Tests if IsIntentHelperPackage works as expected. Probably too trivial | 14 // Tests if IsIntentHelperPackage works as expected. Probably too trivial |
| 15 // to test but just in case. | 15 // to test but just in case. |
| 16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { | 16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { |
| 17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); | 17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); |
| 18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
| 19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); | 19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); |
| 20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
| 21 ArcIntentHelperBridge::kArcIntentHelperPackageName + | 21 ArcIntentHelperBridge::kArcIntentHelperPackageName + |
| 22 std::string("/.ArcIntentHelperActivity"))); | 22 std::string("/.ArcIntentHelperActivity"))); |
| 23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( | 23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( |
| 24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); | 24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Tests if FilterOutIntentHelper removes handlers as expected. | 27 // Tests if FilterOutIntentHelper removes handlers as expected. |
| 28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { | 28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { |
| 29 { | 29 { |
| 30 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 30 std::vector<mojom::IntentHandlerInfoPtr> orig; |
| 31 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 31 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
| 32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
| 33 EXPECT_EQ(0U, filtered.size()); | 33 EXPECT_EQ(0U, filtered.size()); |
| 34 } | 34 } |
| 35 | 35 |
| 36 { | 36 { |
| 37 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 37 std::vector<mojom::IntentHandlerInfoPtr> orig; |
| 38 orig.push_back(mojom::IntentHandlerInfo::New()); | 38 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 39 orig[0]->name = "0"; | 39 orig[0]->name = "0"; |
| 40 orig[0]->package_name = "package_name0"; | 40 orig[0]->package_name = "package_name0"; |
| 41 orig.push_back(mojom::IntentHandlerInfo::New()); | 41 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 42 orig[1]->name = "1"; | 42 orig[1]->name = "1"; |
| 43 orig[1]->package_name = "package_name1"; | 43 orig[1]->package_name = "package_name1"; |
| 44 | 44 |
| 45 // FilterOutIntentHelper is no-op in this case. | 45 // FilterOutIntentHelper is no-op in this case. |
| 46 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 46 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
| 47 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 47 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
| 48 EXPECT_EQ(2U, filtered.size()); | 48 EXPECT_EQ(2U, filtered.size()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 { | 51 { |
| 52 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 52 std::vector<mojom::IntentHandlerInfoPtr> orig; |
| 53 orig.push_back(mojom::IntentHandlerInfo::New()); | 53 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 54 orig[0]->name = "0"; | 54 orig[0]->name = "0"; |
| 55 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 55 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
| 56 orig.push_back(mojom::IntentHandlerInfo::New()); | 56 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 57 orig[1]->name = "1"; | 57 orig[1]->name = "1"; |
| 58 orig[1]->package_name = "package_name1"; | 58 orig[1]->package_name = "package_name1"; |
| 59 | 59 |
| 60 // FilterOutIntentHelper should remove the first element. | 60 // FilterOutIntentHelper should remove the first element. |
| 61 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 61 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
| 62 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 62 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
| 63 ASSERT_EQ(1U, filtered.size()); | 63 ASSERT_EQ(1U, filtered.size()); |
| 64 EXPECT_EQ("1", filtered[0]->name); | 64 EXPECT_EQ("1", filtered[0]->name); |
| 65 EXPECT_EQ("package_name1", filtered[0]->package_name); | 65 EXPECT_EQ("package_name1", filtered[0]->package_name); |
| 66 } | 66 } |
| 67 | 67 |
| 68 { | 68 { |
| 69 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 69 std::vector<mojom::IntentHandlerInfoPtr> orig; |
| 70 orig.push_back(mojom::IntentHandlerInfo::New()); | 70 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 71 orig[0]->name = "0"; | 71 orig[0]->name = "0"; |
| 72 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 72 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
| 73 orig.push_back(mojom::IntentHandlerInfo::New()); | 73 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 74 orig[1]->name = "1"; | 74 orig[1]->name = "1"; |
| 75 orig[1]->package_name = "package_name1"; | 75 orig[1]->package_name = "package_name1"; |
| 76 orig.push_back(mojom::IntentHandlerInfo::New()); | 76 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 77 orig[2]->name = "2"; | 77 orig[2]->name = "2"; |
| 78 orig[2]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 78 orig[2]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
| 79 | 79 |
| 80 // FilterOutIntentHelper should remove two elements. | 80 // FilterOutIntentHelper should remove two elements. |
| 81 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 81 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
| 82 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 82 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
| 83 ASSERT_EQ(1U, filtered.size()); | 83 ASSERT_EQ(1U, filtered.size()); |
| 84 EXPECT_EQ("1", filtered[0]->name); | 84 EXPECT_EQ("1", filtered[0]->name); |
| 85 EXPECT_EQ("package_name1", filtered[0]->package_name); | 85 EXPECT_EQ("package_name1", filtered[0]->package_name); |
| 86 } | 86 } |
| 87 | 87 |
| 88 { | 88 { |
| 89 mojo::Array<mojom::IntentHandlerInfoPtr> orig; | 89 std::vector<mojom::IntentHandlerInfoPtr> orig; |
| 90 orig.push_back(mojom::IntentHandlerInfo::New()); | 90 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 91 orig[0]->name = "0"; | 91 orig[0]->name = "0"; |
| 92 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 92 orig[0]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
| 93 orig.push_back(mojom::IntentHandlerInfo::New()); | 93 orig.push_back(mojom::IntentHandlerInfo::New()); |
| 94 orig[1]->name = "1"; | 94 orig[1]->name = "1"; |
| 95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
| 96 | 96 |
| 97 // FilterOutIntentHelper should remove all elements. | 97 // FilterOutIntentHelper should remove all elements. |
| 98 mojo::Array<mojom::IntentHandlerInfoPtr> filtered = | 98 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
| 99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
| 100 EXPECT_EQ(0U, filtered.size()); | 100 EXPECT_EQ(0U, filtered.size()); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace arc | 104 } // namespace arc |
| OLD | NEW |