| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "chrome/common/extensions/features/feature_channel.h" | 7 #include "chrome/common/extensions/features/feature_channel.h" |
| 8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 8 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 9 #include "extensions/common/error_utils.h" | 9 #include "extensions/common/error_utils.h" |
| 10 #include "extensions/common/manifest_constants.h" | 10 #include "extensions/common/manifest_constants.h" |
| 11 #include "extensions/common/manifest_handlers/externally_connectable.h" | 11 #include "extensions/common/manifest_handlers/externally_connectable.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 using testing::ElementsAre; | 16 using testing::ElementsAre; |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 namespace errors = externally_connectable_errors; | 20 namespace errors = externally_connectable_errors; |
| 20 | 21 |
| 21 class ExternallyConnectableTest : public ExtensionManifestTest { | 22 class ExternallyConnectableTest : public ExtensionManifestTest { |
| 22 public: | 23 public: |
| 23 ExternallyConnectableTest() : channel_(chrome::VersionInfo::CHANNEL_DEV) {} | 24 ExternallyConnectableTest() : channel_(chrome::VersionInfo::CHANNEL_DEV) {} |
| 24 | 25 |
| 25 protected: | 26 protected: |
| 26 ExternallyConnectableInfo* GetExternallyConnectableInfo( | 27 ExternallyConnectableInfo* GetExternallyConnectableInfo( |
| 27 scoped_refptr<Extension> extension) { | 28 scoped_refptr<Extension> extension) { |
| 28 return static_cast<ExternallyConnectableInfo*>( | 29 return static_cast<ExternallyConnectableInfo*>( |
| 29 extension->GetManifestData(manifest_keys::kExternallyConnectable)); | 30 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
| 30 } | 31 } |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 ScopedCurrentChannel channel_; | 34 ScopedCurrentChannel channel_; |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 TEST_F(ExternallyConnectableTest, IDsAndMatches) { | 37 TEST_F(ExternallyConnectableTest, IDsAndMatches) { |
| 37 scoped_refptr<Extension> extension = | 38 scoped_refptr<Extension> extension = |
| 38 LoadAndExpectSuccess("externally_connectable_ids_and_matches.json"); | 39 LoadAndExpectSuccess("externally_connectable_ids_and_matches.json"); |
| 39 ASSERT_TRUE(extension.get()); | 40 ASSERT_TRUE(extension.get()); |
| 40 | 41 |
| 41 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 42 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 43 APIPermission::kWebConnectable)); |
| 42 | 44 |
| 43 ExternallyConnectableInfo* info = | 45 ExternallyConnectableInfo* info = |
| 44 ExternallyConnectableInfo::Get(extension.get()); | 46 ExternallyConnectableInfo::Get(extension.get()); |
| 45 ASSERT_TRUE(info); | 47 ASSERT_TRUE(info); |
| 46 | 48 |
| 47 EXPECT_THAT(info->ids, | 49 EXPECT_THAT(info->ids, |
| 48 ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 50 ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
| 49 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 51 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
| 50 | 52 |
| 51 EXPECT_FALSE(info->all_ids); | 53 EXPECT_FALSE(info->all_ids); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://no.wildcard.path/"))); | 94 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://no.wildcard.path/"))); |
| 93 EXPECT_FALSE( | 95 EXPECT_FALSE( |
| 94 info->matches.MatchesURL(GURL("http://no.wildcard.path/index.html"))); | 96 info->matches.MatchesURL(GURL("http://no.wildcard.path/index.html"))); |
| 95 } | 97 } |
| 96 | 98 |
| 97 TEST_F(ExternallyConnectableTest, IDs) { | 99 TEST_F(ExternallyConnectableTest, IDs) { |
| 98 scoped_refptr<Extension> extension = | 100 scoped_refptr<Extension> extension = |
| 99 LoadAndExpectSuccess("externally_connectable_ids.json"); | 101 LoadAndExpectSuccess("externally_connectable_ids.json"); |
| 100 ASSERT_TRUE(extension.get()); | 102 ASSERT_TRUE(extension.get()); |
| 101 | 103 |
| 102 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 104 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission( |
| 105 APIPermission::kWebConnectable)); |
| 103 | 106 |
| 104 ExternallyConnectableInfo* info = | 107 ExternallyConnectableInfo* info = |
| 105 ExternallyConnectableInfo::Get(extension.get()); | 108 ExternallyConnectableInfo::Get(extension.get()); |
| 106 ASSERT_TRUE(info); | 109 ASSERT_TRUE(info); |
| 107 | 110 |
| 108 EXPECT_THAT(info->ids, | 111 EXPECT_THAT(info->ids, |
| 109 ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 112 ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
| 110 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 113 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
| 111 | 114 |
| 112 EXPECT_FALSE(info->all_ids); | 115 EXPECT_FALSE(info->all_ids); |
| 113 | 116 |
| 114 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); | 117 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://google.com/index.html"))); |
| 115 } | 118 } |
| 116 | 119 |
| 117 TEST_F(ExternallyConnectableTest, Matches) { | 120 TEST_F(ExternallyConnectableTest, Matches) { |
| 118 scoped_refptr<Extension> extension = | 121 scoped_refptr<Extension> extension = |
| 119 LoadAndExpectSuccess("externally_connectable_matches.json"); | 122 LoadAndExpectSuccess("externally_connectable_matches.json"); |
| 120 ASSERT_TRUE(extension.get()); | 123 ASSERT_TRUE(extension.get()); |
| 121 | 124 |
| 122 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 125 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 126 APIPermission::kWebConnectable)); |
| 123 | 127 |
| 124 ExternallyConnectableInfo* info = | 128 ExternallyConnectableInfo* info = |
| 125 ExternallyConnectableInfo::Get(extension.get()); | 129 ExternallyConnectableInfo::Get(extension.get()); |
| 126 ASSERT_TRUE(info); | 130 ASSERT_TRUE(info); |
| 127 | 131 |
| 128 EXPECT_THAT(info->ids, ElementsAre()); | 132 EXPECT_THAT(info->ids, ElementsAre()); |
| 129 | 133 |
| 130 EXPECT_FALSE(info->all_ids); | 134 EXPECT_FALSE(info->all_ids); |
| 131 | 135 |
| 132 EXPECT_FALSE(info->accepts_tls_channel_id); | 136 EXPECT_FALSE(info->accepts_tls_channel_id); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 154 | 158 |
| 155 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com"))); | 159 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com"))); |
| 156 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com/"))); | 160 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://yahoo.com/"))); |
| 157 } | 161 } |
| 158 | 162 |
| 159 TEST_F(ExternallyConnectableTest, MatchesWithTlsChannelId) { | 163 TEST_F(ExternallyConnectableTest, MatchesWithTlsChannelId) { |
| 160 scoped_refptr<Extension> extension = LoadAndExpectSuccess( | 164 scoped_refptr<Extension> extension = LoadAndExpectSuccess( |
| 161 "externally_connectable_matches_tls_channel_id.json"); | 165 "externally_connectable_matches_tls_channel_id.json"); |
| 162 ASSERT_TRUE(extension.get()); | 166 ASSERT_TRUE(extension.get()); |
| 163 | 167 |
| 164 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 168 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 169 APIPermission::kWebConnectable)); |
| 165 | 170 |
| 166 ExternallyConnectableInfo* info = | 171 ExternallyConnectableInfo* info = |
| 167 ExternallyConnectableInfo::Get(extension.get()); | 172 ExternallyConnectableInfo::Get(extension.get()); |
| 168 ASSERT_TRUE(info); | 173 ASSERT_TRUE(info); |
| 169 | 174 |
| 170 EXPECT_THAT(info->ids, ElementsAre()); | 175 EXPECT_THAT(info->ids, ElementsAre()); |
| 171 | 176 |
| 172 EXPECT_FALSE(info->all_ids); | 177 EXPECT_FALSE(info->all_ids); |
| 173 | 178 |
| 174 EXPECT_TRUE(info->accepts_tls_channel_id); | 179 EXPECT_TRUE(info->accepts_tls_channel_id); |
| 175 | 180 |
| 176 // The matches portion of the manifest is identical to those in | 181 // The matches portion of the manifest is identical to those in |
| 177 // externally_connectable_matches, so only a subset of the Matches tests is | 182 // externally_connectable_matches, so only a subset of the Matches tests is |
| 178 // repeated here. | 183 // repeated here. |
| 179 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); | 184 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://example.com"))); |
| 180 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); | 185 EXPECT_FALSE(info->matches.MatchesURL(GURL("http://example.com/index.html"))); |
| 181 } | 186 } |
| 182 | 187 |
| 183 TEST_F(ExternallyConnectableTest, AllIDs) { | 188 TEST_F(ExternallyConnectableTest, AllIDs) { |
| 184 scoped_refptr<Extension> extension = | 189 scoped_refptr<Extension> extension = |
| 185 LoadAndExpectSuccess("externally_connectable_all_ids.json"); | 190 LoadAndExpectSuccess("externally_connectable_all_ids.json"); |
| 186 ASSERT_TRUE(extension.get()); | 191 ASSERT_TRUE(extension.get()); |
| 187 | 192 |
| 188 EXPECT_FALSE(extension->HasAPIPermission(APIPermission::kWebConnectable)); | 193 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission( |
| 194 APIPermission::kWebConnectable)); |
| 189 | 195 |
| 190 ExternallyConnectableInfo* info = | 196 ExternallyConnectableInfo* info = |
| 191 ExternallyConnectableInfo::Get(extension.get()); | 197 ExternallyConnectableInfo::Get(extension.get()); |
| 192 ASSERT_TRUE(info); | 198 ASSERT_TRUE(info); |
| 193 | 199 |
| 194 EXPECT_THAT(info->ids, | 200 EXPECT_THAT(info->ids, |
| 195 ElementsAre("abcdefghijklmnopabcdefghijklmnop", | 201 ElementsAre("abcdefghijklmnopabcdefghijklmnop", |
| 196 "ponmlkjihgfedcbaponmlkjihgfedcba")); | 202 "ponmlkjihgfedcbaponmlkjihgfedcba")); |
| 197 | 203 |
| 198 EXPECT_TRUE(info->all_ids); | 204 EXPECT_TRUE(info->all_ids); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); | 312 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); |
| 307 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); | 313 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); |
| 308 } | 314 } |
| 309 | 315 |
| 310 TEST_F(ExternallyConnectableTest, WarningNothingSpecified) { | 316 TEST_F(ExternallyConnectableTest, WarningNothingSpecified) { |
| 311 LoadAndExpectWarning("externally_connectable_nothing_specified.json", | 317 LoadAndExpectWarning("externally_connectable_nothing_specified.json", |
| 312 errors::kErrorNothingSpecified); | 318 errors::kErrorNothingSpecified); |
| 313 } | 319 } |
| 314 | 320 |
| 315 } // namespace extensions | 321 } // namespace extensions |
| OLD | NEW |