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

Side by Side Diff: components/arc/intent_helper/arc_intent_helper_bridge_unittest.cc

Issue 2487623002: Notify Files App when ARC++ app is installed/removed (Closed)
Patch Set: Addressed comments. Created 4 years 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
OLDNEW
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()
22 : icon_loader_(new ActivityIconLoader()),
hidehiko 2016/11/29 15:29:30 Optional: How about put these into SetUp()/TearDow
oka 2016/11/30 07:22:16 Done.
23 activity_resolver_(new LocalActivityResolver()) {}
24
25 protected:
26 std::unique_ptr<FakeArcBridgeService> fake_arc_bridge_service_;
hidehiko 2016/11/29 15:29:30 Could you kindly sort the order in the initializat
oka 2016/11/30 07:22:15 Done.
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());
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 };
hidehiko 2016/11/29 15:29:30 Could you add: DISALLOW_COPY_AND_ASSIGN(ArcIntent
oka 2016/11/30 07:22:15 Done.
43
44 } // namespace
45
14 // Tests if IsIntentHelperPackage works as expected. Probably too trivial 46 // Tests if IsIntentHelperPackage works as expected. Probably too trivial
15 // to test but just in case. 47 // to test but just in case.
16 TEST(ArcIntentHelperTest, TestIsIntentHelperPackage) { 48 TEST_F(ArcIntentHelperTest, TestIsIntentHelperPackage) {
17 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage("")); 49 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage(""));
18 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( 50 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage(
19 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a"))); 51 ArcIntentHelperBridge::kArcIntentHelperPackageName + std::string("a")));
20 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage( 52 EXPECT_FALSE(ArcIntentHelperBridge::IsIntentHelperPackage(
21 ArcIntentHelperBridge::kArcIntentHelperPackageName + 53 ArcIntentHelperBridge::kArcIntentHelperPackageName +
22 std::string("/.ArcIntentHelperActivity"))); 54 std::string("/.ArcIntentHelperActivity")));
23 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage( 55 EXPECT_TRUE(ArcIntentHelperBridge::IsIntentHelperPackage(
24 ArcIntentHelperBridge::kArcIntentHelperPackageName)); 56 ArcIntentHelperBridge::kArcIntentHelperPackageName));
25 } 57 }
26 58
27 // Tests if FilterOutIntentHelper removes handlers as expected. 59 // Tests if FilterOutIntentHelper removes handlers as expected.
28 TEST(ArcIntentHelperTest, TestFilterOutIntentHelper) { 60 TEST_F(ArcIntentHelperTest, TestFilterOutIntentHelper) {
29 { 61 {
30 std::vector<mojom::IntentHandlerInfoPtr> orig; 62 std::vector<mojom::IntentHandlerInfoPtr> orig;
31 std::vector<mojom::IntentHandlerInfoPtr> filtered = 63 std::vector<mojom::IntentHandlerInfoPtr> filtered =
32 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); 64 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig));
33 EXPECT_EQ(0U, filtered.size()); 65 EXPECT_EQ(0U, filtered.size());
34 } 66 }
35 67
36 { 68 {
37 std::vector<mojom::IntentHandlerInfoPtr> orig; 69 std::vector<mojom::IntentHandlerInfoPtr> orig;
38 orig.push_back(mojom::IntentHandlerInfo::New()); 70 orig.push_back(mojom::IntentHandlerInfo::New());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 orig[1]->name = "1"; 126 orig[1]->name = "1";
95 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName; 127 orig[1]->package_name = ArcIntentHelperBridge::kArcIntentHelperPackageName;
96 128
97 // FilterOutIntentHelper should remove all elements. 129 // FilterOutIntentHelper should remove all elements.
98 std::vector<mojom::IntentHandlerInfoPtr> filtered = 130 std::vector<mojom::IntentHandlerInfoPtr> filtered =
99 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig)); 131 ArcIntentHelperBridge::FilterOutIntentHelper(std::move(orig));
100 EXPECT_EQ(0U, filtered.size()); 132 EXPECT_EQ(0U, filtered.size());
101 } 133 }
102 } 134 }
103 135
136 // Tests if observer works as expected.
137 TEST_F(ArcIntentHelperTest, TestObserver) {
138 struct FakeObserver : public ArcIntentHelperObserver {
hidehiko 2016/11/29 15:29:30 Could you use class, instead? https://google.githu
oka 2016/11/30 07:22:15 Done.
139 public:
140 FakeObserver() : updated_(false) {}
hidehiko 2016/11/29 15:29:30 You can initialize the member at declaration. Fak
oka 2016/11/30 07:22:16 Done.
141 void OnAppsUpdated() override { updated_ = true; }
142 bool updated_;
hidehiko 2016/11/29 15:29:30 the field should be private. https://google.github
oka 2016/11/30 07:22:16 Done.
143 };
144
145 // Observer should be called when intent filter is updated.
hidehiko 2016/11/29 15:29:30 Nice description!
oka 2016/11/30 07:22:15 Done.
146 std::unique_ptr<FakeObserver> observer(new FakeObserver());
hidehiko 2016/11/29 15:29:30 Optional: auto observer = base::MakeUnique<FakeOb
oka 2016/11/30 07:22:15 Done.
147 instance_->AddObserver(observer.get());
148 std::vector<mojom::IntentFilterPtr> v;
hidehiko 2016/11/29 15:29:30 Optional: I think you can inline the vector. EXC
oka 2016/11/30 07:22:15 Done.
149 EXPECT_FALSE(observer->updated_);
150 instance_->OnIntentFiltersUpdated(std::move(v));
151 EXPECT_TRUE(observer->updated_);
152
153 // Observer should not be called after it's removed.
154 observer->updated_ = false;
155 instance_->RemoveObserver(observer.get());
156 std::vector<mojom::IntentFilterPtr> v2;
157 instance_->OnIntentFiltersUpdated(std::move(v2));
158 EXPECT_FALSE(observer->updated_);
159 }
160
104 } // namespace arc 161 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/intent_helper/arc_intent_helper_bridge.cc ('k') | components/arc/intent_helper/arc_intent_helper_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698