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

Side by Side Diff: chrome/common/extensions/api/extension_api_unittest.cc

Issue 641363003: Convert ARRAYSIZE_UNSAFE -> arraysize in chrome/, outside of chrome/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | chrome/common/extensions/command_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extensions/common/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 struct { 51 struct {
52 ExtensionAPI* api; 52 ExtensionAPI* api;
53 bool expect_populated; 53 bool expect_populated;
54 } test_data[] = { 54 } test_data[] = {
55 { shared_instance, true }, 55 { shared_instance, true },
56 { new_instance.get(), true }, 56 { new_instance.get(), true },
57 { &empty_instance, false } 57 { &empty_instance, false }
58 }; 58 };
59 59
60 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 60 for (size_t i = 0; i < arraysize(test_data); ++i) {
61 EXPECT_EQ(test_data[i].expect_populated, 61 EXPECT_EQ(test_data[i].expect_populated,
62 test_data[i].api->GetSchema("bookmarks.create") != NULL); 62 test_data[i].api->GetSchema("bookmarks.create") != NULL);
63 } 63 }
64 } 64 }
65 65
66 TEST(ExtensionAPITest, SplitDependencyName) { 66 TEST(ExtensionAPITest, SplitDependencyName) {
67 struct { 67 struct {
68 std::string input; 68 std::string input;
69 std::string expected_feature_type; 69 std::string expected_feature_type;
70 std::string expected_feature_name; 70 std::string expected_feature_name;
71 } test_data[] = {{"", "api", ""}, // assumes "api" when no type is present 71 } test_data[] = {{"", "api", ""}, // assumes "api" when no type is present
72 {"foo", "api", "foo"}, 72 {"foo", "api", "foo"},
73 {"foo:", "foo", ""}, 73 {"foo:", "foo", ""},
74 {":foo", "", "foo"}, 74 {":foo", "", "foo"},
75 {"foo:bar", "foo", "bar"}, 75 {"foo:bar", "foo", "bar"},
76 {"foo:bar.baz", "foo", "bar.baz"}}; 76 {"foo:bar.baz", "foo", "bar.baz"}};
77 77
78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 78 for (size_t i = 0; i < arraysize(test_data); ++i) {
79 std::string feature_type; 79 std::string feature_type;
80 std::string feature_name; 80 std::string feature_name;
81 ExtensionAPI::SplitDependencyName( 81 ExtensionAPI::SplitDependencyName(
82 test_data[i].input, &feature_type, &feature_name); 82 test_data[i].input, &feature_type, &feature_name);
83 EXPECT_EQ(test_data[i].expected_feature_type, feature_type) << i; 83 EXPECT_EQ(test_data[i].expected_feature_type, feature_type) << i;
84 EXPECT_EQ(test_data[i].expected_feature_name, feature_name) << i; 84 EXPECT_EQ(test_data[i].expected_feature_name, feature_name) << i;
85 } 85 }
86 } 86 }
87 87
88 TEST(ExtensionAPITest, IsAvailableInUntrustedContext) { 88 TEST(ExtensionAPITest, IsAvailableInUntrustedContext) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 ASSERT_TRUE(base::ReadFileToString( 163 ASSERT_TRUE(base::ReadFileToString(
164 api_features_path, &api_features_str)) << "privileged_api_features.json"; 164 api_features_path, &api_features_str)) << "privileged_api_features.json";
165 165
166 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( 166 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
167 base::JSONReader::Read(api_features_str))); 167 base::JSONReader::Read(api_features_str)));
168 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); 168 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature);
169 169
170 scoped_refptr<Extension> extension = 170 scoped_refptr<Extension> extension =
171 BuildExtension(ExtensionBuilder().Pass()).Build(); 171 BuildExtension(ExtensionBuilder().Pass()).Build();
172 172
173 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 173 for (size_t i = 0; i < arraysize(test_data); ++i) {
174 ExtensionAPI api; 174 ExtensionAPI api;
175 api.RegisterDependencyProvider("api", &api_feature_provider); 175 api.RegisterDependencyProvider("api", &api_feature_provider);
176 EXPECT_EQ(test_data[i].expect_is_available, 176 EXPECT_EQ(test_data[i].expect_is_available,
177 api.IsAvailableInUntrustedContext(test_data[i].api_full_name, 177 api.IsAvailableInUntrustedContext(test_data[i].api_full_name,
178 extension.get())) 178 extension.get()))
179 << i; 179 << i;
180 } 180 }
181 } 181 }
182 182
183 TEST(ExtensionAPITest, APIFeatures) { 183 TEST(ExtensionAPITest, APIFeatures) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 .AppendASCII("api_features.json"); 261 .AppendASCII("api_features.json");
262 262
263 std::string api_features_str; 263 std::string api_features_str;
264 ASSERT_TRUE(base::ReadFileToString( 264 ASSERT_TRUE(base::ReadFileToString(
265 api_features_path, &api_features_str)) << "api_features.json"; 265 api_features_path, &api_features_str)) << "api_features.json";
266 266
267 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( 267 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
268 base::JSONReader::Read(api_features_str))); 268 base::JSONReader::Read(api_features_str)));
269 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); 269 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature);
270 270
271 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 271 for (size_t i = 0; i < arraysize(test_data); ++i) {
272 ExtensionAPI api; 272 ExtensionAPI api;
273 api.RegisterDependencyProvider("api", &api_feature_provider); 273 api.RegisterDependencyProvider("api", &api_feature_provider);
274 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); 274 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd();
275 iter.Advance()) { 275 iter.Advance()) {
276 if (iter.key().find(".") == std::string::npos) 276 if (iter.key().find(".") == std::string::npos)
277 api.RegisterSchemaResource(iter.key(), 0); 277 api.RegisterSchemaResource(iter.key(), 0);
278 } 278 }
279 279
280 ExtensionAPI::OverrideSharedInstanceForTest scope(&api); 280 ExtensionAPI::OverrideSharedInstanceForTest scope(&api);
281 bool expected = test_data[i].expect_is_available; 281 bool expected = test_data[i].expect_is_available;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 .AppendASCII("api_features.json"); 341 .AppendASCII("api_features.json");
342 342
343 std::string api_features_str; 343 std::string api_features_str;
344 ASSERT_TRUE(base::ReadFileToString( 344 ASSERT_TRUE(base::ReadFileToString(
345 api_features_path, &api_features_str)) << "api_features.json"; 345 api_features_path, &api_features_str)) << "api_features.json";
346 346
347 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>( 347 scoped_ptr<base::DictionaryValue> value(static_cast<base::DictionaryValue*>(
348 base::JSONReader::Read(api_features_str))); 348 base::JSONReader::Read(api_features_str)));
349 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature); 349 BaseFeatureProvider api_feature_provider(*value, CreateAPIFeature);
350 350
351 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 351 for (size_t i = 0; i < arraysize(test_data); ++i) {
352 ExtensionAPI api; 352 ExtensionAPI api;
353 api.RegisterDependencyProvider("api", &api_feature_provider); 353 api.RegisterDependencyProvider("api", &api_feature_provider);
354 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd(); 354 for (base::DictionaryValue::Iterator iter(*value); !iter.IsAtEnd();
355 iter.Advance()) { 355 iter.Advance()) {
356 if (iter.key().find(".") == std::string::npos) 356 if (iter.key().find(".") == std::string::npos)
357 api.RegisterSchemaResource(iter.key(), 0); 357 api.RegisterSchemaResource(iter.key(), 0);
358 } 358 }
359 359
360 Feature* test_feature = 360 Feature* test_feature =
361 api_feature_provider.GetFeature(test_data[i].api_full_name); 361 api_feature_provider.GetFeature(test_data[i].api_full_name);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 { "bookmarks.", "bookmarks", "" }, 704 { "bookmarks.", "bookmarks", "" },
705 { ".bookmarks", "", "" }, 705 { ".bookmarks", "", "" },
706 { "bookmarks.create", "bookmarks", "create" }, 706 { "bookmarks.create", "bookmarks", "create" },
707 { "bookmarks.create.", "bookmarks", "create." }, 707 { "bookmarks.create.", "bookmarks", "create." },
708 { "bookmarks.create.monkey", "bookmarks", "create.monkey" }, 708 { "bookmarks.create.monkey", "bookmarks", "create.monkey" },
709 { "bookmarkManagerPrivate", "bookmarkManagerPrivate", "" }, 709 { "bookmarkManagerPrivate", "bookmarkManagerPrivate", "" },
710 { "bookmarkManagerPrivate.copy", "bookmarkManagerPrivate", "copy" } 710 { "bookmarkManagerPrivate.copy", "bookmarkManagerPrivate", "copy" }
711 }; 711 };
712 712
713 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); 713 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration());
714 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 714 for (size_t i = 0; i < arraysize(test_data); ++i) {
715 std::string child_name; 715 std::string child_name;
716 std::string api_name = api->GetAPINameFromFullName(test_data[i].input, 716 std::string api_name = api->GetAPINameFromFullName(test_data[i].input,
717 &child_name); 717 &child_name);
718 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input; 718 EXPECT_EQ(test_data[i].api_name, api_name) << test_data[i].input;
719 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input; 719 EXPECT_EQ(test_data[i].child_name, child_name) << test_data[i].input;
720 } 720 }
721 } 721 }
722 722
723 TEST(ExtensionAPITest, DefaultConfigurationFeatures) { 723 TEST(ExtensionAPITest, DefaultConfigurationFeatures) {
724 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration()); 724 scoped_ptr<ExtensionAPI> api(ExtensionAPI::CreateWithDefaultConfiguration());
725 725
726 SimpleFeature* bookmarks = static_cast<SimpleFeature*>( 726 SimpleFeature* bookmarks = static_cast<SimpleFeature*>(
727 api->GetFeatureDependency("api:bookmarks")); 727 api->GetFeatureDependency("api:bookmarks"));
728 SimpleFeature* bookmarks_create = static_cast<SimpleFeature*>( 728 SimpleFeature* bookmarks_create = static_cast<SimpleFeature*>(
729 api->GetFeatureDependency("api:bookmarks.create")); 729 api->GetFeatureDependency("api:bookmarks.create"));
730 730
731 struct { 731 struct {
732 SimpleFeature* feature; 732 SimpleFeature* feature;
733 // TODO(aa): More stuff to test over time. 733 // TODO(aa): More stuff to test over time.
734 } test_data[] = { 734 } test_data[] = {
735 { bookmarks }, 735 { bookmarks },
736 { bookmarks_create } 736 { bookmarks_create }
737 }; 737 };
738 738
739 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 739 for (size_t i = 0; i < arraysize(test_data); ++i) {
740 SimpleFeature* feature = test_data[i].feature; 740 SimpleFeature* feature = test_data[i].feature;
741 ASSERT_TRUE(feature) << i; 741 ASSERT_TRUE(feature) << i;
742 742
743 EXPECT_TRUE(feature->whitelist()->empty()); 743 EXPECT_TRUE(feature->whitelist()->empty());
744 EXPECT_TRUE(feature->extension_types()->empty()); 744 EXPECT_TRUE(feature->extension_types()->empty());
745 745
746 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); 746 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location());
747 EXPECT_TRUE(feature->platforms()->empty()); 747 EXPECT_TRUE(feature->platforms()->empty());
748 EXPECT_EQ(0, feature->min_manifest_version()); 748 EXPECT_EQ(0, feature->min_manifest_version());
749 EXPECT_EQ(0, feature->max_manifest_version()); 749 EXPECT_EQ(0, feature->max_manifest_version());
(...skipping 15 matching lines...) Expand all
765 api_features2->Set("test", test2); 765 api_features2->Set("test", test2);
766 766
767 struct { 767 struct {
768 base::DictionaryValue* api_features; 768 base::DictionaryValue* api_features;
769 bool expect_success; 769 bool expect_success;
770 } test_data[] = { 770 } test_data[] = {
771 { api_features1.get(), true }, 771 { api_features1.get(), true },
772 { api_features2.get(), false } 772 { api_features2.get(), false }
773 }; 773 };
774 774
775 775 for (size_t i = 0; i < arraysize(test_data); ++i) {
776 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
777 BaseFeatureProvider api_feature_provider(*test_data[i].api_features, 776 BaseFeatureProvider api_feature_provider(*test_data[i].api_features,
778 CreateAPIFeature); 777 CreateAPIFeature);
779 Feature* feature = api_feature_provider.GetFeature("test"); 778 Feature* feature = api_feature_provider.GetFeature("test");
780 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; 779 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i;
781 } 780 }
782 } 781 }
783 782
784 static void GetDictionaryFromList(const base::DictionaryValue* schema, 783 static void GetDictionaryFromList(const base::DictionaryValue* schema,
785 const std::string& list_name, 784 const std::string& list_name,
786 const int list_index, 785 const int list_index,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 { "management.uninstallSelf", true }, 893 { "management.uninstallSelf", true },
895 // But other functions in those modules do. 894 // But other functions in those modules do.
896 { "management.getPermissionWarningsById", false }, 895 { "management.getPermissionWarningsById", false },
897 }; 896 };
898 897
899 scoped_ptr<ExtensionAPI> extension_api( 898 scoped_ptr<ExtensionAPI> extension_api(
900 ExtensionAPI::CreateWithDefaultConfiguration()); 899 ExtensionAPI::CreateWithDefaultConfiguration());
901 scoped_refptr<Extension> extension = 900 scoped_refptr<Extension> extension =
902 BuildExtension(ExtensionBuilder().Pass()).Build(); 901 BuildExtension(ExtensionBuilder().Pass()).Build();
903 902
904 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 903 for (size_t i = 0; i < arraysize(kTests); ++i) {
905 EXPECT_EQ(kTests[i].expect_success, 904 EXPECT_EQ(kTests[i].expect_success,
906 extension_api->IsAvailable(kTests[i].permission_name, 905 extension_api->IsAvailable(kTests[i].permission_name,
907 extension.get(), 906 extension.get(),
908 Feature::BLESSED_EXTENSION_CONTEXT, 907 Feature::BLESSED_EXTENSION_CONTEXT,
909 GURL()).is_available()) 908 GURL()).is_available())
910 << "Permission being tested: " << kTests[i].permission_name; 909 << "Permission being tested: " << kTests[i].permission_name;
911 } 910 }
912 } 911 }
913 912
914 // Tests that permissions that require manifest keys are available when those 913 // Tests that permissions that require manifest keys are available when those
(...skipping 12 matching lines...) Expand all
927 extension.get(), 926 extension.get(),
928 Feature::BLESSED_EXTENSION_CONTEXT, 927 Feature::BLESSED_EXTENSION_CONTEXT,
929 GURL()).is_available()); 928 GURL()).is_available());
930 EXPECT_FALSE(extension_api->IsAvailable("pageAction", 929 EXPECT_FALSE(extension_api->IsAvailable("pageAction",
931 extension.get(), 930 extension.get(),
932 Feature::BLESSED_EXTENSION_CONTEXT, 931 Feature::BLESSED_EXTENSION_CONTEXT,
933 GURL()).is_available()); 932 GURL()).is_available());
934 } 933 }
935 934
936 } // namespace extensions 935 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/command_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698