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

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 7003098: Start refractoring extension permissions into ExtensionPermissionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and update ExtensionPermissionSet data model. Created 9 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 24 matching lines...) Expand all
35 35
36 void CompareLists(const std::vector<std::string>& expected, 36 void CompareLists(const std::vector<std::string>& expected,
37 const std::vector<std::string>& actual) { 37 const std::vector<std::string>& actual) {
38 ASSERT_EQ(expected.size(), actual.size()); 38 ASSERT_EQ(expected.size(), actual.size());
39 39
40 for (size_t i = 0; i < expected.size(); ++i) { 40 for (size_t i = 0; i < expected.size(); ++i) {
41 EXPECT_EQ(expected[i], actual[i]); 41 EXPECT_EQ(expected[i], actual[i]);
42 } 42 }
43 } 43 }
44 44
45 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
46 int schemes = URLPattern::SCHEME_ALL;
47 extent->AddPattern(URLPattern(schemes, pattern));
48 }
49
50 static scoped_refptr<Extension> LoadManifestUnchecked( 45 static scoped_refptr<Extension> LoadManifestUnchecked(
51 const std::string& dir, 46 const std::string& dir,
52 const std::string& test_file, 47 const std::string& test_file,
53 Extension::Location location, 48 Extension::Location location,
54 int extra_flags, 49 int extra_flags,
55 std::string* error) { 50 std::string* error) {
56 FilePath path; 51 FilePath path;
57 PathService::Get(chrome::DIR_TEST_DATA, &path); 52 PathService::Get(chrome::DIR_TEST_DATA, &path);
58 path = path.AppendASCII("extensions") 53 path = path.AppendASCII("extensions")
59 .AppendASCII(dir) 54 .AppendASCII(dir)
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 hosts = extension->GetEffectiveHostPermissions(); 382 hosts = extension->GetEffectiveHostPermissions();
388 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); 383 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com")));
389 EXPECT_TRUE(hosts.MatchesURL(GURL("https://google.com"))); 384 EXPECT_TRUE(hosts.MatchesURL(GURL("https://google.com")));
390 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 385 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
391 386
392 extension = LoadManifest("effective_host_permissions", 387 extension = LoadManifest("effective_host_permissions",
393 "two_content_scripts.json"); 388 "two_content_scripts.json");
394 hosts = extension->GetEffectiveHostPermissions(); 389 hosts = extension->GetEffectiveHostPermissions();
395 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); 390 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com")));
396 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); 391 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com")));
392 EXPECT_TRUE(extension->permission_set()->HasEffectiveAccessToHost(
393 GURL("http://www.reddit.com")));
397 EXPECT_TRUE(hosts.MatchesURL(GURL("http://news.ycombinator.com"))); 394 EXPECT_TRUE(hosts.MatchesURL(GURL("http://news.ycombinator.com")));
395 EXPECT_TRUE(extension->permission_set()->HasEffectiveAccessToHost(
396 GURL("http://news.ycombinator.com")));
398 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts()); 397 EXPECT_FALSE(extension->HasEffectiveAccessToAllHosts());
399 398
400 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); 399 extension = LoadManifest("effective_host_permissions", "all_hosts.json");
401 hosts = extension->GetEffectiveHostPermissions(); 400 hosts = extension->GetEffectiveHostPermissions();
402 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); 401 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/")));
403 EXPECT_FALSE(hosts.MatchesURL(GURL("https://test/"))); 402 EXPECT_FALSE(hosts.MatchesURL(GURL("https://test/")));
404 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 403 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com")));
405 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 404 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts());
406 405
407 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); 406 extension = LoadManifest("effective_host_permissions", "all_hosts2.json");
408 hosts = extension->GetEffectiveHostPermissions(); 407 hosts = extension->GetEffectiveHostPermissions();
409 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); 408 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/")));
410 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 409 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com")));
411 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 410 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts());
412 411
413 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); 412 extension = LoadManifest("effective_host_permissions", "all_hosts3.json");
414 hosts = extension->GetEffectiveHostPermissions(); 413 hosts = extension->GetEffectiveHostPermissions();
415 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); 414 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/")));
416 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); 415 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/")));
417 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); 416 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com")));
418 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 417 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts());
419 } 418 }
420 419
421 TEST(ExtensionTest, IsPrivilegeIncrease) {
422 const struct {
423 const char* base_name;
424 // Increase these sizes if you have more than 10.
425 const char* granted_apis[10];
426 const char* granted_hosts[10];
427 bool full_access;
428 bool expect_increase;
429 } kTests[] = {
430 { "allhosts1", {NULL}, {"http://*/", NULL}, false,
431 false }, // all -> all
432 { "allhosts2", {NULL}, {"http://*/", NULL}, false,
433 false }, // all -> one
434 { "allhosts3", {NULL}, {NULL}, false, true }, // one -> all
435 { "hosts1", {NULL},
436 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false,
437 false }, // http://a,http://b -> http://a,http://b
438 { "hosts2", {NULL},
439 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false,
440 true }, // http://a,http://b -> https://a,http://*.b
441 { "hosts3", {NULL},
442 {"http://www.google.com/", "http://www.reddit.com/", NULL}, false,
443 false }, // http://a,http://b -> http://a
444 { "hosts4", {NULL},
445 {"http://www.google.com/", NULL}, false,
446 true }, // http://a -> http://a,http://b
447 { "hosts5", {"tabs", "notifications", NULL},
448 {"http://*.example.com/", "http://*.example.com/*",
449 "http://*.example.co.uk/*", "http://*.example.com.au/*",
450 NULL}, false,
451 false }, // http://a,b,c -> http://a,b,c + https://a,b,c
452 { "hosts6", {"tabs", "notifications", NULL},
453 {"http://*.example.com/", "http://*.example.com/*", NULL}, false,
454 false }, // http://a.com -> http://a.com + http://a.co.uk
455 { "permissions1", {"tabs", NULL},
456 {NULL}, false, false }, // tabs -> tabs
457 { "permissions2", {"tabs", NULL},
458 {NULL}, false, true }, // tabs -> tabs,bookmarks
459 { "permissions3", {NULL},
460 {"http://*/*", NULL},
461 false, true }, // http://a -> http://a,tabs
462 { "permissions5", {"bookmarks", NULL},
463 {NULL}, false, true }, // bookmarks -> bookmarks,history
464 #if !defined(OS_CHROMEOS) // plugins aren't allowed in ChromeOS
465 { "permissions4", {NULL},
466 {NULL}, true, false }, // plugin -> plugin,tabs
467 { "plugin1", {NULL},
468 {NULL}, true, false }, // plugin -> plugin
469 { "plugin2", {NULL},
470 {NULL}, true, false }, // plugin -> none
471 { "plugin3", {NULL},
472 {NULL}, false, true }, // none -> plugin
473 #endif
474 { "storage", {NULL},
475 {NULL}, false, false }, // none -> storage
476 { "notifications", {NULL},
477 {NULL}, false, false } // none -> notifications
478 };
479
480 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
481 scoped_refptr<Extension> old_extension(
482 LoadManifest("allow_silent_upgrade",
483 std::string(kTests[i].base_name) + "_old.json"));
484 scoped_refptr<Extension> new_extension(
485 LoadManifest("allow_silent_upgrade",
486 std::string(kTests[i].base_name) + "_new.json"));
487
488 std::set<std::string> granted_apis;
489 for (size_t j = 0; kTests[i].granted_apis[j] != NULL; ++j)
490 granted_apis.insert(kTests[i].granted_apis[j]);
491
492 URLPatternSet granted_hosts;
493 for (size_t j = 0; kTests[i].granted_hosts[j] != NULL; ++j)
494 AddPattern(&granted_hosts, kTests[i].granted_hosts[j]);
495
496 EXPECT_TRUE(new_extension.get()) << kTests[i].base_name << "_new.json";
497 if (!new_extension.get())
498 continue;
499
500 EXPECT_EQ(kTests[i].expect_increase,
501 Extension::IsPrivilegeIncrease(kTests[i].full_access,
502 granted_apis,
503 granted_hosts,
504 new_extension.get()))
505 << kTests[i].base_name;
506 }
507 }
508
509 TEST(ExtensionTest, PermissionMessages) {
510 // Ensure that all permissions that needs to show install UI actually have
511 // strings associated with them.
512
513 std::set<std::string> skip;
514
515 // These are considered "nuisance" or "trivial" permissions that don't need
516 // a prompt.
517 skip.insert(Extension::kContextMenusPermission);
518 skip.insert(Extension::kIdlePermission);
519 skip.insert(Extension::kNotificationPermission);
520 skip.insert(Extension::kUnlimitedStoragePermission);
521 skip.insert(Extension::kContentSettingsPermission);
522
523 // TODO(erikkay) add a string for this permission.
524 skip.insert(Extension::kBackgroundPermission);
525
526 skip.insert(Extension::kClipboardWritePermission);
527
528 // The cookie permission does nothing unless you have associated host
529 // permissions.
530 skip.insert(Extension::kCookiePermission);
531
532 // The proxy permission is warned as part of host permission checks.
533 skip.insert(Extension::kProxyPermission);
534
535 // This permission requires explicit user action (context menu handler)
536 // so we won't prompt for it for now.
537 skip.insert(Extension::kFileBrowserHandlerPermission);
538
539 // If you've turned on the experimental command-line flag, we don't need
540 // to warn you further.
541 skip.insert(Extension::kExperimentalPermission);
542
543 // These are private.
544 skip.insert(Extension::kWebstorePrivatePermission);
545 skip.insert(Extension::kFileBrowserPrivatePermission);
546 skip.insert(Extension::kMediaPlayerPrivatePermission);
547 skip.insert(Extension::kChromePrivatePermission);
548 skip.insert(Extension::kChromeosInfoPrivatePermission);
549 skip.insert(Extension::kWebSocketProxyPrivatePermission);
550
551 const Extension::PermissionMessage::MessageId ID_NONE =
552 Extension::PermissionMessage::ID_NONE;
553
554 for (size_t i = 0; i < Extension::kNumPermissions; ++i) {
555 Extension::Permission permission = Extension::kPermissions[i];
556 if (skip.count(permission.name)) {
557 EXPECT_EQ(ID_NONE, permission.message_id)
558 << "unexpected message_id for " << permission.name;
559 } else {
560 EXPECT_NE(ID_NONE, permission.message_id)
561 << "missing message_id for " << permission.name;
562 }
563 }
564 }
565
566 // Returns a copy of |source| resized to |size| x |size|. 420 // Returns a copy of |source| resized to |size| x |size|.
567 static SkBitmap ResizedCopy(const SkBitmap& source, int size) { 421 static SkBitmap ResizedCopy(const SkBitmap& source, int size) {
568 return skia::ImageOperations::Resize(source, 422 return skia::ImageOperations::Resize(source,
569 skia::ImageOperations::RESIZE_LANCZOS3, 423 skia::ImageOperations::RESIZE_LANCZOS3,
570 size, 424 size,
571 size); 425 size);
572 } 426 }
573 427
574 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) { 428 static bool SizeEquals(const SkBitmap& bitmap, const gfx::Size& size) {
575 return bitmap.width() == size.width() && bitmap.height() == size.height(); 429 return bitmap.width() == size.width() && bitmap.height() == size.height();
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 EXPECT_TRUE(Allowed(extension, http_url)); 751 EXPECT_TRUE(Allowed(extension, http_url));
898 EXPECT_TRUE(Blocked(extension, https_url)); 752 EXPECT_TRUE(Blocked(extension, https_url));
899 EXPECT_TRUE(Blocked(extension, file_url)); 753 EXPECT_TRUE(Blocked(extension, file_url));
900 EXPECT_TRUE(Blocked(extension, settings_url)); 754 EXPECT_TRUE(Blocked(extension, settings_url));
901 EXPECT_TRUE(Blocked(extension, favicon_url)); 755 EXPECT_TRUE(Blocked(extension, favicon_url));
902 EXPECT_TRUE(Blocked(extension, about_url)); 756 EXPECT_TRUE(Blocked(extension, about_url));
903 EXPECT_TRUE(Blocked(extension, extension_url)); 757 EXPECT_TRUE(Blocked(extension, extension_url));
904 EXPECT_FALSE(extension->HasHostPermission(settings_url)); 758 EXPECT_FALSE(extension->HasHostPermission(settings_url));
905 } 759 }
906 760
907 TEST(ExtensionTest, GetDistinctHostsForDisplay) {
908 std::vector<std::string> expected;
909 expected.push_back("www.foo.com");
910 expected.push_back("www.bar.com");
911 expected.push_back("www.baz.com");
912 URLPatternList actual;
913
914 {
915 SCOPED_TRACE("no dupes");
916
917 // Simple list with no dupes.
918 actual.push_back(
919 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
920 actual.push_back(
921 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/path"));
922 actual.push_back(
923 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
924 CompareLists(expected,
925 Extension::GetDistinctHostsForDisplay(actual));
926 }
927
928 {
929 SCOPED_TRACE("two dupes");
930
931 // Add some dupes.
932 actual.push_back(
933 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
934 actual.push_back(
935 URLPattern(URLPattern::SCHEME_HTTP, "http://www.baz.com/path"));
936 CompareLists(expected,
937 Extension::GetDistinctHostsForDisplay(actual));
938 }
939
940 {
941 SCOPED_TRACE("schemes differ");
942
943 // Add a pattern that differs only by scheme. This should be filtered out.
944 actual.push_back(
945 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.bar.com/path"));
946 CompareLists(expected,
947 Extension::GetDistinctHostsForDisplay(actual));
948 }
949
950 {
951 SCOPED_TRACE("paths differ");
952
953 // Add some dupes by path.
954 actual.push_back(
955 URLPattern(URLPattern::SCHEME_HTTP, "http://www.bar.com/pathypath"));
956 CompareLists(expected,
957 Extension::GetDistinctHostsForDisplay(actual));
958 }
959
960 {
961 SCOPED_TRACE("subdomains differ");
962
963 // We don't do anything special for subdomains.
964 actual.push_back(
965 URLPattern(URLPattern::SCHEME_HTTP, "http://monkey.www.bar.com/path"));
966 actual.push_back(
967 URLPattern(URLPattern::SCHEME_HTTP, "http://bar.com/path"));
968
969 expected.push_back("monkey.www.bar.com");
970 expected.push_back("bar.com");
971
972 CompareLists(expected,
973 Extension::GetDistinctHostsForDisplay(actual));
974 }
975
976 {
977 SCOPED_TRACE("RCDs differ");
978
979 // Now test for RCD uniquing.
980 actual.push_back(
981 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
982 actual.push_back(
983 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
984 actual.push_back(
985 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.de/path"));
986 actual.push_back(
987 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca.us/path"));
988 actual.push_back(
989 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
990 actual.push_back(
991 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com.my/path"));
992
993 // This is an unknown RCD, which shouldn't be uniqued out.
994 actual.push_back(
995 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
996 // But it should only occur once.
997 actual.push_back(
998 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.xyzzy/path"));
999
1000 expected.push_back("www.foo.xyzzy");
1001
1002 CompareLists(expected,
1003 Extension::GetDistinctHostsForDisplay(actual));
1004 }
1005
1006 {
1007 SCOPED_TRACE("wildcards");
1008
1009 actual.push_back(
1010 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*"));
1011
1012 expected.push_back("*.google.com");
1013
1014 CompareLists(expected,
1015 Extension::GetDistinctHostsForDisplay(actual));
1016 }
1017 }
1018
1019 TEST(ExtensionTest, GetDistinctHostsForDisplay_ComIsBestRcd) {
1020 URLPatternList actual;
1021 actual.push_back(
1022 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1023 actual.push_back(
1024 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1025 actual.push_back(
1026 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1027 actual.push_back(
1028 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
1029 actual.push_back(
1030 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1031 actual.push_back(
1032 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.com/path"));
1033
1034 std::vector<std::string> expected;
1035 expected.push_back("www.foo.com");
1036
1037 CompareLists(expected,
1038 Extension::GetDistinctHostsForDisplay(actual));
1039 }
1040
1041 TEST(ExtensionTest, GetDistinctHostsForDisplay_NetIs2ndBestRcd) {
1042 URLPatternList actual;
1043 actual.push_back(
1044 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1045 actual.push_back(
1046 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1047 actual.push_back(
1048 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1049 actual.push_back(
1050 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.net/path"));
1051 actual.push_back(
1052 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1053 // No http://www.foo.com/path
1054
1055 std::vector<std::string> expected;
1056 expected.push_back("www.foo.net");
1057
1058 CompareLists(expected,
1059 Extension::GetDistinctHostsForDisplay(actual));
1060 }
1061
1062 TEST(ExtensionTest, GetDistinctHostsForDisplay_OrgIs3rdBestRcd) {
1063 URLPatternList actual;
1064 actual.push_back(
1065 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1066 actual.push_back(
1067 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.org/path"));
1068 actual.push_back(
1069 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1070 // No http://www.foo.net/path
1071 actual.push_back(
1072 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1073 // No http://www.foo.com/path
1074
1075 std::vector<std::string> expected;
1076 expected.push_back("www.foo.org");
1077
1078 CompareLists(expected,
1079 Extension::GetDistinctHostsForDisplay(actual));
1080 }
1081
1082 TEST(ExtensionTest, GetDistinctHostsForDisplay_FirstInListIs4thBestRcd) {
1083 URLPatternList actual;
1084 actual.push_back(
1085 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.ca/path"));
1086 // No http://www.foo.org/path
1087 actual.push_back(
1088 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.co.uk/path"));
1089 // No http://www.foo.net/path
1090 actual.push_back(
1091 URLPattern(URLPattern::SCHEME_HTTP, "http://www.foo.jp/path"));
1092 // No http://www.foo.com/path
1093
1094 std::vector<std::string> expected;
1095 expected.push_back("www.foo.ca");
1096
1097 CompareLists(expected,
1098 Extension::GetDistinctHostsForDisplay(actual));
1099 }
1100
1101 TEST(ExtensionTest, IsElevatedHostList) {
1102 URLPatternList list1;
1103 URLPatternList list2;
1104
1105 list1.push_back(
1106 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
1107 list1.push_back(
1108 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1109
1110 // Test that the host order does not matter.
1111 list2.push_back(
1112 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1113 list2.push_back(
1114 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path"));
1115
1116 EXPECT_FALSE(Extension::IsElevatedHostList(list1, list2));
1117 EXPECT_FALSE(Extension::IsElevatedHostList(list2, list1));
1118
1119 // Test that paths are ignored.
1120 list2.clear();
1121 list2.push_back(
1122 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*"));
1123 EXPECT_FALSE(Extension::IsElevatedHostList(list1, list2));
1124 EXPECT_FALSE(Extension::IsElevatedHostList(list2, list1));
1125
1126 // Test that RCDs are ignored.
1127 list2.clear();
1128 list2.push_back(
1129 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*"));
1130 EXPECT_FALSE(Extension::IsElevatedHostList(list1, list2));
1131 EXPECT_FALSE(Extension::IsElevatedHostList(list2, list1));
1132
1133 // Test that subdomain wildcards are handled properly.
1134 list2.clear();
1135 list2.push_back(
1136 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*"));
1137 EXPECT_TRUE(Extension::IsElevatedHostList(list1, list2));
1138 //TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337
1139 //EXPECT_FALSE(Extension::IsElevatedHostList(list2, list1));
1140
1141 // Test that different domains count as different hosts.
1142 list2.clear();
1143 list2.push_back(
1144 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path"));
1145 list2.push_back(
1146 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path"));
1147 EXPECT_TRUE(Extension::IsElevatedHostList(list1, list2));
1148 EXPECT_FALSE(Extension::IsElevatedHostList(list2, list1));
1149
1150 // Test that different subdomains count as different hosts.
1151 list2.clear();
1152 list2.push_back(
1153 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*"));
1154 EXPECT_TRUE(Extension::IsElevatedHostList(list1, list2));
1155 EXPECT_TRUE(Extension::IsElevatedHostList(list2, list1));
1156 }
1157
1158 TEST(ExtensionTest, GenerateId) { 761 TEST(ExtensionTest, GenerateId) {
1159 std::string result; 762 std::string result;
1160 EXPECT_TRUE(Extension::GenerateId("", &result)); 763 EXPECT_TRUE(Extension::GenerateId("", &result));
1161 764
1162 EXPECT_TRUE(Extension::GenerateId("test", &result)); 765 EXPECT_TRUE(Extension::GenerateId("test", &result));
1163 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); 766 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
1164 767
1165 EXPECT_TRUE(Extension::GenerateId("_", &result)); 768 EXPECT_TRUE(Extension::GenerateId("_", &result));
1166 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); 769 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
1167 770
1168 EXPECT_TRUE(Extension::GenerateId( 771 EXPECT_TRUE(Extension::GenerateId(
1169 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); 772 "this_string_is_longer_than_a_single_sha256_hash_digest", &result));
1170 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); 773 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi");
1171 } 774 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698