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 "components/arc/intent_helper/activity_icon_loader.h" |
| 11 #include "components/arc/intent_helper/local_activity_resolver.h" |
| 12 #include "components/arc/test/fake_arc_bridge_service.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
11 | 14 |
12 namespace arc { | 15 namespace arc { |
13 | 16 |
| 17 namespace { |
| 18 |
| 19 class ArcIntentHelperTest : public testing::Test { |
| 20 public: |
| 21 ArcIntentHelperTest() = default; |
| 22 |
| 23 protected: |
| 24 std::unique_ptr<FakeArcBridgeService> fake_arc_bridge_service_; |
| 25 scoped_refptr<ActivityIconLoader> icon_loader_; |
| 26 scoped_refptr<LocalActivityResolver> activity_resolver_; |
| 27 std::unique_ptr<ArcIntentHelperBridge> instance_; |
| 28 |
| 29 private: |
| 30 void SetUp() override { |
| 31 fake_arc_bridge_service_.reset(new FakeArcBridgeService()); |
| 32 icon_loader_ = new ActivityIconLoader(); |
| 33 activity_resolver_ = new LocalActivityResolver(); |
| 34 instance_.reset(new ArcIntentHelperBridge( |
| 35 fake_arc_bridge_service_.get(), icon_loader_, activity_resolver_)); |
| 36 } |
| 37 |
| 38 void TearDown() override { |
| 39 instance_.reset(); |
| 40 activity_resolver_ = nullptr; |
| 41 icon_loader_ = nullptr; |
| 42 fake_arc_bridge_service_.reset(); |
| 43 } |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(ArcIntentHelperTest); |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
14 // Tests if IsIntentHelperPackage works as expected. Probably too trivial | 50 // Tests if IsIntentHelperPackage works as expected. Probably too trivial |
15 // to test but just in case. | 51 // to test but just in case. |
16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { | 52 TEST_F(ArcIntentHelperTest, TestIsIntentHelperPackage) { |
17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); | 53 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); |
18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 54 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); | 55 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); |
20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 56 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
21 ArcIntentHelperBridge::kArcIntentHelperPackageName + | 57 ArcIntentHelperBridge::kArcIntentHelperPackageName + |
22 std::string("/.ArcIntentHelperActivity"))); | 58 std::string("/.ArcIntentHelperActivity"))); |
23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( | 59 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( |
24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); | 60 ArcIntentHelperBridge::kArcIntentHelperPackageName)); |
25 } | 61 } |
26 | 62 |
27 // Tests if FilterOutIntentHelper removes handlers as expected. | 63 // Tests if FilterOutIntentHelper removes handlers as expected. |
28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { | 64 TEST_F(ArcIntentHelperTest, TestFilterOutIntentHelper) { |
29 { | 65 { |
30 std::vector<mojom::IntentHandlerInfoPtr> orig; | 66 std::vector<mojom::IntentHandlerInfoPtr> orig; |
31 std::vector<mojom::IntentHandlerInfoPtr> filtered = | 67 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 68 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
33 EXPECT_EQ(0U, filtered.size()); | 69 EXPECT_EQ(0U, filtered.size()); |
34 } | 70 } |
35 | 71 |
36 { | 72 { |
37 std::vector<mojom::IntentHandlerInfoPtr> orig; | 73 std::vector<mojom::IntentHandlerInfoPtr> orig; |
38 orig.push_back(mojom::IntentHandlerInfo::New()); | 74 orig.push_back(mojom::IntentHandlerInfo::New()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 orig[1]->name = "1"; | 130 orig[1]->name = "1"; |
95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 131 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
96 | 132 |
97 // FilterOutIntentHelper should remove all elements. | 133 // FilterOutIntentHelper should remove all elements. |
98 std::vector<mojom::IntentHandlerInfoPtr> filtered = | 134 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 135 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
100 EXPECT_EQ(0U, filtered.size()); | 136 EXPECT_EQ(0U, filtered.size()); |
101 } | 137 } |
102 } | 138 } |
103 | 139 |
| 140 // Tests if observer works as expected. |
| 141 TEST_F(ArcIntentHelperTest, TestObserver) { |
| 142 class FakeObserver : public ArcIntentHelperObserver { |
| 143 public: |
| 144 FakeObserver() = default; |
| 145 void OnAppsUpdated() override { updated_ = true; } |
| 146 bool IsUpdated() { return updated_; } |
| 147 void Reset() { updated_ = false; } |
| 148 |
| 149 private: |
| 150 bool updated_ = false; |
| 151 }; |
| 152 |
| 153 // Observer should be called when intent filter is updated. |
| 154 auto observer = base::MakeUnique<FakeObserver>(); |
| 155 instance_->AddObserver(observer.get()); |
| 156 EXPECT_FALSE(observer->IsUpdated()); |
| 157 instance_->OnIntentFiltersUpdated(std::vector<mojom::IntentFilterPtr>()); |
| 158 EXPECT_TRUE(observer->IsUpdated()); |
| 159 |
| 160 // Observer should not be called after it's removed. |
| 161 observer->Reset(); |
| 162 instance_->RemoveObserver(observer.get()); |
| 163 instance_->OnIntentFiltersUpdated(std::vector<mojom::IntentFilterPtr>()); |
| 164 EXPECT_FALSE(observer->IsUpdated()); |
| 165 } |
| 166 |
104 } // namespace arc | 167 } // namespace arc |
OLD | NEW |