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