Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: extensions/common/manifest_handlers/externally_connectable_unittest.cc

Issue 599163003: Add whitelist for extensions to put <all_urls> in externally_connectable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed permission warnings unittest Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « extensions/common/manifest_handlers/externally_connectable.cc ('k') | extensions/common/permissions/api_permission.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698