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