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

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

Issue 2557703002: Revert of Use mojo typemaps to simplify arc::IntentFilter::IntentFilter() (Closed)
Patch Set: 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
« no previous file with comments | « components/arc/intent_helper/local_activity_resolver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/local_activity_resolver.h" 5 #include "components/arc/intent_helper/local_activity_resolver.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "components/arc/intent_helper/intent_filter.h" 10 #include "components/arc/intent_helper/intent_filter.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 13
14 namespace arc { 14 namespace arc {
15 15
16 namespace { 16 namespace {
17 17
18 IntentFilter GetIntentFilter(const std::string& host) { 18 mojom::IntentFilterPtr GetIntentFilter(const std::string& host) {
19 std::vector<IntentFilter::AuthorityEntry> authorities; 19 mojom::IntentFilterPtr filter = mojom::IntentFilter::New();
20 authorities.emplace_back(host, -1); 20 mojom::AuthorityEntryPtr authority_entry = mojom::AuthorityEntry::New();
21 21 authority_entry->host = host;
22 return IntentFilter(std::move(authorities), {}); 22 authority_entry->port = -1;
23 filter->data_authorities = std::vector<mojom::AuthorityEntryPtr>();
24 filter->data_authorities->push_back(std::move(authority_entry));
25 return filter;
23 } 26 }
24 27
25 } // namespace 28 } // namespace
26 29
27 // Tests that ShouldChromeHandleUrl returns true by default. 30 // Tests that ShouldChromeHandleUrl returns true by default.
28 TEST(LocalActivityResolverTest, TestDefault) { 31 TEST(LocalActivityResolverTest, TestDefault) {
29 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); 32 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver());
30 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); 33 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com")));
31 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); 34 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com")));
32 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("file:///etc/password"))); 35 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("file:///etc/password")));
33 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://help"))); 36 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://help")));
34 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("about://chrome"))); 37 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("about://chrome")));
35 } 38 }
36 39
37 // Tests that ShouldChromeHandleUrl returns false when there's a match. 40 // Tests that ShouldChromeHandleUrl returns false when there's a match.
38 TEST(LocalActivityResolverTest, TestSingleFilter) { 41 TEST(LocalActivityResolverTest, TestSingleFilter) {
39 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); 42 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver());
40 43
41 std::vector<IntentFilter> array; 44 std::vector<mojom::IntentFilterPtr> array;
42 array.emplace_back(GetIntentFilter("www.google.com")); 45 array.push_back(GetIntentFilter("www.google.com"));
43 resolver->UpdateIntentFilters(std::move(array)); 46 resolver->UpdateIntentFilters(std::move(array));
44 47
45 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); 48 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com")));
46 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); 49 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com")));
47 50
48 EXPECT_TRUE( 51 EXPECT_TRUE(
49 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); 52 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk")));
50 } 53 }
51 54
52 // Tests the same with multiple filters. 55 // Tests the same with multiple filters.
53 TEST(LocalActivityResolverTest, TestMultipleFilters) { 56 TEST(LocalActivityResolverTest, TestMultipleFilters) {
54 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); 57 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver());
55 58
56 std::vector<IntentFilter> array; 59 std::vector<mojom::IntentFilterPtr> array;
57 array.emplace_back(GetIntentFilter("www.google.com")); 60 array.push_back(GetIntentFilter("www.google.com"));
58 array.emplace_back(GetIntentFilter("www.google.co.uk")); 61 array.push_back(GetIntentFilter("www.google.co.uk"));
59 array.emplace_back(GetIntentFilter("dev.chromium.org")); 62 array.push_back(GetIntentFilter("dev.chromium.org"));
60 resolver->UpdateIntentFilters(std::move(array)); 63 resolver->UpdateIntentFilters(std::move(array));
61 64
62 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); 65 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com")));
63 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); 66 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com")));
64 EXPECT_FALSE( 67 EXPECT_FALSE(
65 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); 68 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk")));
66 EXPECT_FALSE( 69 EXPECT_FALSE(
67 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); 70 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk")));
68 EXPECT_FALSE( 71 EXPECT_FALSE(
69 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); 72 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org")));
70 EXPECT_FALSE( 73 EXPECT_FALSE(
71 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); 74 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org")));
72 75
73 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); 76 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com")));
74 } 77 }
75 78
76 // Tests that ShouldChromeHandleUrl returns true for non http(s) URLs. 79 // Tests that ShouldChromeHandleUrl returns true for non http(s) URLs.
77 TEST(LocalActivityResolverTest, TestNonHttp) { 80 TEST(LocalActivityResolverTest, TestNonHttp) {
78 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); 81 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver());
79 82
80 std::vector<IntentFilter> array; 83 std::vector<mojom::IntentFilterPtr> array;
81 array.emplace_back(GetIntentFilter("www.google.com")); 84 array.push_back(GetIntentFilter("www.google.com"));
82 resolver->UpdateIntentFilters(std::move(array)); 85 resolver->UpdateIntentFilters(std::move(array));
83 86
84 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://www.google.com"))); 87 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://www.google.com")));
85 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("custom://www.google.com"))); 88 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("custom://www.google.com")));
86 } 89 }
87 90
88 // Tests that ShouldChromeHandleUrl discards the previous filters when 91 // Tests that ShouldChromeHandleUrl discards the previous filters when
89 // UpdateIntentFilters is called with new ones. 92 // UpdateIntentFilters is called with new ones.
90 TEST(LocalActivityResolverTest, TestMultipleUpdate) { 93 TEST(LocalActivityResolverTest, TestMultipleUpdate) {
91 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); 94 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver());
92 95
93 std::vector<IntentFilter> array; 96 std::vector<mojom::IntentFilterPtr> array;
94 array.emplace_back(GetIntentFilter("www.google.com")); 97 array.push_back(GetIntentFilter("www.google.com"));
95 array.emplace_back(GetIntentFilter("dev.chromium.org")); 98 array.push_back(GetIntentFilter("dev.chromium.org"));
96 resolver->UpdateIntentFilters(std::move(array)); 99 resolver->UpdateIntentFilters(std::move(array));
97 100
98 std::vector<IntentFilter> array2; 101 std::vector<mojom::IntentFilterPtr> array2;
99 array2.emplace_back(GetIntentFilter("www.google.co.uk")); 102 array2.push_back(GetIntentFilter("www.google.co.uk"));
100 array2.emplace_back(GetIntentFilter("dev.chromium.org")); 103 array2.push_back(GetIntentFilter("dev.chromium.org"));
101 array2.emplace_back(GetIntentFilter("www.android.com")); 104 array2.push_back(GetIntentFilter("www.android.com"));
102 resolver->UpdateIntentFilters(std::move(array2)); 105 resolver->UpdateIntentFilters(std::move(array2));
103 106
104 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); 107 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com")));
105 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); 108 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com")));
106 EXPECT_FALSE( 109 EXPECT_FALSE(
107 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); 110 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk")));
108 EXPECT_FALSE( 111 EXPECT_FALSE(
109 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); 112 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk")));
110 EXPECT_FALSE( 113 EXPECT_FALSE(
111 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); 114 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org")));
112 EXPECT_FALSE( 115 EXPECT_FALSE(
113 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); 116 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org")));
114 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); 117 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com")));
115 EXPECT_FALSE( 118 EXPECT_FALSE(
116 resolver->ShouldChromeHandleUrl(GURL("https://www.android.com"))); 119 resolver->ShouldChromeHandleUrl(GURL("https://www.android.com")));
117 } 120 }
118 121
119 } // namespace arc 122 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/intent_helper/local_activity_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698