| 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 "extensions/common/error_utils.h" | 7 #include "extensions/common/error_utils.h" |
| 8 #include "extensions/common/manifest_constants.h" | 8 #include "extensions/common/manifest_constants.h" |
| 9 #include "extensions/common/manifest_handlers/externally_connectable.h" | 9 #include "extensions/common/manifest_handlers/externally_connectable.h" |
| 10 #include "extensions/common/manifest_test.h" | 10 #include "extensions/common/manifest_test.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ErrorUtils::FormatErrorMessage( | 246 ErrorUtils::FormatErrorMessage( |
| 247 errors::kErrorInvalidMatchPattern, "www.yahoo.com")); | 247 errors::kErrorInvalidMatchPattern, "www.yahoo.com")); |
| 248 } | 248 } |
| 249 | 249 |
| 250 TEST_F(ExternallyConnectableTest, WarningNoAllURLs) { | 250 TEST_F(ExternallyConnectableTest, WarningNoAllURLs) { |
| 251 scoped_refptr<Extension> extension = LoadAndExpectWarning( | 251 scoped_refptr<Extension> extension = LoadAndExpectWarning( |
| 252 "externally_connectable_error_all_urls.json", | 252 "externally_connectable_error_all_urls.json", |
| 253 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, | 253 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, |
| 254 "<all_urls>")); | 254 "<all_urls>")); |
| 255 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); | 255 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); |
| 256 EXPECT_FALSE(info->matches.MatchesAllURLs()); |
| 256 EXPECT_FALSE(info->matches.ContainsPattern( | 257 EXPECT_FALSE(info->matches.ContainsPattern( |
| 257 URLPattern(URLPattern::SCHEME_ALL, "<all_urls>"))); | 258 URLPattern(URLPattern::SCHEME_ALL, "<all_urls>"))); |
| 258 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); | 259 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); |
| 259 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); | 260 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); |
| 260 } | 261 } |
| 261 | 262 |
| 263 TEST_F(ExternallyConnectableTest, AllURLsNotWhitelisted) { |
| 264 scoped_refptr<Extension> extension = LoadAndExpectSuccess( |
| 265 "externally_connectable_all_urls_not_whitelisted.json"); |
| 266 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); |
| 267 EXPECT_FALSE(info->matches.MatchesAllURLs()); |
| 268 } |
| 269 |
| 270 TEST_F(ExternallyConnectableTest, AllURLsWhitelisted) { |
| 271 scoped_refptr<Extension> extension = |
| 272 LoadAndExpectSuccess("externally_connectable_all_urls_whitelisted.json"); |
| 273 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); |
| 274 EXPECT_TRUE(info->matches.MatchesAllURLs()); |
| 275 URLPattern pattern(URLPattern::SCHEME_ALL, "<all_urls>"); |
| 276 EXPECT_TRUE(info->matches.ContainsPattern(pattern)); |
| 277 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); |
| 278 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); |
| 279 } |
| 280 |
| 262 TEST_F(ExternallyConnectableTest, WarningWildcardHost) { | 281 TEST_F(ExternallyConnectableTest, WarningWildcardHost) { |
| 263 scoped_refptr<Extension> extension = LoadAndExpectWarning( | 282 scoped_refptr<Extension> extension = LoadAndExpectWarning( |
| 264 "externally_connectable_error_wildcard_host.json", | 283 "externally_connectable_error_wildcard_host.json", |
| 265 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, | 284 ErrorUtils::FormatErrorMessage(errors::kErrorWildcardHostsNotAllowed, |
| 266 "http://*/*")); | 285 "http://*/*")); |
| 267 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); | 286 ExternallyConnectableInfo* info = GetExternallyConnectableInfo(extension); |
| 268 EXPECT_FALSE(info->matches.ContainsPattern( | 287 EXPECT_FALSE(info->matches.ContainsPattern( |
| 269 URLPattern(URLPattern::SCHEME_ALL, "http://*/*"))); | 288 URLPattern(URLPattern::SCHEME_ALL, "http://*/*"))); |
| 270 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); | 289 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); |
| 271 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); | 290 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); | 328 EXPECT_TRUE(info->matches.MatchesURL(GURL("https://example.com"))); |
| 310 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); | 329 EXPECT_TRUE(info->matches.MatchesURL(GURL("http://build.chromium.org"))); |
| 311 } | 330 } |
| 312 | 331 |
| 313 TEST_F(ExternallyConnectableTest, WarningNothingSpecified) { | 332 TEST_F(ExternallyConnectableTest, WarningNothingSpecified) { |
| 314 LoadAndExpectWarning("externally_connectable_nothing_specified.json", | 333 LoadAndExpectWarning("externally_connectable_nothing_specified.json", |
| 315 errors::kErrorNothingSpecified); | 334 errors::kErrorNothingSpecified); |
| 316 } | 335 } |
| 317 | 336 |
| 318 } // namespace extensions | 337 } // namespace extensions |
| OLD | NEW |