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/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 mojom::IntentFilterPtr GetIntentFilter(const std::string& host) { | 18 IntentFilter GetIntentFilter(const std::string& host) { |
19 mojom::IntentFilterPtr filter = mojom::IntentFilter::New(); | 19 std::vector<IntentFilter::AuthorityEntry> authorities; |
20 mojom::AuthorityEntryPtr authority_entry = mojom::AuthorityEntry::New(); | 20 authorities.emplace_back(host, -1); |
21 authority_entry->host = host; | 21 |
22 authority_entry->port = -1; | 22 return IntentFilter(std::move(authorities), |
23 filter->data_authorities = std::vector<mojom::AuthorityEntryPtr>(); | 23 std::vector<IntentFilter::PatternMatcher>()); |
24 filter->data_authorities->push_back(std::move(authority_entry)); | |
25 return filter; | |
26 } | 24 } |
27 | 25 |
28 } // namespace | 26 } // namespace |
29 | 27 |
30 // Tests that ShouldChromeHandleUrl returns true by default. | 28 // Tests that ShouldChromeHandleUrl returns true by default. |
31 TEST(LocalActivityResolverTest, TestDefault) { | 29 TEST(LocalActivityResolverTest, TestDefault) { |
32 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); | 30 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); |
33 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); | 31 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); |
34 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); | 32 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); |
35 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("file:///etc/password"))); | 33 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("file:///etc/password"))); |
36 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://help"))); | 34 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://help"))); |
37 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("about://chrome"))); | 35 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("about://chrome"))); |
38 } | 36 } |
39 | 37 |
40 // Tests that ShouldChromeHandleUrl returns false when there's a match. | 38 // Tests that ShouldChromeHandleUrl returns false when there's a match. |
41 TEST(LocalActivityResolverTest, TestSingleFilter) { | 39 TEST(LocalActivityResolverTest, TestSingleFilter) { |
42 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); | 40 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); |
43 | 41 |
44 std::vector<mojom::IntentFilterPtr> array; | 42 std::vector<IntentFilter> array; |
45 array.push_back(GetIntentFilter("www.google.com")); | 43 array.emplace_back(GetIntentFilter("www.google.com")); |
46 resolver->UpdateIntentFilters(std::move(array)); | 44 resolver->UpdateIntentFilters(std::move(array)); |
47 | 45 |
48 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); | 46 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); |
49 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); | 47 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); |
50 | 48 |
51 EXPECT_TRUE( | 49 EXPECT_TRUE( |
52 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); | 50 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); |
53 } | 51 } |
54 | 52 |
55 // Tests the same with multiple filters. | 53 // Tests the same with multiple filters. |
56 TEST(LocalActivityResolverTest, TestMultipleFilters) { | 54 TEST(LocalActivityResolverTest, TestMultipleFilters) { |
57 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); | 55 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); |
58 | 56 |
59 std::vector<mojom::IntentFilterPtr> array; | 57 std::vector<IntentFilter> array; |
60 array.push_back(GetIntentFilter("www.google.com")); | 58 array.emplace_back(GetIntentFilter("www.google.com")); |
61 array.push_back(GetIntentFilter("www.google.co.uk")); | 59 array.emplace_back(GetIntentFilter("www.google.co.uk")); |
62 array.push_back(GetIntentFilter("dev.chromium.org")); | 60 array.emplace_back(GetIntentFilter("dev.chromium.org")); |
63 resolver->UpdateIntentFilters(std::move(array)); | 61 resolver->UpdateIntentFilters(std::move(array)); |
64 | 62 |
65 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); | 63 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); |
66 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); | 64 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); |
67 EXPECT_FALSE( | 65 EXPECT_FALSE( |
68 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); | 66 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); |
69 EXPECT_FALSE( | 67 EXPECT_FALSE( |
70 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); | 68 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); |
71 EXPECT_FALSE( | 69 EXPECT_FALSE( |
72 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); | 70 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); |
73 EXPECT_FALSE( | 71 EXPECT_FALSE( |
74 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); | 72 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); |
75 | 73 |
76 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); | 74 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); |
77 } | 75 } |
78 | 76 |
79 // Tests that ShouldChromeHandleUrl returns true for non http(s) URLs. | 77 // Tests that ShouldChromeHandleUrl returns true for non http(s) URLs. |
80 TEST(LocalActivityResolverTest, TestNonHttp) { | 78 TEST(LocalActivityResolverTest, TestNonHttp) { |
81 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); | 79 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); |
82 | 80 |
83 std::vector<mojom::IntentFilterPtr> array; | 81 std::vector<IntentFilter> array; |
84 array.push_back(GetIntentFilter("www.google.com")); | 82 array.emplace_back(GetIntentFilter("www.google.com")); |
85 resolver->UpdateIntentFilters(std::move(array)); | 83 resolver->UpdateIntentFilters(std::move(array)); |
86 | 84 |
87 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://www.google.com"))); | 85 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://www.google.com"))); |
88 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("custom://www.google.com"))); | 86 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("custom://www.google.com"))); |
89 } | 87 } |
90 | 88 |
91 // Tests that ShouldChromeHandleUrl discards the previous filters when | 89 // Tests that ShouldChromeHandleUrl discards the previous filters when |
92 // UpdateIntentFilters is called with new ones. | 90 // UpdateIntentFilters is called with new ones. |
93 TEST(LocalActivityResolverTest, TestMultipleUpdate) { | 91 TEST(LocalActivityResolverTest, TestMultipleUpdate) { |
94 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); | 92 scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); |
95 | 93 |
96 std::vector<mojom::IntentFilterPtr> array; | 94 std::vector<IntentFilter> array; |
97 array.push_back(GetIntentFilter("www.google.com")); | 95 array.emplace_back(GetIntentFilter("www.google.com")); |
98 array.push_back(GetIntentFilter("dev.chromium.org")); | 96 array.emplace_back(GetIntentFilter("dev.chromium.org")); |
99 resolver->UpdateIntentFilters(std::move(array)); | 97 resolver->UpdateIntentFilters(std::move(array)); |
100 | 98 |
101 std::vector<mojom::IntentFilterPtr> array2; | 99 std::vector<IntentFilter> array2; |
102 array2.push_back(GetIntentFilter("www.google.co.uk")); | 100 array2.emplace_back(GetIntentFilter("www.google.co.uk")); |
103 array2.push_back(GetIntentFilter("dev.chromium.org")); | 101 array2.emplace_back(GetIntentFilter("dev.chromium.org")); |
104 array2.push_back(GetIntentFilter("www.android.com")); | 102 array2.emplace_back(GetIntentFilter("www.android.com")); |
105 resolver->UpdateIntentFilters(std::move(array2)); | 103 resolver->UpdateIntentFilters(std::move(array2)); |
106 | 104 |
107 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); | 105 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); |
108 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); | 106 EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); |
109 EXPECT_FALSE( | 107 EXPECT_FALSE( |
110 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); | 108 resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); |
111 EXPECT_FALSE( | 109 EXPECT_FALSE( |
112 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); | 110 resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); |
113 EXPECT_FALSE( | 111 EXPECT_FALSE( |
114 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); | 112 resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); |
115 EXPECT_FALSE( | 113 EXPECT_FALSE( |
116 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); | 114 resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); |
117 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); | 115 EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); |
118 EXPECT_FALSE( | 116 EXPECT_FALSE( |
119 resolver->ShouldChromeHandleUrl(GURL("https://www.android.com"))); | 117 resolver->ShouldChromeHandleUrl(GURL("https://www.android.com"))); |
120 } | 118 } |
121 | 119 |
122 } // namespace arc | 120 } // namespace arc |
OLD | NEW |