OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
Yusuke Sato
2016/11/28 19:24:54
Thanks for adding the test!
oka
2016/11/29 06:56:49
Acknowledged.
| |
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 #include <vector> | |
Yusuke Sato
2016/11/28 19:24:54
This is already in arc_intent_helper_bridge.h. Rem
oka
2016/11/29 06:56:49
Done.
| |
8 | 9 |
10 #include "base/memory/ptr_util.h" | |
Yusuke Sato
2016/11/28 19:24:54
What is this for?
oka
2016/11/29 06:56:49
Removed.
| |
9 #include "components/arc/common/intent_helper.mojom.h" | 11 #include "components/arc/common/intent_helper.mojom.h" |
12 #include "components/arc/intent_helper/activity_icon_loader.h" | |
13 #include "components/arc/intent_helper/local_activity_resolver.h" | |
14 #include "components/arc/test/fake_arc_bridge_service.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
11 | 16 |
12 namespace arc { | 17 namespace arc { |
13 | 18 |
19 class ArcIntentHelperTest : public testing::Test { | |
Yusuke Sato
2016/11/28 19:24:54
Please put this in an anonymous namespace.
names
oka
2016/11/29 06:56:49
Done.
| |
20 public: | |
21 ArcIntentHelperTest() | |
22 : icon_loader_(new ActivityIconLoader), | |
Yusuke Sato
2016/11/28 19:24:54
nit: could you add ()? IIUC, Chromium folks are tr
oka
2016/11/29 06:56:49
Done.
| |
23 activity_resolver_(new LocalActivityResolver) {} | |
Yusuke Sato
2016/11/28 19:24:54
same
oka
2016/11/29 06:56:49
Done.
| |
24 | |
25 protected: | |
26 std::unique_ptr<FakeArcBridgeService> fake_arc_bridge_service_; | |
27 scoped_refptr<ActivityIconLoader> icon_loader_; | |
28 scoped_refptr<LocalActivityResolver> activity_resolver_; | |
29 std::unique_ptr<ArcIntentHelperBridge> instance_; | |
30 | |
31 private: | |
32 void SetUp() override { | |
33 fake_arc_bridge_service_.reset(new FakeArcBridgeService); | |
Yusuke Sato
2016/11/28 19:24:54
same
oka
2016/11/29 06:56:49
Done.
| |
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 fake_arc_bridge_service_.reset(); | |
41 } | |
42 }; | |
43 | |
14 // Tests if IsIntentHelperPackage works as expected. Probably too trivial | 44 // Tests if IsIntentHelperPackage works as expected. Probably too trivial |
15 // to test but just in case. | 45 // to test but just in case. |
16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { | 46 TEST_F(ArcIntentHelperTest, TestIsIntentHelperPackage) { |
17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); | 47 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); |
18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 48 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); | 49 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); |
20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( | 50 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( |
21 ArcIntentHelperBridge::kArcIntentHelperPackageName + | 51 ArcIntentHelperBridge::kArcIntentHelperPackageName + |
22 std::string("/.ArcIntentHelperActivity"))); | 52 std::string("/.ArcIntentHelperActivity"))); |
23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( | 53 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( |
24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); | 54 ArcIntentHelperBridge::kArcIntentHelperPackageName)); |
25 } | 55 } |
26 | 56 |
27 // Tests if FilterOutIntentHelper removes handlers as expected. | 57 // Tests if FilterOutIntentHelper removes handlers as expected. |
28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { | 58 TEST_F(ArcIntentHelperTest, TestFilterOutIntentHelper) { |
29 { | 59 { |
30 std::vector<mojom::IntentHandlerInfoPtr> orig; | 60 std::vector<mojom::IntentHandlerInfoPtr> orig; |
31 std::vector<mojom::IntentHandlerInfoPtr> filtered = | 61 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 62 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
33 EXPECT_EQ(0U, filtered.size()); | 63 EXPECT_EQ(0U, filtered.size()); |
34 } | 64 } |
35 | 65 |
36 { | 66 { |
37 std::vector<mojom::IntentHandlerInfoPtr> orig; | 67 std::vector<mojom::IntentHandlerInfoPtr> orig; |
38 orig.push_back(mojom::IntentHandlerInfo::New()); | 68 orig.push_back(mojom::IntentHandlerInfo::New()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 orig[1]->name = "1"; | 124 orig[1]->name = "1"; |
95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; | 125 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; |
96 | 126 |
97 // FilterOutIntentHelper should remove all elements. | 127 // FilterOutIntentHelper should remove all elements. |
98 std::vector<mojom::IntentHandlerInfoPtr> filtered = | 128 std::vector<mojom::IntentHandlerInfoPtr> filtered = |
99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); | 129 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); |
100 EXPECT_EQ(0U, filtered.size()); | 130 EXPECT_EQ(0U, filtered.size()); |
101 } | 131 } |
102 } | 132 } |
103 | 133 |
134 // Tests if observer is called when intent filter is updated. | |
135 TEST_F(ArcIntentHelperTest, TestObserverIsCalled) { | |
136 struct FakeObserver : public ArcIntentHelperObserver { | |
137 public: | |
138 FakeObserver() : updated_(false) {} | |
139 void OnAppsUpdated() override { updated_ = true; } | |
140 bool updated_; | |
141 }; | |
142 | |
143 std::unique_ptr<FakeObserver> observer(new FakeObserver); | |
Yusuke Sato
2016/11/28 19:24:54
same
oka
2016/11/29 06:56:49
Done.
| |
144 instance_->AddObserver(observer.get()); | |
145 std::vector<mojom::IntentFilterPtr> v; | |
146 instance_->OnIntentFiltersUpdated(std::move(v)); | |
Yusuke Sato
2016/11/28 19:24:54
nit: I'd add EXPECT_FALSE() call between L145&146.
oka
2016/11/29 06:56:49
Done.
| |
147 | |
148 EXPECT_TRUE(observer->updated_); | |
149 } | |
Yusuke Sato
2016/11/28 19:24:54
Can you also do
observer->updated_ = false; //
oka
2016/11/29 06:56:49
Done.
| |
150 | |
104 } // namespace arc | 151 } // namespace arc |
OLD | NEW |