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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/common/permissions/permissions_info.h" | 9 #include "extensions/common/permissions/permissions_info.h" |
10 #include "extensions/common/permissions/socket_permission.h" | 10 #include "extensions/common/permissions/socket_permission.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ParseTest("udp-bind::99", "udp-bind:*:99"); | 118 ParseTest("udp-bind::99", "udp-bind:*:99"); |
119 ParseTest("udp-send-to::99", "udp-send-to:*:99"); | 119 ParseTest("udp-send-to::99", "udp-send-to:*:99"); |
120 | 120 |
121 ParseTest("tcp-connect:www.example.com", "tcp-connect:www.example.com:*"); | 121 ParseTest("tcp-connect:www.example.com", "tcp-connect:www.example.com:*"); |
122 | 122 |
123 ParseTest("tcp-connect:*.example.com:99", "tcp-connect:*.example.com:99"); | 123 ParseTest("tcp-connect:*.example.com:99", "tcp-connect:*.example.com:99"); |
124 } | 124 } |
125 | 125 |
126 TEST(SocketPermissionTest, Match) { | 126 TEST(SocketPermissionTest, Match) { |
127 SocketPermissionData data; | 127 SocketPermissionData data; |
128 scoped_ptr<SocketPermission::CheckParam> param; | 128 std::unique_ptr<SocketPermission::CheckParam> param; |
129 | 129 |
130 CHECK(data.ParseForTest("tcp-connect")); | 130 CHECK(data.ParseForTest("tcp-connect")); |
131 param.reset(new SocketPermission::CheckParam( | 131 param.reset(new SocketPermission::CheckParam( |
132 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 132 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
133 EXPECT_TRUE(data.Check(param.get())); | 133 EXPECT_TRUE(data.Check(param.get())); |
134 param.reset(new SocketPermission::CheckParam( | 134 param.reset(new SocketPermission::CheckParam( |
135 SocketPermissionRequest::UDP_SEND_TO, "www.example.com", 80)); | 135 SocketPermissionRequest::UDP_SEND_TO, "www.example.com", 80)); |
136 EXPECT_FALSE(data.Check(param.get())); | 136 EXPECT_FALSE(data.Check(param.get())); |
137 | 137 |
138 CHECK(data.ParseForTest("udp-send-to::8800")); | 138 CHECK(data.ParseForTest("udp-send-to::8800")); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 EXPECT_FALSE(data.Check(param.get())); | 262 EXPECT_FALSE(data.Check(param.get())); |
263 } | 263 } |
264 | 264 |
265 TEST(SocketPermissionTest, IPC) { | 265 TEST(SocketPermissionTest, IPC) { |
266 const APIPermissionInfo* permission_info = | 266 const APIPermissionInfo* permission_info = |
267 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 267 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
268 | 268 |
269 { | 269 { |
270 IPC::Message m; | 270 IPC::Message m; |
271 | 271 |
272 scoped_ptr<APIPermission> permission1( | 272 std::unique_ptr<APIPermission> permission1( |
273 permission_info->CreateAPIPermission()); | 273 permission_info->CreateAPIPermission()); |
274 scoped_ptr<APIPermission> permission2( | 274 std::unique_ptr<APIPermission> permission2( |
275 permission_info->CreateAPIPermission()); | 275 permission_info->CreateAPIPermission()); |
276 | 276 |
277 permission1->Write(&m); | 277 permission1->Write(&m); |
278 base::PickleIterator iter(m); | 278 base::PickleIterator iter(m); |
279 permission2->Read(&m, &iter); | 279 permission2->Read(&m, &iter); |
280 | 280 |
281 EXPECT_TRUE(permission1->Equal(permission2.get())); | 281 EXPECT_TRUE(permission1->Equal(permission2.get())); |
282 } | 282 } |
283 | 283 |
284 { | 284 { |
285 IPC::Message m; | 285 IPC::Message m; |
286 | 286 |
287 scoped_ptr<APIPermission> permission1( | 287 std::unique_ptr<APIPermission> permission1( |
288 permission_info->CreateAPIPermission()); | 288 permission_info->CreateAPIPermission()); |
289 scoped_ptr<APIPermission> permission2( | 289 std::unique_ptr<APIPermission> permission2( |
290 permission_info->CreateAPIPermission()); | 290 permission_info->CreateAPIPermission()); |
291 | 291 |
292 scoped_ptr<base::ListValue> value(new base::ListValue()); | 292 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
293 value->AppendString("tcp-connect:*.example.com:80"); | 293 value->AppendString("tcp-connect:*.example.com:80"); |
294 value->AppendString("udp-bind::8080"); | 294 value->AppendString("udp-bind::8080"); |
295 value->AppendString("udp-send-to::8888"); | 295 value->AppendString("udp-send-to::8888"); |
296 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); | 296 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); |
297 | 297 |
298 EXPECT_FALSE(permission1->Equal(permission2.get())); | 298 EXPECT_FALSE(permission1->Equal(permission2.get())); |
299 | 299 |
300 permission1->Write(&m); | 300 permission1->Write(&m); |
301 base::PickleIterator iter(m); | 301 base::PickleIterator iter(m); |
302 permission2->Read(&m, &iter); | 302 permission2->Read(&m, &iter); |
303 EXPECT_TRUE(permission1->Equal(permission2.get())); | 303 EXPECT_TRUE(permission1->Equal(permission2.get())); |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 TEST(SocketPermissionTest, Value) { | 307 TEST(SocketPermissionTest, Value) { |
308 const APIPermissionInfo* permission_info = | 308 const APIPermissionInfo* permission_info = |
309 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 309 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
310 | 310 |
311 scoped_ptr<APIPermission> permission1(permission_info->CreateAPIPermission()); | 311 std::unique_ptr<APIPermission> permission1( |
312 scoped_ptr<APIPermission> permission2(permission_info->CreateAPIPermission()); | 312 permission_info->CreateAPIPermission()); |
| 313 std::unique_ptr<APIPermission> permission2( |
| 314 permission_info->CreateAPIPermission()); |
313 | 315 |
314 scoped_ptr<base::ListValue> value(new base::ListValue()); | 316 std::unique_ptr<base::ListValue> value(new base::ListValue()); |
315 value->AppendString("tcp-connect:*.example.com:80"); | 317 value->AppendString("tcp-connect:*.example.com:80"); |
316 value->AppendString("udp-bind::8080"); | 318 value->AppendString("udp-bind::8080"); |
317 value->AppendString("udp-send-to::8888"); | 319 value->AppendString("udp-send-to::8888"); |
318 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); | 320 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); |
319 | 321 |
320 EXPECT_FALSE(permission1->Equal(permission2.get())); | 322 EXPECT_FALSE(permission1->Equal(permission2.get())); |
321 | 323 |
322 scoped_ptr<base::Value> vtmp(permission1->ToValue()); | 324 std::unique_ptr<base::Value> vtmp(permission1->ToValue()); |
323 ASSERT_TRUE(vtmp); | 325 ASSERT_TRUE(vtmp); |
324 ASSERT_TRUE(permission2->FromValue(vtmp.get(), NULL, NULL)); | 326 ASSERT_TRUE(permission2->FromValue(vtmp.get(), NULL, NULL)); |
325 EXPECT_TRUE(permission1->Equal(permission2.get())); | 327 EXPECT_TRUE(permission1->Equal(permission2.get())); |
326 } | 328 } |
327 | 329 |
328 } // namespace | 330 } // namespace |
329 | 331 |
330 } // namespace extensions | 332 } // namespace extensions |
OLD | NEW |