OLD | NEW |
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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" | 7 #include "chrome/browser/extensions/api/permissions/permissions_api_helpers.h" |
8 #include "chrome/common/extensions/api/permissions.h" | 8 #include "chrome/common/extensions/api/permissions.h" |
9 #include "extensions/common/permissions/permission_set.h" | 9 #include "extensions/common/permissions/permission_set.h" |
10 #include "extensions/common/url_pattern_set.h" | 10 #include "extensions/common/url_pattern_set.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 base::ListValue* api_list = NULL; | 45 base::ListValue* api_list = NULL; |
46 base::ListValue* origin_list = NULL; | 46 base::ListValue* origin_list = NULL; |
47 EXPECT_TRUE(value->GetList("permissions", &api_list)); | 47 EXPECT_TRUE(value->GetList("permissions", &api_list)); |
48 EXPECT_TRUE(value->GetList("origins", &origin_list)); | 48 EXPECT_TRUE(value->GetList("origins", &origin_list)); |
49 | 49 |
50 EXPECT_EQ(3u, api_list->GetSize()); | 50 EXPECT_EQ(3u, api_list->GetSize()); |
51 EXPECT_EQ(2u, origin_list->GetSize()); | 51 EXPECT_EQ(2u, origin_list->GetSize()); |
52 | 52 |
53 std::string expected_apis[] = {"tabs", "fileBrowserHandler", | 53 std::string expected_apis[] = {"tabs", "fileBrowserHandler", |
54 "fileBrowserHandlerInternal"}; | 54 "fileBrowserHandlerInternal"}; |
55 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected_apis); ++i) { | 55 for (size_t i = 0; i < arraysize(expected_apis); ++i) { |
56 scoped_ptr<base::Value> value(new base::StringValue(expected_apis[i])); | 56 scoped_ptr<base::Value> value(new base::StringValue(expected_apis[i])); |
57 EXPECT_NE(api_list->end(), api_list->Find(*value)); | 57 EXPECT_NE(api_list->end(), api_list->Find(*value)); |
58 } | 58 } |
59 | 59 |
60 std::string expected_origins[] = { "http://a.com/*", "http://b.com/*" }; | 60 std::string expected_origins[] = { "http://a.com/*", "http://b.com/*" }; |
61 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(expected_origins); ++i) { | 61 for (size_t i = 0; i < arraysize(expected_origins); ++i) { |
62 scoped_ptr<base::Value> value(new base::StringValue(expected_origins[i])); | 62 scoped_ptr<base::Value> value(new base::StringValue(expected_origins[i])); |
63 EXPECT_NE(origin_list->end(), origin_list->Find(*value)); | 63 EXPECT_NE(origin_list->end(), origin_list->Find(*value)); |
64 } | 64 } |
65 | 65 |
66 // Unpack the value back to a permission set and make sure its equal to the | 66 // Unpack the value back to a permission set and make sure its equal to the |
67 // original one. | 67 // original one. |
68 scoped_refptr<PermissionSet> from_value; | 68 scoped_refptr<PermissionSet> from_value; |
69 std::string error; | 69 std::string error; |
70 Permissions permissions_object; | 70 Permissions permissions_object; |
71 EXPECT_TRUE(Permissions::Populate(*value, &permissions_object)); | 71 EXPECT_TRUE(Permissions::Populate(*value, &permissions_object)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 value->Set("permissions", invalid_apis->DeepCopy()); | 167 value->Set("permissions", invalid_apis->DeepCopy()); |
168 EXPECT_TRUE(Permissions::Populate(*value, &permissions_object)); | 168 EXPECT_TRUE(Permissions::Populate(*value, &permissions_object)); |
169 permissions = UnpackPermissionSet(permissions_object, true, &error); | 169 permissions = UnpackPermissionSet(permissions_object, true, &error); |
170 EXPECT_FALSE(permissions.get()); | 170 EXPECT_FALSE(permissions.get()); |
171 EXPECT_FALSE(error.empty()); | 171 EXPECT_FALSE(error.empty()); |
172 EXPECT_EQ(error, "'unknown_permission' is not a recognized permission."); | 172 EXPECT_EQ(error, "'unknown_permission' is not a recognized permission."); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 } // namespace extensions | 176 } // namespace extensions |
OLD | NEW |